/* ******************************************************************************* * * Copyright (c) 1995-2013 International Business Machines Corporation and others * * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, and/or sell copies of the * Software, and to permit persons to whom the Software is furnished to do so, * provided that the above copyright notice(s) and this permission notice appear * in all copies of the Software and that both the above copyright notice(s) and * this permission notice appear in supporting documentation. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN * NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE * LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Except as contained in this notice, the name of a copyright holder shall not be * used in advertising or otherwise to promote the sale, use or other dealings in * this Software without prior written authorization of the copyright holder. * ******************************************************************************* * file name: scrptrun.cpp * * created on: 10/17/2001 * created by: Eric R. Mader
*/ /** * This file is largely copied from the ICU project, * under folder source/extra/scrptrun/scrptrun.cpp
*/
UScriptCode getScript(UChar32 ch, UErrorCode* status)
{ // tdf#154549 // Make combining marks inherit the script of their bases, regardless of // their own script. if (u_getIntPropertyValue(ch, UCHAR_GENERAL_CATEGORY) == U_NON_SPACING_MARK) return USCRIPT_INHERITED;
UScriptCode script = uscript_getScript(ch, status); if (U_FAILURE(*status)) return script;
// There are three Unicode script codes for Japanese text, but only one // OpenType script tag, so we want to keep them in one run as splitting is // pointless for the purpose of OpenType shaping. if (script == USCRIPT_KATAKANA || script == USCRIPT_KATAKANA_OR_HIRAGANA) return USCRIPT_HIRAGANA; return script;
}
UBool ScriptRun::next()
{
int32_t startSP = parenSP; // used to find the first new open character
UErrorCode error = U_ZERO_ERROR;
// if we've fallen off the end of the text, we're done if (scriptEnd >= charLimit) { returnfalse;
}
scriptCode = USCRIPT_COMMON;
for (scriptStart = scriptEnd; scriptEnd < charLimit; scriptEnd += 1) {
UChar high = charArray[scriptEnd];
UChar32 ch = high;
// if the character is a high surrogate and it's not the last one // in the text, see if it's followed by a low surrogate if (rtl::isHighSurrogate(high) && scriptEnd < charLimit - 1)
{
UChar low = charArray[scriptEnd + 1];
// if it is followed by a low surrogate, // consume it and form the full character if (rtl::isLowSurrogate(low)) {
ch = rtl::combineSurrogates(high, low);
scriptEnd += 1;
}
}
// if it's an open character, push it onto the stack. // if it's a close character, find the matching open on the // stack, and use that script code. Any non-matching open // characters above it on the stack will be popped. if (pairIndex >= 0) { if ((pairIndex & 1) == 0) {
++parenSP;
int32_t nVecSize = parenStack.size(); if (parenSP == nVecSize)
parenStack.resize(nVecSize + 128);
parenStack[parenSP].pairIndex = pairIndex;
parenStack[parenSP].scriptCode = scriptCode;
} elseif (parenSP >= 0) {
int32_t pi = pairIndex & ~1;
if (sameScript(scriptCode, sc)) { if (scriptCode <= USCRIPT_INHERITED && sc > USCRIPT_INHERITED) {
scriptCode = sc;
// now that we have a final script code, fix any open // characters we pushed before we knew the script code. while (startSP < parenSP) {
parenStack[++startSP].scriptCode = scriptCode;
}
}
// if this character is a close paired character, // pop it from the stack if (pairIndex >= 0 && (pairIndex & 1) != 0 && parenSP >= 0) {
parenSP -= 1; /* decrement startSP only if it is >= 0, decrementing it unnecessarily will lead to memory corruption while processing the above while block. e.g. startSP = -4 , parenSP = -1
*/ if (startSP >= 0) {
startSP -= 1;
}
}
} else { // if the run broke on a surrogate pair, // end it before the high surrogate if (ch >= 0x10000) {
scriptEnd -= 1;
}
break;
}
}
returntrue;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.8 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.