1 7 8 package com.ibm.icu.impl; 9 14 15 21 public final class USerializedSet { 22 29 public final boolean getSet(char src[], int srcStart) { 30 array=null; 32 arrayOffset=bmpLength=length=0; 33 34 length=src[srcStart++]; 35 36 37 if((length&0x8000) >0) { 38 39 length&=0x7fff; 40 if(src.length<(srcStart+1+length)) { 41 length=0; 42 throw new IndexOutOfBoundsException (); 43 } 44 bmpLength=src[srcStart++]; 45 } else { 46 47 if(src.length<(srcStart+length)) { 48 length=0; 49 throw new IndexOutOfBoundsException (); 50 } 51 bmpLength=length; 52 } 53 array = new char[length]; 54 System.arraycopy(src,srcStart,array,0,length); 55 return true; 57 } 58 59 64 public final void setToOne(int c) { 65 if( 0x10ffff<c) { 66 return; 67 } 68 69 if(c<0xffff) { 70 bmpLength=length=2; 71 array[0]=(char)c; 72 array[1]=(char)(c+1); 73 } else if(c==0xffff) { 74 bmpLength=1; 75 length=3; 76 array[0]=0xffff; 77 array[1]=1; 78 array[2]=0; 79 } else if(c<0x10ffff) { 80 bmpLength=0; 81 length=4; 82 array[0]=(char)(c>>16); 83 array[1]=(char)c; 84 ++c; 85 array[2]=(char)(c>>16); 86 array[3]=(char)c; 87 } else { 88 bmpLength=0; 89 length=2; 90 array[0]=0x10; 91 array[1]=0xffff; 92 } 93 } 94 95 104 public final boolean getRange(int rangeIndex, int[] range) { 105 if( rangeIndex<0) { 106 return false; 107 } 108 if(array==null){ 109 array = new char[8]; 110 } 111 if(range==null || range.length <2){ 112 throw new IllegalArgumentException (); 113 } 114 rangeIndex*=2; 115 if(rangeIndex<bmpLength) { 116 range[0]=array[rangeIndex++]; 117 if(rangeIndex<bmpLength) { 118 range[1]=array[rangeIndex]; 119 } else if(rangeIndex<length) { 120 range[1]=(((int)array[rangeIndex])<<16)|array[rangeIndex+1]; 121 } else { 122 range[1]=0x110000; 123 } 124 range[1]-=1; 125 return true; 126 } else { 127 rangeIndex-=bmpLength; 128 rangeIndex*=2; 129 length-=bmpLength; 130 if(rangeIndex<length) { 131 int offset=arrayOffset+bmpLength; 132 range[0]=(((int)array[offset+rangeIndex])<<16)|array[offset+rangeIndex+1]; 133 rangeIndex+=2; 134 if(rangeIndex<length) { 135 range[1]=(((int)array[offset+rangeIndex])<<16)|array[offset+rangeIndex+1]; 136 } else { 137 range[1]=0x110000; 138 } 139 range[1]-=1; 140 return true; 141 } else { 142 return false; 143 } 144 } 145 } 146 147 154 public final boolean contains(int c) { 156 157 if(c>0x10ffff) { 158 return false; 159 } 160 161 if(c<=0xffff) { 162 int i; 163 164 for(i=0; i<bmpLength && (char)c>=array[i]; ++i) {} 165 return (boolean)((i&1) != 0); 166 } else { 167 int i; 168 169 char high=(char)(c>>16), low=(char)c; 170 for(i=bmpLength; 171 i<length && (high>array[i] || (high==array[i] && low>=array[i+1])); 172 i+=2) {} 173 174 175 return (boolean)(((i+bmpLength)&2)!=0); 176 } 177 } 178 187 public final int countRanges() { 188 return (bmpLength+(length-bmpLength)/2+1)/2; 189 } 190 191 private char array[] = new char[8]; 192 private int arrayOffset, bmpLength, length; 193 } 194 | Popular Tags |