diff options
author | Eike Rathke <erack@redhat.com> | 2018-02-13 10:45:21 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2018-02-13 21:43:02 +0100 |
commit | 114b9562e58a91b34c6e931c281d8a3900744750 (patch) | |
tree | b72f878af2a60062d44cdaf1dd1c3b3b2e7276cd /sc/source | |
parent | fabb533e06c6c3732bf38544faad30b048c6c627 (diff) |
Resolves: tdf#95192 correctly split non-numeral/numeral parts for natural sort
XCharacterClassification::parsePredefinedToken() with
KParseType::IDENTNAME and KParseTokens::ANY_LETTER does exactly
that, it parses one identifier name consisting of Unicode letters
and stops at the first non-letter character (additionally '-'
hyphen-minus was allowed as character).
Instead, scan for the first (any Unicode) digit and split there.
Also, copying the whole string to the prefix string if no split
happens was unnecessary, the caller does not use the prefix if no
number was found. Nail this as post condition.
Change-Id: I941f9739b39c36c83b63145e3b762ec558738c1c
(cherry picked from commit 2d62a1016438ea0bc079e6de3a5bcdcb34680f43)
Reviewed-on: https://gerrit.libreoffice.org/49629
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/data/table3.cxx | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index f4b63f4f1eaf..cf96a01a926e 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -85,13 +85,16 @@ using namespace ::com::sun::star::i18n; Original string to be split into pieces @param sPrefix - Prefix string that consists of the part before the first number token + Prefix string that consists of the part before the first number token. + If no number was found, sPrefix is unchanged. @param sSuffix String after the last number token. This may still contain number strings. + If no number was found, sSuffix is unchanged. @param fNum Number converted from the middle number string + If no number was found, fNum is unchanged. @return Returns TRUE if a numeral element is found in a given string, or FALSE if no numeral element is found. @@ -99,28 +102,34 @@ using namespace ::com::sun::star::i18n; bool SplitString( const OUString &sWhole, OUString &sPrefix, OUString &sSuffix, double &fNum ) { - i18n::LocaleDataItem2 aLocaleItem = ScGlobal::pLocaleData->getLocaleItem(); - - // Get prefix element - OUString sUser = "-"; - ParseResult aPRPre = ScGlobal::pCharClass->parsePredefinedToken( - KParseType::IDENTNAME, sWhole, 0, - KParseTokens::ANY_LETTER, sUser, KParseTokens::ANY_LETTER, sUser ); - sPrefix = sWhole.copy( 0, aPRPre.EndPos ); + // Get prefix element, search for any digit and stop. + sal_Int32 nPos = 0; + while (nPos < sWhole.getLength()) + { + const sal_uInt16 nType = ScGlobal::pCharClass->getCharacterType( sWhole, nPos); + if (nType & KCharacterType::DIGIT) + break; + sWhole.iterateCodePoints( &nPos ); + } // Return FALSE if no numeral element is found - if ( aPRPre.EndPos == sWhole.getLength() ) + if ( nPos == sWhole.getLength() ) return false; // Get numeral element - sUser = aLocaleItem.decimalSeparator; + OUString sUser = ScGlobal::pLocaleData->getNumDecimalSep(); ParseResult aPRNum = ScGlobal::pCharClass->parsePredefinedToken( - KParseType::ANY_NUMBER, sWhole, aPRPre.EndPos, + KParseType::ANY_NUMBER, sWhole, nPos, KParseTokens::ANY_NUMBER, "", KParseTokens::ANY_NUMBER, sUser ); - if ( aPRNum.EndPos == aPRPre.EndPos ) + if ( aPRNum.EndPos == nPos ) + { + SAL_WARN("sc.core","naturalsort::SplitString - digit found but no number parsed, pos " << + nPos << " : " << sWhole); return false; + } + sPrefix = sWhole.copy( 0, nPos ); fNum = aPRNum.Value; sSuffix = sWhole.copy( aPRNum.EndPos ); |