diff options
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/mathml/starmathdatabase.hxx | 5 | ||||
-rw-r--r-- | starmath/source/mathml/starmathdatabase.cxx | 51 | ||||
-rw-r--r-- | starmath/source/parse.cxx | 2 |
3 files changed, 35 insertions, 23 deletions
diff --git a/starmath/inc/mathml/starmathdatabase.hxx b/starmath/inc/mathml/starmathdatabase.hxx index 096a38b1e4c2..b40a932809a4 100644 --- a/starmath/inc/mathml/starmathdatabase.hxx +++ b/starmath/inc/mathml/starmathdatabase.hxx @@ -203,6 +203,7 @@ extern const SmColorTokenTableEntry aColorTokenTableParse[159]; extern const SmColorTokenTableEntry aColorTokenTableHTML[148]; extern const SmColorTokenTableEntry aColorTokenTableMATHML[16]; extern const SmColorTokenTableEntry aColorTokenTableDVIPS[5]; +extern const SmColorTokenTableEntry aColorTokenTableERROR[1]; /** * Identifies operator chars tokens for importing mathml. @@ -301,7 +302,7 @@ std::unique_ptr<SmColorTokenTableEntry> Identify_Color_DVIPSNAMES(sal_uInt32 cCo * @param cColor * @param parser color */ -std::unique_ptr<SmColorTokenTableEntry> Identify_ColorName_Parser(const OUString& colorname); +const SmColorTokenTableEntry* Identify_ColorName_Parser(const OUString& colorname); /** * Identifies color from color name. @@ -325,5 +326,5 @@ std::unique_ptr<SmColorTokenTableEntry> Identify_ColorName_HTML(const OUString& * @param cColor * @param parser color */ -std::unique_ptr<SmColorTokenTableEntry> Identify_ColorName_DVIPSNAMES(const OUString& colorname); +const SmColorTokenTableEntry* Identify_ColorName_DVIPSNAMES(const OUString& colorname); } diff --git a/starmath/source/mathml/starmathdatabase.cxx b/starmath/source/mathml/starmathdatabase.cxx index 630fb343840d..f358a37be72c 100644 --- a/starmath/source/mathml/starmathdatabase.cxx +++ b/starmath/source/mathml/starmathdatabase.cxx @@ -692,6 +692,9 @@ const SmColorTokenTableEntry starmathdatabase::aColorTokenTableMATHML[] = { // clang-format on }; +const SmColorTokenTableEntry starmathdatabase::aColorTokenTableERROR[] + = { { "", TERROR, COL_SM_BLACK } }; + std::unique_ptr<SmColorTokenTableEntry> starmathdatabase::Identify_Color_Parser(sal_uInt32 cColor) { for (auto i = std::begin(aColorTokenTableParse); i < std::end(aColorTokenTableParse); ++i) @@ -748,46 +751,54 @@ starmathdatabase::Identify_Color_DVIPSNAMES(sal_uInt32 cColor) new SmColorTokenTableEntry("", TRGBA, cColor)); } -std::unique_ptr<SmColorTokenTableEntry> -starmathdatabase::Identify_ColorName_Parser(const OUString& colorname) +const SmColorTokenTableEntry* starmathdatabase::Identify_ColorName_Parser(const OUString& colorname) { if (colorname.isEmpty()) - return std::unique_ptr<SmColorTokenTableEntry>( - new SmColorTokenTableEntry("", TERROR, COL_SM_BLACK)); + return &aColorTokenTableERROR[0]; for (auto i = std::begin(aColorTokenTableParse); i < std::end(aColorTokenTableParse); ++i) - if (i->equals(colorname)) - return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry(i)); - return std::unique_ptr<SmColorTokenTableEntry>( - new SmColorTokenTableEntry("", TERROR, COL_SM_BLACK)); + { + sal_Int32 matches = colorname.compareToIgnoreAsciiCaseAscii(i->pIdent); + if (matches == 0) + return i; + if (matches < 0) + break; + } + return &aColorTokenTableERROR[0]; } - std::unique_ptr<SmColorTokenTableEntry> starmathdatabase::Identify_ColorName_HTML(const OUString& colorname) { if (colorname.isEmpty()) return std::unique_ptr<SmColorTokenTableEntry>( new SmColorTokenTableEntry("", TERROR, COL_SM_BLACK)); - for (auto i = std::begin(aColorTokenTableHTML); i < std::end(aColorTokenTableHTML); ++i) - if (i->equals(colorname)) - return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry(i)); if (colorname[0] == '#') { Color col = Color::STRtoRGB(colorname); return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry("", TRGB, col)); } + for (auto i = std::begin(aColorTokenTableHTML); i < std::end(aColorTokenTableHTML); ++i) + { + sal_Int32 matches = colorname.compareToIgnoreAsciiCaseAscii(i->pIdent); + if (matches == 0) + return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry(i)); + if (matches < 0) + break; + } return std::unique_ptr<SmColorTokenTableEntry>( new SmColorTokenTableEntry("", TERROR, COL_SM_BLACK)); } - -std::unique_ptr<SmColorTokenTableEntry> +const SmColorTokenTableEntry* starmathdatabase::Identify_ColorName_DVIPSNAMES(const OUString& colorname) { if (colorname.isEmpty()) - return std::unique_ptr<SmColorTokenTableEntry>( - new SmColorTokenTableEntry("", TERROR, COL_SM_BLACK)); + return &aColorTokenTableERROR[0]; for (auto i = std::begin(aColorTokenTableDVIPS); i < std::end(aColorTokenTableDVIPS); ++i) - if (i->equals(colorname)) - return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry(i)); - return std::unique_ptr<SmColorTokenTableEntry>( - new SmColorTokenTableEntry("", TERROR, COL_SM_BLACK)); + { + sal_Int32 matches = colorname.compareToIgnoreAsciiCaseAscii(i->pIdent); + if (matches == 0) + return i; + if (matches < 0) + break; + } + return &aColorTokenTableERROR[0]; } diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx index 5bb152f68607..8bd06070c268 100644 --- a/starmath/source/parse.cxx +++ b/starmath/source/parse.cxx @@ -1008,7 +1008,7 @@ void SmParser::NextTokenColor(bool dvipload) sal_Int32 n = aRes.EndPos - nRealStart; assert(n >= 0); OUString aName( m_aBufferString.copy( nRealStart, n ) ); - std::unique_ptr<SmColorTokenTableEntry> aSmColorTokenTableEntry; + const SmColorTokenTableEntry* aSmColorTokenTableEntry; if(dvipload) aSmColorTokenTableEntry = starmathdatabase::Identify_ColorName_DVIPSNAMES( aName ); else aSmColorTokenTableEntry = starmathdatabase::Identify_ColorName_Parser( aName ); m_aCurToken = aSmColorTokenTableEntry; |