diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2016-12-23 01:13:05 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2017-01-20 02:25:59 +0000 |
commit | cef8ebe925bde6fc1889085e3ccb1be236791e99 (patch) | |
tree | f2c5387e5012d5520bbdefd7571a7b7016190170 /starmath | |
parent | e15fd1371567fd4b78dab37d843562ff676c52b8 (diff) |
starmath: Avoid ad hoc LanguageTag and CharClass at tokenization
Instead, keep them as SmParser's members.
Change-Id: I8a2aad7ba8baaad9a761f42f62d51fc67cadec07
Reviewed-on: https://gerrit.libreoffice.org/32348
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Takeshi Abe <tabe@fixedpoint.jp>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/parse.hxx | 8 | ||||
-rw-r--r-- | starmath/source/parse.cxx | 25 |
2 files changed, 15 insertions, 18 deletions
diff --git a/starmath/inc/parse.hxx b/starmath/inc/parse.hxx index d22a426519fe..76d602f1a3ed 100644 --- a/starmath/inc/parse.hxx +++ b/starmath/inc/parse.hxx @@ -19,7 +19,7 @@ #ifndef INCLUDED_STARMATH_INC_PARSE_HXX #define INCLUDED_STARMATH_INC_PARSE_HXX -#include <com/sun/star/lang/Locale.hpp> +#include <unotools/charclass.hxx> #include <memory> #include <set> #include <vector> @@ -46,8 +46,10 @@ class SmParser // map of used symbols (used to reduce file size by exporting only actually used symbols) std::set< OUString > m_aUsedSymbols; - //! locale where '.' is decimal separator! - css::lang::Locale m_aDotLoc; + // CharClass representing a locale for parsing numbers + CharClass m_aNumCC; + // pointer to System locale's CharClass, which is alive inside SM_MOD() + const CharClass* m_pSysCC; SmParser(const SmParser&) = delete; SmParser& operator=(const SmParser&) = delete; diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx index f33a942f0ee5..1d0129a23df5 100644 --- a/starmath/source/parse.cxx +++ b/starmath/source/parse.cxx @@ -19,7 +19,6 @@ #include <com/sun/star/i18n/UnicodeType.hpp> #include <i18nlangtag/lang.h> -#include <unotools/charclass.hxx> #include <editeng/unolingu.hxx> #include <unotools/syslocale.hxx> #include <sal/macros.h> @@ -379,29 +378,25 @@ void SmParser::NextToken() ParseResult aRes; sal_Int32 nRealStart; bool bCont; - CharClass aCC(SM_MOD()->GetSysLocale().GetLanguageTag()); do { // skip white spaces while (UnicodeType::SPACE_SEPARATOR == - aCC.getType( m_aBufferString, m_nBufferIndex )) + m_pSysCC->getType( m_aBufferString, m_nBufferIndex )) ++m_nBufferIndex; - // Try to parse a number. This should be independent from the locale - // setting, so temporarily set the language to English. + // Try to parse a number in a locale-independent manner using + // '.' as decimal separator. // See https://bz.apache.org/ooo/show_bug.cgi?id=45779 - LanguageTag aOldLoc(aCC.getLanguageTag()); - aCC.setLanguageTag(LanguageTag(m_aDotLoc)); - aRes = aCC.parsePredefinedToken(KParseType::ASC_NUMBER, + aRes = m_aNumCC.parsePredefinedToken(KParseType::ASC_NUMBER, m_aBufferString, m_nBufferIndex, coNumStartFlags, "", coNumContFlags, ""); - aCC.setLanguageTag(aOldLoc); if (aRes.TokenType == 0) { // Try again with the default token parsing. - aRes = aCC.parseAnyToken(m_aBufferString, m_nBufferIndex, + aRes = m_pSysCC->parseAnyToken(m_aBufferString, m_nBufferIndex, coStartFlags, "", coContFlags, ""); } @@ -454,7 +449,7 @@ void SmParser::NextToken() assert(aRes.EndPos > 0); if ( m_aBufferString[aRes.EndPos-1] == ',' && aRes.EndPos < nBufLen && - aCC.getType( m_aBufferString, aRes.EndPos ) != UnicodeType::SPACE_SEPARATOR ) + m_pSysCC->getType( m_aBufferString, aRes.EndPos ) != UnicodeType::SPACE_SEPARATOR ) { // Comma followed by a non-space char is unlikely for decimal/thousands separator. --aRes.EndPos; @@ -639,7 +634,7 @@ void SmParser::NextToken() "unexpected comment start" ); // get identifier of user-defined character - ParseResult aTmpRes = aCC.parseAnyToken( + ParseResult aTmpRes = m_pSysCC->parseAnyToken( m_aBufferString, rnEndPos, KParseTokens::ANY_LETTER, "", @@ -1374,7 +1369,6 @@ void SmParser::DoTerm(bool bGroupNumberIdent) // See https://bz.apache.org/ooo/show_bug.cgi?id=11752 and // https://bugs.libreoffice.org/show_bug.cgi?id=55853 sal_Int32 nBufLen = m_aBufferString.getLength(); - CharClass aCC(SM_MOD()->GetSysLocale().GetLanguageTag()); sal_Int32 nTokens = 1; // We need to be careful to call NextToken() only after having @@ -1382,7 +1376,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent) // skipped!) bool moveToNextToken = true; while (m_nBufferIndex < nBufLen && - aCC.getType(m_aBufferString, m_nBufferIndex) != + m_pSysCC->getType(m_aBufferString, m_nBufferIndex) != UnicodeType::SPACE_SEPARATOR) { NextToken(); @@ -2295,7 +2289,8 @@ SmParser::SmParser() , m_nColOff( 0 ) , m_bImportSymNames( false ) , m_bExportSymNames( false ) - , m_aDotLoc( LanguageTag::convertToLocale( LANGUAGE_ENGLISH_US ) ) + , m_aNumCC( LanguageTag( LANGUAGE_ENGLISH_US ) ) + , m_pSysCC( SM_MOD()->GetSysLocale().GetCharClassPtr() ) { } |