# HG changeset patch # User Teemu Piippo # Date 1452354508 -7200 # Node ID ca10837a2a9ee3cba6a9ccbaba421bfa4af3a9e6 # Parent b4466472aecdf7873cc06ab1e2f617d9a749428d Backport string changes from protocol5 diff -r b4466472aecd -r ca10837a2a9e sources/mystring.cpp --- 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 diff -r b4466472aecd -r ca10837a2a9e sources/mystring.h --- 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& unwanted); + bool starts_with (const String &other) const; + String strip (char unwanted) { return strip ({unwanted}); } + String strip (const List &unwanted); void trim (int n); static String from_number (short int a);