2001-11-07 23:48:17 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2001, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: scrptrun.cpp
|
|
|
|
*
|
|
|
|
* created on: 10/17/2001
|
|
|
|
* created by: Eric R. Mader
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uscript.h"
|
|
|
|
|
|
|
|
#include "scrptrun.h"
|
|
|
|
|
|
|
|
UBool ScriptRun::sameScript(int32_t scriptOne, int32_t scriptTwo)
|
|
|
|
{
|
|
|
|
return scriptOne <= USCRIPT_INHERITED || scriptTwo <= USCRIPT_INHERITED || scriptOne == scriptTwo;
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool ScriptRun::next()
|
|
|
|
{
|
|
|
|
UErrorCode error = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
if (scriptEnd >= charLimit) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptCode = USCRIPT_COMMON;
|
|
|
|
|
|
|
|
for (scriptStart = scriptEnd; scriptEnd < charLimit; scriptEnd += 1) {
|
|
|
|
UChar high = charArray[scriptEnd];
|
|
|
|
UChar32 ch = high;
|
|
|
|
|
|
|
|
if (scriptEnd < charLimit - 1 && high >= 0xD800 && high <= 0xDBFF)
|
|
|
|
{
|
|
|
|
UChar low = charArray[scriptEnd + 1];
|
|
|
|
|
|
|
|
if (low >= 0xDC00 && low <= 0xDFFF) {
|
|
|
|
ch = (high - 0xD800) * 0x0400 + low - 0xDC00 + 0x10000;
|
|
|
|
scriptEnd += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UScriptCode sc = uscript_getScript(ch, &error);
|
|
|
|
|
2001-11-08 21:52:08 +00:00
|
|
|
if (ch == ')' && parenSP >= 0 && parenStack[parenSP] != scriptCode) {
|
|
|
|
sc = parenStack[parenSP--];
|
|
|
|
break;
|
|
|
|
} else if (sameScript(scriptCode, sc)) {
|
2001-11-07 23:48:17 +00:00
|
|
|
if (scriptCode <= USCRIPT_INHERITED && sc > USCRIPT_INHERITED) {
|
|
|
|
scriptCode = sc;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if the run broke on a surrogate pair,
|
|
|
|
// end it before the high surrogate
|
|
|
|
if (ch >= 0x10000) {
|
|
|
|
scriptEnd -= 1;
|
|
|
|
}
|
|
|
|
|
2001-11-08 21:52:08 +00:00
|
|
|
for (int32_t i = scriptStart; i < scriptEnd; i += 1) {
|
|
|
|
if (charArray[i] == '(') {
|
|
|
|
parenStack[++parenSP] = scriptCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-07 23:48:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|