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