sources/mystring.cpp

changeset 137
485cb6d6b98c
parent 129
a556ce001e26
child 141
d9073c13dc98
child 145
d0aedc9be448
--- a/sources/mystring.cpp	Fri May 15 22:46:53 2015 +0300
+++ b/sources/mystring.cpp	Wed Jul 20 14:48:47 2016 +0300
@@ -70,13 +70,9 @@
 {
 	String result (m_string);
 
-	for (int i = 0; i < unwanted.size(); ++i)
-	{
-		String c = unwanted[i];
-
-		for (int pos = 0; (pos = result.find (c)) != -1;)
-			result.remove_at (pos--);
-	}
+	for (String c : unwanted)
+	for (int pos = 0; (pos = result.find (c)) != -1;)
+		result.remove_at (pos--);
 
 	return result;
 }
@@ -87,10 +83,10 @@
 {
 	String result (m_string);
 
-	for (int i = 0; i < result.length(); ++i)
+	for (char &ch : result)
 	{
-		if (islower (result[i]))
-			result[i] -= 'a' - 'A';
+		if (islower(ch))
+			ch -= 'a' - 'A';
 	}
 
 	return result;
@@ -102,10 +98,10 @@
 {
 	String result (m_string);
 
-	for (int i = 0; i < result.length(); ++i)
+	for (char &ch : result)
 	{
-		if (isupper (result[i]))
-			result[i] += 'a' - 'A';
+		if (isupper(ch))
+			ch += 'a' - 'A';
 	}
 
 	return result;
@@ -162,9 +158,9 @@
 {
 	int result = 0;
 
-	for (int i = 0; i < length(); ++i)
+	for (char ch : *this)
 	{
-		if (m_string[i] == needle)
+		if (ch == needle)
 			result++;
 	}
 
@@ -205,12 +201,10 @@
 {
 	int count = 0;
 
-	for (int i = 0; i < length(); ++i)
+	for (char ch : *this)
 	{
-		if (not isspace (m_string[i]) or ++count < n)
+		if (not isspace(ch) or ++count < n)
 			continue;
-
-		return i;
 	}
 
 	return -1;
@@ -379,12 +373,12 @@
 {
 	String result;
 
-	for (int i = 0; i < size(); ++i)
+	for (const String &item : container())
 	{
 		if (result.is_empty() == false)
 			result += delim;
 
-		result += container()[i];
+		result += item;
 	}
 
 	return result;

mercurial