diff options
| author | Martin Hořeňovský | 2017-07-25 21:57:35 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2017-07-25 21:57:35 +0200 |
| commit | 1a96175bb290a351c5aabbbf330ab7512635db3f (patch) | |
| tree | 9454a5bc3eb303d9f025e23fb56e5c5472c31279 /include/internal/catch_common.cpp | |
| parent | 1e59ccee41f269440310979a0b6ab7e4dbb1e453 (diff) | |
| download | catch3-1a96175bb290a351c5aabbbf330ab7512635db3f.tar.gz | |
Split out helper functions on std::string from catch_common.h
Diffstat (limited to 'include/internal/catch_common.cpp')
| -rw-r--r-- | include/internal/catch_common.cpp | 65 |
1 files changed, 4 insertions, 61 deletions
diff --git a/include/internal/catch_common.cpp b/include/internal/catch_common.cpp index a35ef93a..d865cd52 100644 --- a/include/internal/catch_common.cpp +++ b/include/internal/catch_common.cpp @@ -11,70 +11,9 @@ #include "catch_interfaces_config.h" #include <cstring> -#include <cctype> namespace Catch { - bool startsWith( std::string const& s, std::string const& prefix ) { - return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin()); - } - bool startsWith( std::string const& s, char prefix ) { - return !s.empty() && s[0] == prefix; - } - bool endsWith( std::string const& s, std::string const& suffix ) { - return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin()); - } - bool endsWith( std::string const& s, char suffix ) { - return !s.empty() && s[s.size()-1] == suffix; - } - bool contains( std::string const& s, std::string const& infix ) { - return s.find( infix ) != std::string::npos; - } - char toLowerCh(char c) { - return static_cast<char>( std::tolower( c ) ); - } - void toLowerInPlace( std::string& s ) { - std::transform( s.begin(), s.end(), s.begin(), toLowerCh ); - } - std::string toLower( std::string const& s ) { - std::string lc = s; - toLowerInPlace( lc ); - return lc; - } - std::string trim( std::string const& str ) { - static char const* whitespaceChars = "\n\r\t "; - std::string::size_type start = str.find_first_not_of( whitespaceChars ); - std::string::size_type end = str.find_last_not_of( whitespaceChars ); - - return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string(); - } - - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { - bool replaced = false; - std::size_t i = str.find( replaceThis ); - while( i != std::string::npos ) { - replaced = true; - str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); - if( i < str.size()-withThis.size() ) - i = str.find( replaceThis, i+withThis.size() ); - else - i = std::string::npos; - } - return replaced; - } - - pluralise::pluralise( std::size_t count, std::string const& label ) - : m_count( count ), - m_label( label ) - {} - - std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { - os << pluraliser.m_count << ' ' << pluraliser.m_label; - if( pluraliser.m_count != 1 ) - os << 's'; - return os; - } - SourceLineInfo::SourceLineInfo() noexcept : file(""), line( 0 ){} SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line ) noexcept : file( _file ), @@ -111,4 +50,8 @@ namespace Catch { bool alwaysTrue() { return true; } bool alwaysFalse() { return false; } + std::string StreamEndStop::operator+() const { + return std::string(); + } + } |