diff -r e5d185b62b7f -r a556ce001e26 sources/mystring.cpp --- a/sources/mystring.cpp Mon Jan 11 16:44:26 2016 +0200 +++ b/sources/mystring.cpp Mon Jan 11 16:58:59 2016 +0200 @@ -173,23 +173,20 @@ // ------------------------------------------------------------------------------------------------- // -String String::mid (long a, long b) const +// Returns a substring from [a, b) +// +String String::mid (int a, int b) const { - if (b == -1 or b > length()) + a = max(a, 0); + b = min(b, length()); + + if (b == -1) b = length(); if (b <= a) return ""; - - if (a == 0 and b == length()) - return *this; - - char* newstr = new char[b - a + 1]; - strncpy (newstr, chars() + a, b - a); - newstr[b - a] = '\0'; - String other (newstr); - delete[] newstr; - return other; + else + return m_string.substr(a, b - a); } // -------------------------------------------------------------------------------------------------