Change string::split once more

- Delimiters now end up in their own token when keepSeparators is true.
- When ignoreEmptyTokens is false we now add a token at the end when the last character is a delimiter.
While this means some changes, the ignoreEmptyTokens=false didn't work correct in 1.8 anyway, so another change shouldn't break much.
Thanks @manni63 for bringing this up in forum: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=51584&p=299634#p299634


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6007 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2019-12-13 15:30:07 +00:00
parent 421000e00d
commit 44fd5d37ea
1 changed files with 11 additions and 10 deletions

View File

@ -1376,8 +1376,9 @@ public:
\param delimiter C-style string of delimiter characters \param delimiter C-style string of delimiter characters
\param countDelimiters Number of delimiter characters \param countDelimiters Number of delimiter characters
\param ignoreEmptyTokens Flag to avoid empty substrings in the result \param ignoreEmptyTokens Flag to avoid empty substrings in the result
container. If two delimiters occur without a character in between, an container. If two delimiters occur without a character in between or an
empty substring would be placed in the result. If this flag is set, empty substring would be placed in the result. Or if a delimiter is the last
character an empty substring would be added at the end. If this flag is set,
only non-empty strings are stored. only non-empty strings are stored.
\param keepSeparators Flag which allows to add the separator to the \param keepSeparators Flag which allows to add the separator to the
result string. If this flag is true, the concatenation of the result string. If this flag is true, the concatenation of the
@ -1400,17 +1401,15 @@ public:
{ {
if (array[i] == delimiter[j]) if (array[i] == delimiter[j])
{ {
if (i - tokenStartIdx > 0)
ret.push_back(string<T,TAlloc>(&array[tokenStartIdx], i - tokenStartIdx));
else if ( !ignoreEmptyTokens )
ret.push_back(string<T,TAlloc>());
if ( keepSeparators ) if ( keepSeparators )
{ {
ret.push_back(string<T,TAlloc>(&array[tokenStartIdx], i+1 - tokenStartIdx)); ret.push_back(string<T,TAlloc>(&array[i], 1));
}
else
{
if (i - tokenStartIdx > 0)
ret.push_back(string<T,TAlloc>(&array[tokenStartIdx], i - tokenStartIdx));
else if ( !ignoreEmptyTokens )
ret.push_back(string<T,TAlloc>());
} }
tokenStartIdx = i+1; tokenStartIdx = i+1;
break; break;
} }
@ -1418,6 +1417,8 @@ public:
} }
if ((used - 1) > tokenStartIdx) if ((used - 1) > tokenStartIdx)
ret.push_back(string<T,TAlloc>(&array[tokenStartIdx], (used - 1) - tokenStartIdx)); ret.push_back(string<T,TAlloc>(&array[tokenStartIdx], (used - 1) - tokenStartIdx));
else if ( !ignoreEmptyTokens )
ret.push_back(string<T,TAlloc>());
return ret.size()-oldSize; return ret.size()-oldSize;
} }