diff options
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 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 ); |