Backport string changes from protocol5

Sat, 09 Jan 2016 17:48:28 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 09 Jan 2016 17:48:28 +0200
changeset 107
ca10837a2a9e
parent 105
b4466472aecd
child 108
5900be70c619
child 109
e4966d7e615d

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);

mercurial