summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2018-02-13 10:45:21 +0100
committerEike Rathke <erack@redhat.com>2018-02-13 11:03:14 +0100
commit2d62a1016438ea0bc079e6de3a5bcdcb34680f43 (patch)
tree3ca8a6c0008528b1cac82a093cc1a5d83e8ddcbc
parentf737c9386a605cb7d8c9dbc210c557f98f6cdc19 (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
-rw-r--r--sc/source/core/data/table3.cxx35
1 files changed, 22 insertions, 13 deletions
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index d25bd8823319..fb340248d715 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -87,13 +87,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.
@@ -101,28 +104,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 );