string_trim.hpp 681 B

1234567891011121314151617181920212223242526272829
  1. #ifndef BOOST_THREAD_DETAIL_STRING_TRIM_HPP_INCLUDED
  2. #define BOOST_THREAD_DETAIL_STRING_TRIM_HPP_INCLUDED
  3. // Copyright 2023 Peter Dimov
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #include <string>
  7. namespace boost
  8. {
  9. namespace thread_detail
  10. {
  11. inline std::string string_trim( std::string const& s )
  12. {
  13. std::size_t i = s.find_first_not_of( " \t\r\n" );
  14. if( i == std::string::npos ) return std::string();
  15. std::size_t j = s.find_last_not_of( " \t\r\n" );
  16. return s.substr( i, j + 1 - i );
  17. }
  18. } // namespace thread_detail
  19. } // namespace boost
  20. #endif // #ifndef BOOST_THREAD_DETAIL_STRING_TRIM_HPP_INCLUDED