Fix compilation on MSVC 2010

Sun, 10 Jan 2016 19:38:11 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 10 Jan 2016 19:38:11 +0200
changeset 110
cad1163333b9
parent 109
e4966d7e615d
child 111
51c93a0cc317

Fix compilation on MSVC 2010

sources/mystring.cpp file | annotate | diff | comparison | revisions
sources/mystring.h file | annotate | diff | comparison | revisions
--- 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<char>& 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<char>& 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())
--- 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<char> &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<char> &unwanted);
 	void trim (int n);
 
 	static String from_number (short int a);

mercurial