From 44fd5d37ea570e37a35639f42900785506923419 Mon Sep 17 00:00:00 2001 From: cutealien Date: Fri, 13 Dec 2019 15:30:07 +0000 Subject: [PATCH] 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 --- include/irrString.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/include/irrString.h b/include/irrString.h index 6f4812a..0b57864 100644 --- a/include/irrString.h +++ b/include/irrString.h @@ -1376,8 +1376,9 @@ public: \param delimiter C-style string of delimiter characters \param countDelimiters Number of delimiter characters \param ignoreEmptyTokens Flag to avoid empty substrings in the result - container. If two delimiters occur without a character in between, an - empty substring would be placed in the result. If this flag is set, + container. If two delimiters occur without a character in between or an + 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. \param keepSeparators Flag which allows to add the separator to the result string. If this flag is true, the concatenation of the @@ -1400,17 +1401,15 @@ public: { if (array[i] == delimiter[j]) { + if (i - tokenStartIdx > 0) + ret.push_back(string(&array[tokenStartIdx], i - tokenStartIdx)); + else if ( !ignoreEmptyTokens ) + ret.push_back(string()); if ( keepSeparators ) { - ret.push_back(string(&array[tokenStartIdx], i+1 - tokenStartIdx)); - } - else - { - if (i - tokenStartIdx > 0) - ret.push_back(string(&array[tokenStartIdx], i - tokenStartIdx)); - else if ( !ignoreEmptyTokens ) - ret.push_back(string()); + ret.push_back(string(&array[i], 1)); } + tokenStartIdx = i+1; break; } @@ -1418,6 +1417,8 @@ public: } if ((used - 1) > tokenStartIdx) ret.push_back(string(&array[tokenStartIdx], (used - 1) - tokenStartIdx)); + else if ( !ignoreEmptyTokens ) + ret.push_back(string()); return ret.size()-oldSize; }