]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/patternprops.cpp
   2 ******************************************************************************* 
   3 *   Copyright (C) 2011, International Business Machines 
   4 *   Corporation and others.  All Rights Reserved. 
   5 ******************************************************************************* 
   6 *   file name:  patternprops.cpp 
   8 *   tab size:   8 (not used) 
  11 *   created on: 2011mar13 
  12 *   created by: Markus W. Scherer 
  15 #include "unicode/utypes.h" 
  16 #include "patternprops.h" 
  21  * One byte per Latin-1 character. 
  22  * Bit 0 is set if either Pattern property is true, 
  23  * bit 1 if Pattern_Syntax is true, 
  24  * bit 2 if Pattern_White_Space is true. 
  25  * That is, Pattern_Syntax is encoded as 3 and Pattern_White_Space as 5. 
  27 static const uint8_t latin1
[256]={ 
  29     0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 
  30     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  31     // WS: 20  Syntax: 21..2F 
  32     5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
  34     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 
  35     3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  37     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 0, 
  39     3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  41     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 0, 
  43     0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  44     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  45     // Syntax: A1..A7, A9, AB, AC, AE 
  46     0, 3, 3, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3, 0, 3, 0, 
  47     // Syntax: B0, B1, B6, BB, BF 
  48     3, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 3, 
  49     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  51     0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 
  52     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  54     0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0 
  58  * One byte per 32 characters from U+2000..U+303F indexing into 
  59  * a small table of 32-bit data words. 
  60  * The first two data words are all-zeros and all-ones. 
  62 static const uint8_t index2000
[130]={ 
  63     2, 3, 4, 0, 0, 0, 0, 0,  // 20xx 
  64     0, 0, 0, 0, 5, 1, 1, 1,  // 21xx 
  65     1, 1, 1, 1, 1, 1, 1, 1,  // 22xx 
  66     1, 1, 1, 1, 1, 1, 1, 1,  // 23xx 
  67     1, 1, 1, 0, 0, 0, 0, 0,  // 24xx 
  68     1, 1, 1, 1, 1, 1, 1, 1,  // 25xx 
  69     1, 1, 1, 1, 1, 1, 1, 1,  // 26xx 
  70     1, 1, 1, 6, 7, 1, 1, 1,  // 27xx 
  71     1, 1, 1, 1, 1, 1, 1, 1,  // 28xx 
  72     1, 1, 1, 1, 1, 1, 1, 1,  // 29xx 
  73     1, 1, 1, 1, 1, 1, 1, 1,  // 2Axx 
  74     1, 1, 1, 1, 1, 1, 1, 1,  // 2Bxx 
  75     0, 0, 0, 0, 0, 0, 0, 0,  // 2Cxx 
  76     0, 0, 0, 0, 0, 0, 0, 0,  // 2Dxx 
  77     1, 1, 1, 1, 0, 0, 0, 0,  // 2Exx 
  78     0, 0, 0, 0, 0, 0, 0, 0,  // 2Fxx 
  83  * One 32-bit integer per 32 characters. Ranges of all-false and all-true 
  84  * are mapped to the first two values, other ranges map to appropriate bit patterns. 
  86 static const uint32_t syntax2000
[]={ 
  89     0xffff0000,  // 2: 2010..201F 
  90     0x7fff00ff,  // 3: 2020..2027, 2030..203E 
  91     0x7feffffe,  // 4: 2041..2053, 2055..205E 
  92     0xffff0000,  // 5: 2190..219F 
  93     0x003fffff,  // 6: 2760..2775 
  94     0xfff00000,  // 7: 2794..279F 
  95     0xffffff0e,  // 8: 3001..3003, 3008..301F 
  96     0x00010001   // 9: 3020, 3030 
 100  * Same as syntax2000, but with additional bits set for the 
 101  * Pattern_White_Space characters 200E 200F 2028 2029. 
 103 static const uint32_t syntaxOrWhiteSpace2000
[]={ 
 106     0xffffc000,  // 2: 200E..201F 
 107     0x7fff03ff,  // 3: 2020..2029, 2030..203E 
 108     0x7feffffe,  // 4: 2041..2053, 2055..205E 
 109     0xffff0000,  // 5: 2190..219F 
 110     0x003fffff,  // 6: 2760..2775 
 111     0xfff00000,  // 7: 2794..279F 
 112     0xffffff0e,  // 8: 3001..3003, 3008..301F 
 113     0x00010001   // 9: 3020, 3030 
 117 PatternProps::isSyntax(UChar32 c
) { 
 121         return (UBool
)(latin1
[c
]>>1)&1; 
 122     } else if(c
<0x2010) { 
 124     } else if(c
<=0x3030) { 
 125         uint32_t bits
=syntax2000
[index2000
[(c
-0x2000)>>5]]; 
 126         return (UBool
)((bits
>>(c
&0x1f))&1); 
 127     } else if(0xfd3e<=c 
&& c
<=0xfe46) { 
 128         return c
<=0xfd3f || 0xfe45<=c
; 
 135 PatternProps::isSyntaxOrWhiteSpace(UChar32 c
) { 
 139         return (UBool
)(latin1
[c
]&1); 
 140     } else if(c
<0x200e) { 
 142     } else if(c
<=0x3030) { 
 143         uint32_t bits
=syntaxOrWhiteSpace2000
[index2000
[(c
-0x2000)>>5]]; 
 144         return (UBool
)((bits
>>(c
&0x1f))&1); 
 145     } else if(0xfd3e<=c 
&& c
<=0xfe46) { 
 146         return c
<=0xfd3f || 0xfe45<=c
; 
 153 PatternProps::isWhiteSpace(UChar32 c
) { 
 157         return (UBool
)(latin1
[c
]>>2)&1; 
 158     } else if(0x200e<=c 
&& c
<=0x2029) { 
 159         return c
<=0x200f || 0x2028<=c
; 
 166 PatternProps::skipWhiteSpace(const UChar 
*s
, int32_t length
) { 
 167     while(length
>0 && isWhiteSpace(*s
)) { 
 175 PatternProps::trimWhiteSpace(const UChar 
*s
, int32_t &length
) { 
 176     if(length
<=0 || (!isWhiteSpace(s
[0]) && !isWhiteSpace(s
[length
-1]))) { 
 180     int32_t limit
=length
; 
 181     while(start
<limit 
&& isWhiteSpace(s
[start
])) { 
 185         // There is non-white space at start; we will not move limit below that, 
 186         // so we need not test start<limit in the loop. 
 187         while(isWhiteSpace(s
[limit
-1])) { 
 196 PatternProps::isIdentifier(const UChar 
*s
, int32_t length
) { 
 200     const UChar 
*limit
=s
+length
; 
 202         if(isSyntaxOrWhiteSpace(*s
++)) { 
 210 PatternProps::skipIdentifier(const UChar 
*s
, int32_t length
) { 
 211     while(length
>0 && !isSyntaxOrWhiteSpace(*s
)) {