catch_string_manip.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Created by Martin on 25/07/2017.
  3. *
  4. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #ifndef TWOBLUECUBES_CATCH_STRING_MANIP_H_INCLUDED
  8. #define TWOBLUECUBES_CATCH_STRING_MANIP_H_INCLUDED
  9. #include "catch_stringref.h"
  10. #include <string>
  11. #include <iosfwd>
  12. #include <vector>
  13. namespace Catch {
  14. bool startsWith( std::string const& s, std::string const& prefix );
  15. bool startsWith( std::string const& s, char prefix );
  16. bool endsWith( std::string const& s, std::string const& suffix );
  17. bool endsWith( std::string const& s, char suffix );
  18. bool contains( std::string const& s, std::string const& infix );
  19. void toLowerInPlace( std::string& s );
  20. std::string toLower( std::string const& s );
  21. //! Returns a new string without whitespace at the start/end
  22. std::string trim( std::string const& str );
  23. //! Returns a substring of the original ref without whitespace. Beware lifetimes!
  24. StringRef trim(StringRef ref);
  25. // !!! Be aware, returns refs into original string - make sure original string outlives them
  26. std::vector<StringRef> splitStringRef( StringRef str, char delimiter );
  27. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
  28. struct pluralise {
  29. pluralise( std::size_t count, std::string const& label );
  30. friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
  31. std::size_t m_count;
  32. std::string m_label;
  33. };
  34. }
  35. #endif // TWOBLUECUBES_CATCH_STRING_MANIP_H_INCLUDED