164339d36f8bd4db5025fe2988eda22b491a9219cFredrik Roubert// Copyright (C) 2016 and later: Unicode, Inc. and others. 264339d36f8bd4db5025fe2988eda22b491a9219cFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Copyright (C) 1999-2003, International Business Machines 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Corporation and others. All Rights Reserved. 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * file name: scrptrun.h 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * created on: 10/17/2001 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * created by: Eric R. Mader 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef __SCRPTRUN_H 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define __SCRPTRUN_H 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uobject.h" 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uscript.h" 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct ScriptRecord 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar32 startChar; 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar32 endChar; 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UScriptCode scriptCode; 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct ParenStackEntry 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t pairIndex; 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UScriptCode scriptCode; 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass ScriptRun : public UObject { 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ScriptRun(); 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ScriptRun(const UChar chars[], int32_t length); 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ScriptRun(const UChar chars[], int32_t start, int32_t length); 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void reset(); 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void reset(int32_t start, int32_t count); 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void reset(const UChar chars[], int32_t start, int32_t length); 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t getScriptStart(); 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t getScriptEnd(); 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UScriptCode getScriptCode(); 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool next(); 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICU "poor man's RTTI", returns a UClassID for the actual class. 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.2 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICU "poor man's RTTI", returns a UClassID for this class. 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.2 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate: 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static UBool sameScript(int32_t scriptOne, int32_t scriptTwo); 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t charStart; 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t charLimit; 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *charArray; 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t scriptStart; 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t scriptEnd; 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UScriptCode scriptCode; 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ParenStackEntry parenStack[128]; 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t parenSP; 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static int8_t highBit(int32_t value); 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static int32_t getPairIndex(UChar32 ch); 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static UChar32 pairedChars[]; 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const int32_t pairedCharCount; 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const int32_t pairedCharPower; 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const int32_t pairedCharExtra; 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The address of this static class variable serves as this class's ID 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * for ICU "poor man's RTTI". 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const char fgClassID; 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline ScriptRun::ScriptRun() 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru reset(NULL, 0, 0); 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline ScriptRun::ScriptRun(const UChar chars[], int32_t length) 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru reset(chars, 0, length); 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline ScriptRun::ScriptRun(const UChar chars[], int32_t start, int32_t length) 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru reset(chars, start, length); 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t ScriptRun::getScriptStart() 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return scriptStart; 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t ScriptRun::getScriptEnd() 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return scriptEnd; 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline UScriptCode ScriptRun::getScriptCode() 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return scriptCode; 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline void ScriptRun::reset() 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru scriptStart = charStart; 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru scriptEnd = charStart; 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru scriptCode = USCRIPT_INVALID_CODE; 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru parenSP = -1; 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline void ScriptRun::reset(int32_t start, int32_t length) 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru charStart = start; 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru charLimit = start + length; 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru reset(); 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline void ScriptRun::reset(const UChar chars[], int32_t start, int32_t length) 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru charArray = chars; 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru reset(start, length); 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 157