Sat, 09 Jan 2016 17:48:28 +0200
Backport string changes from protocol5
sources/mystring.cpp | file | annotate | diff | comparison | revisions | |
sources/mystring.h | file | annotate | diff | comparison | revisions |
--- a/sources/mystring.cpp Sat Jan 09 17:20:25 2016 +0200 +++ b/sources/mystring.cpp Sat Jan 09 17:48:28 2016 +0200 @@ -315,7 +315,7 @@ // ------------------------------------------------------------------------------------------------- // -bool String::starts_with (const String& other) +bool String::starts_with (const String& other) const { if (length() < other.length()) return false; @@ -509,4 +509,13 @@ m_string = m_string.substr (a, b - a + 1); } +// ------------------------------------------------------------------------------------------------- +// +String String::normalized (int (*filter)(int)) const +{ + String result = *this; + result.normalize(filter); + return result; +} + END_ZFC_NAMESPACE
--- a/sources/mystring.h Sat Jan 09 17:20:25 2016 +0200 +++ b/sources/mystring.h Sat Jan 09 17:48:28 2016 +0200 @@ -100,6 +100,7 @@ void insert (int pos, const char*c) { m_string.insert (pos, c); } void modify_index (int &a) { if (a < 0) { a = length() - a; } } void normalize (int (*filter)(int) = &isspace); + String normalized (int (*filter)(int) = &isspace) const; void prepend (String a) { m_string = (a + m_string).std_string(); } void remove (int pos, int len) { m_string.replace (pos, len, ""); } void remove_at (int pos) { m_string.erase (m_string.begin() + pos); } @@ -110,8 +111,9 @@ void shrink_to_fit() { m_string.shrink_to_fit(); } void __cdecl sprintf (const char* fmtstr, ...); void vsprintf (const char* fmtstr, va_list args); - bool starts_with (const String &other); - String strip (const List<char>& unwanted); + bool starts_with (const String &other) const; + String strip (char unwanted) { return strip ({unwanted}); } + String strip (const List<char> &unwanted); void trim (int n); static String from_number (short int a);