starmath: Simplify and micro-optimize lookup in SmIsMathAlpha()
Change-Id: Ica2e0d14141785b9e14c05179e517117afadc5e0 Reviewed-on: https://gerrit.libreoffice.org/33734 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Takeshi Abe <tabe@fixedpoint.jp>
This commit is contained in:
@@ -29,13 +29,16 @@
|
|||||||
#include "smmod.hxx"
|
#include "smmod.hxx"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
|
||||||
// '\0' terminated Array with symbol, which should be treat as letters in
|
bool SmIsMathAlpha(const OUString &rText)
|
||||||
// StarMath Font, (to get a normal (non-clipped) SmRect in contrast to the
|
// true iff symbol (from StarMath Font) should be treated as letter
|
||||||
// other operators and symbols).
|
|
||||||
static sal_Unicode const aMathAlpha[] =
|
|
||||||
{
|
{
|
||||||
|
// Set of symbols, which should be treated as letters in StarMath Font
|
||||||
|
// (to get a normal (non-clipped) SmRect in contrast to the other operators
|
||||||
|
// and symbols).
|
||||||
|
static std::unordered_set<sal_Unicode> const aMathAlpha({
|
||||||
MS_ALEPH, MS_IM, MS_RE,
|
MS_ALEPH, MS_IM, MS_RE,
|
||||||
MS_WP, sal_Unicode(0xE070), MS_EMPTYSET,
|
MS_WP, sal_Unicode(0xE070), MS_EMPTYSET,
|
||||||
sal_Unicode(0x2113), sal_Unicode(0xE0D6), sal_Unicode(0x2107),
|
sal_Unicode(0x2113), sal_Unicode(0xE0D6), sal_Unicode(0x2107),
|
||||||
@@ -43,13 +46,9 @@ static sal_Unicode const aMathAlpha[] =
|
|||||||
MS_LAMBDABAR, MS_SETN, MS_SETZ,
|
MS_LAMBDABAR, MS_SETN, MS_SETZ,
|
||||||
MS_SETQ, MS_SETR, MS_SETC,
|
MS_SETQ, MS_SETR, MS_SETC,
|
||||||
sal_Unicode(0x2373), sal_Unicode(0xE0A5), sal_Unicode(0x2112),
|
sal_Unicode(0x2373), sal_Unicode(0xE0A5), sal_Unicode(0x2112),
|
||||||
sal_Unicode(0x2130), sal_Unicode(0x2131),
|
sal_Unicode(0x2130), sal_Unicode(0x2131)
|
||||||
sal_Unicode('\0')
|
});
|
||||||
};
|
|
||||||
|
|
||||||
bool SmIsMathAlpha(const OUString &rText)
|
|
||||||
// true iff symbol (from StarMath Font) should be treated as letter
|
|
||||||
{
|
|
||||||
if (rText.isEmpty())
|
if (rText.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -59,14 +58,8 @@ bool SmIsMathAlpha(const OUString &rText)
|
|||||||
// is it a greek symbol?
|
// is it a greek symbol?
|
||||||
if (sal_Unicode(0xE0AC) <= cChar && cChar <= sal_Unicode(0xE0D4))
|
if (sal_Unicode(0xE0AC) <= cChar && cChar <= sal_Unicode(0xE0D4))
|
||||||
return true;
|
return true;
|
||||||
else
|
// or, does it appear in 'aMathAlpha'?
|
||||||
{
|
return aMathAlpha.find(cChar) != aMathAlpha.end();
|
||||||
// appears it in 'aMathAlpha'?
|
|
||||||
const sal_Unicode *pChar = aMathAlpha;
|
|
||||||
while (*pChar && *pChar != cChar)
|
|
||||||
pChar++;
|
|
||||||
return *pChar != '\0';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user