You need to sign in or sign up before continuing.
Commit 386c0c06 authored by Rogerborg's avatar Rogerborg

"Bug" #2237876; provide an optional parameter to string::trim() to allow the...

"Bug" #2237876; provide an optional parameter to string::trim() to allow the user to specify characters other than common Latin-1 whitespace.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1726 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 18ff52c0
...@@ -821,18 +821,16 @@ public: ...@@ -821,18 +821,16 @@ public:
//! trims the string. //! trims the string.
/** Removes whitespace from begin and end of the string. */ /** Removes the specified characters (by default, Latin-1 whitespace)
string<T>& trim() from the begining and the end of the string. */
string<T>& trim(const string<T> & whitespace = " \t\n\r")
{ {
const c8 whitespace[] = " \t\n\r"; // find start and end of the substring without the specified characters
const u32 whitespacecount = 4; const s32 begin = findFirstCharNotInList(whitespace.c_str(), whitespace.used);
// find start and end of real string without whitespace
const s32 begin = findFirstCharNotInList(whitespace, whitespacecount);
if (begin == -1) if (begin == -1)
return (*this=""); return (*this="");
const s32 end = findLastCharNotInList(whitespace, whitespacecount); const s32 end = findLastCharNotInList(whitespace.c_str(), whitespace.used);
return (*this = subString(begin, (end +1) - begin)); return (*this = subString(begin, (end +1) - begin));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment