# HG changeset patch # User Teemu Piippo # Date 1452447491 -7200 # Node ID cad1163333b9af6e2a34b1513e315e946741f4d5 # Parent e4966d7e615df76456c26a99157152ab3d2444a1 Fix compilation on MSVC 2010 diff -r e4966d7e615d -r cad1163333b9 sources/mystring.cpp --- a/sources/mystring.cpp Sat Jan 09 18:09:32 2016 +0200 +++ b/sources/mystring.cpp Sun Jan 10 19:38:11 2016 +0200 @@ -54,7 +54,19 @@ // ------------------------------------------------------------------------------------------------- // -String String::strip (const List& unwanted) +String String::strip (char unwanted) const +{ + String result (m_string); + + for (int pos = 0; (pos = result.find (unwanted)) != -1;) + result.remove_at (pos--); + + return result; +} + +// ------------------------------------------------------------------------------------------------- +// +String String::strip (const List& unwanted) const { String result (m_string); @@ -221,6 +233,18 @@ // ------------------------------------------------------------------------------------------------- // +int String::find (char ch, int a) const +{ + int pos = m_string.find (ch, a); + + if (pos == int (std::string::npos)) + return -1; + + return pos; +} + +// ------------------------------------------------------------------------------------------------- +// int String::find_last (const char* c, int a) const { if (a == -1 or a >= length()) diff -r e4966d7e615d -r cad1163333b9 sources/mystring.h --- a/sources/mystring.h Sat Jan 09 18:09:32 2016 +0200 +++ b/sources/mystring.h Sun Jan 10 19:38:11 2016 +0200 @@ -69,7 +69,8 @@ int count (char needle) const; const char* chars() const { return m_string.c_str(); } ConstIterator end() const { return m_string.end(); } - int find (const char*c, int a = 0) const; + int find (const char* c, int a = 0) const; + int find (char ch, int a = 0) const; bool is_empty() const { return m_string[0] == '\0'; } bool is_numeric() const; int find_last (const char*c, int a) const; @@ -81,6 +82,8 @@ StringList split (const String &del) const; StringList split (char del) const; const std::string& std_string() const { return m_string; } + String strip (char unwanted) const; + String strip (const List &unwanted) const; double to_double (bool* ok = nullptr) const; float to_float (bool* ok = nullptr) const; long to_int (bool* ok = nullptr, int base = 10) const; @@ -112,8 +115,6 @@ void __cdecl sprintf (const char* fmtstr, ...); void vsprintf (const char* fmtstr, va_list args); 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);