--- a/sources/mystring.cpp Sat Jan 09 02:35:00 2016 +0200 +++ b/sources/mystring.cpp Sat Jan 09 17:41:21 2016 +0200 @@ -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; } // ------------------------------------------------------------------------------------------------- @@ -160,12 +166,9 @@ if (b == -1 or b > length()) b = length(); - if (b == a) + if (b <= a) return ""; - if (b < a) - swap (a, b); - if (a == 0 and b == length()) return *this; @@ -179,6 +182,16 @@ // ------------------------------------------------------------------------------------------------- // +String String::right(int length) const +{ + if (length >= this->length()) + return *this; + else + return String(chars() + this->length() - length); +} + +// ------------------------------------------------------------------------------------------------- +// int String::word_position (int n) const { int count = 0; @@ -240,7 +253,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 +358,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; @@ -504,3 +517,5 @@ result.normalize(filter); return result; } + +END_ZFC_NAMESPACE