• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 #include "catch_stringref.h"
11 
12 #include <string>
13 #include <iosfwd>
14 #include <vector>
15 
16 namespace Catch {
17 
18     bool startsWith( std::string const& s, std::string const& prefix );
19     bool startsWith( std::string const& s, char prefix );
20     bool endsWith( std::string const& s, std::string const& suffix );
21     bool endsWith( std::string const& s, char suffix );
22     bool contains( std::string const& s, std::string const& infix );
23     void toLowerInPlace( std::string& s );
24     std::string toLower( std::string const& s );
25     //! Returns a new string without whitespace at the start/end
26     std::string trim( std::string const& str );
27     //! Returns a substring of the original ref without whitespace. Beware lifetimes!
28     StringRef trim(StringRef ref);
29 
30     // !!! Be aware, returns refs into original string - make sure original string outlives them
31     std::vector<StringRef> splitStringRef( StringRef str, char delimiter );
32     bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
33 
34     struct pluralise {
35         pluralise( std::size_t count, std::string const& label );
36 
37         friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
38 
39         std::size_t m_count;
40         std::string m_label;
41     };
42 }
43 
44 #endif // TWOBLUECUBES_CATCH_STRING_MANIP_H_INCLUDED
45 
46