sources/mystring.cpp

branch
protocol5
changeset 141
d9073c13dc98
parent 131
4996c8684b93
parent 137
485cb6d6b98c
child 150
37db42ad451a
--- a/sources/mystring.cpp	Wed Jul 20 13:29:03 2016 +0300
+++ b/sources/mystring.cpp	Wed Jul 20 15:03:37 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