--- a/sources/mystring.cpp Thu Jul 23 00:16:47 2015 +0300 +++ b/sources/mystring.cpp Thu Jul 23 01:52:04 2015 +0300 @@ -33,6 +33,8 @@ #include "mystring.h" #include "md5.h" +BEGIN_ZFC_NAMESPACE + // ------------------------------------------------------------------------------------------------- // int String::compare (const String& other) const @@ -54,45 +56,47 @@ // String String::strip (const List<char>& unwanted) { - String copy (m_string); + String result (m_string); - for (char c : unwanted) + for (int i = 0; i < unwanted.size(); ++i) { - for (int pos = 0; (pos = copy.find (String (c))) != -1;) - copy.remove_at (pos--); + String c = unwanted[i]; + + for (int pos = 0; (pos = result.find (c)) != -1;) + result.remove_at (pos--); } - return copy; + return result; } // ------------------------------------------------------------------------------------------------- // String String::to_uppercase() const { - String newstr (m_string); + String result (m_string); - for (char& c : newstr) + for (int i = 0; i < result.length(); ++i) { - if (c >= 'a' and c <= 'z') - c -= 'a' - 'A'; + if (islower (result[i])) + result[i] -= 'a' - 'A'; } - return newstr; + return result; } // ------------------------------------------------------------------------------------------------- // String String::to_lowercase() const { - String newstr (m_string); + String result (m_string); - for (char& c : newstr) + for (int i = 0; i < result.length(); ++i) { - if (c >= 'A' and c <= 'Z') - c += 'a' - 'A'; + if (isupper (result[i])) + result[i] += 'a' - 'A'; } - return newstr; + return result; } // ------------------------------------------------------------------------------------------------- @@ -144,13 +148,15 @@ // int String::count (char needle) const { - int needles = 0; + int result = 0; - for (const char & c : m_string) - if (c == needle) - needles++; + for (int i = 0; i < length(); ++i) + { + if (m_string[i] == needle) + result++; + } - return needles; + return result; } // ------------------------------------------------------------------------------------------------- @@ -164,7 +170,7 @@ return ""; if (b < a) - swap (a, b); + std::swap (a, b); if (a == 0 and b == length()) return *this; @@ -240,7 +246,7 @@ { errno = 0; char* endptr; - float i = strtof (chars(), &endptr); + float i = (float) strtod (chars(), &endptr); if (ok != nullptr) *ok = (errno == 0 and *endptr == '\0'); @@ -345,12 +351,12 @@ { String result; - for (const String& it : container()) + for (int i = 0; i < size(); ++i) { if (result.is_empty() == false) result += delim; - result += it; + result += container()[i]; } return result; @@ -495,3 +501,5 @@ else if (a != 0 or b != length() - 1) m_string = m_string.substr (a, b - a + 1); } + +END_ZFC_NAMESPACE \ No newline at end of file