UCharacterProperty.java 14.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.agl.impl;

import com.adobe.agl.impl.*;
import com.adobe.agl.lang.UCharacter;
import com.adobe.agl.text.Normalizer;
import com.adobe.agl.text.UTF16;
import com.adobe.agl.text.UnicodeSet;
import com.adobe.agl.util.RangeValueIterator;
import com.adobe.agl.util.VersionInfo;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.MissingResourceException;

public final class UCharacterProperty {
    public CharTrie m_trie_;
    public char[] m_trieIndex_;
    public char[] m_trieData_;
    public int m_trieInitialValue_;
    public VersionInfo m_unicodeVersion_;
    private static final int GC_CN_MASK = UCharacterProperty.getMask(0);
    private static final int GC_CC_MASK = UCharacterProperty.getMask(15);
    private static final int GC_CS_MASK = UCharacterProperty.getMask(18);
    private static final int GC_ZS_MASK = UCharacterProperty.getMask(12);
    private static final int GC_ZL_MASK = UCharacterProperty.getMask(13);
    private static final int GC_ZP_MASK = UCharacterProperty.getMask(14);
    private static final int GC_Z_MASK = GC_ZS_MASK | GC_ZL_MASK | GC_ZP_MASK;
    BinaryProperties[] binProps = new BinaryProperties[]{new BinaryProperties(1, 256), new BinaryProperties(1, 128), new BinaryProperties(7, 0), new BinaryProperties(7, 0), new BinaryProperties(1, 2), new BinaryProperties(1, 524288), new BinaryProperties(1, 0x100000), new BinaryProperties(1, 1024), new BinaryProperties(1, 2048), new BinaryProperties(5, 0), new BinaryProperties(1, 0x4000000), new BinaryProperties(1, 8192), new BinaryProperties(1, 16384), new BinaryProperties(1, 64), new BinaryProperties(1, 4), new BinaryProperties(1, 0x2000000), new BinaryProperties(1, 0x1000000), new BinaryProperties(1, 512), new BinaryProperties(1, 32768), new BinaryProperties(1, 65536), new BinaryProperties(7, 0), new BinaryProperties(1, 0x200000), new BinaryProperties(6, 0), new BinaryProperties(1, 32), new BinaryProperties(1, 4096), new BinaryProperties(1, 8), new BinaryProperties(1, 131072), new BinaryProperties(6, 0), new BinaryProperties(1, 16), new BinaryProperties(1, 262144), new BinaryProperties(6, 0), new BinaryProperties(1, 1), new BinaryProperties(1, 0x800000), new BinaryProperties(1, 0x400000), new BinaryProperties(6, 0), new BinaryProperties(1, 0x8000000), new BinaryProperties(1, 0x10000000), new BinaryProperties(5, 0), new BinaryProperties(5, 0), new BinaryProperties(5, 0), new BinaryProperties(5, 0), new BinaryProperties(5, 0), new BinaryProperties(1, 0x20000000), new BinaryProperties(1, 0x40000000), new BinaryProperties(8, 0), new BinaryProperties(1, 0), new BinaryProperties(1, 0), new BinaryProperties(1, 0), new BinaryProperties(1, 0)};
    CharTrie m_additionalTrie_;
    int[] m_additionalVectors_;
    int m_additionalColumnsCount_;
    int m_maxBlockScriptValue_;
    int m_maxJTGValue_;
    private static UCharacterProperty INSTANCE_ = null;

    public void setIndexData(CharTrie.FriendAgent friendagent) {
        this.m_trieIndex_ = friendagent.getPrivateIndex();
        this.m_trieData_ = friendagent.getPrivateData();
        this.m_trieInitialValue_ = friendagent.getPrivateInitialValue();
    }

    public final int getProperty(int ch) {
        if (ch < 55296 || ch > 56319 && ch < 65536) {
            try {
                return this.m_trieData_[(this.m_trieIndex_[ch >> 5] << 2) + (ch & 31)];
            }
            catch (ArrayIndexOutOfBoundsException e) {
                return this.m_trieInitialValue_;
            }
        }
        if (ch <= 56319) {
            return this.m_trieData_[(this.m_trieIndex_[320 + (ch >> 5)] << 2) + (ch & 31)];
        }
        if (ch <= 1114111) {
            return this.m_trie_.getSurrogateValue(UTF16.getLeadSurrogate(ch), (char)(ch & 1023));
        }
        return this.m_trieInitialValue_;
    }

    public static int getUnsignedValue(int prop) {
        return prop >> 8 & 255;
    }

    public int getAdditional(int codepoint, int column) {
        if (column == -1) {
            return this.getProperty(codepoint);
        }
        if (column < 0 || column >= this.m_additionalColumnsCount_) {
            return 0;
        }
        return this.m_additionalVectors_[this.m_additionalTrie_.getCodePointValue(codepoint) + column];
    }

    public VersionInfo getAge(int codepoint) {
        int version = this.getAdditional(codepoint, 0) >> 24;
        return VersionInfo.getInstance(version >> 4 & 15, version & 15, 0, 0);
    }

    private static final boolean isgraphPOSIX(int c) {
        return (UCharacterProperty.getMask(UCharacter.getType(c)) & (GC_CC_MASK | GC_CS_MASK | GC_CN_MASK | GC_Z_MASK)) == 0;
    }

    public boolean hasBinaryProperty(int codepoint, int property) {
        if (property < 0 || 49 <= property) {
            return false;
        }
        long mask = this.binProps[property].mask;
        int column = this.binProps[property].column;
        if (mask != 0) {
            return (0xFFFFFFFFL & (long)this.getAdditional(codepoint, column) & mask) != 0;
        }
        if (column == 6) {
            UCaseProps csp;
            try {
                csp = UCaseProps.getSingleton();
            }
            catch (IOException e) {
                return false;
            }
            switch (property) {
                case 22: {
                    return 1 == csp.getType(codepoint);
                }
                case 30: {
                    return 2 == csp.getType(codepoint);
                }
                case 27: {
                    return csp.isSoftDotted(codepoint);
                }
                case 34: {
                    return csp.isCaseSensitive(codepoint);
                }
            }
        } else if (column == 5) {
            switch (property) {
                case 9: {
                    return NormalizerImpl.isFullCompositionExclusion(codepoint);
                }
                case 37: {
                    return Normalizer.isNFSkippable(codepoint, Normalizer.NFD);
                }
                case 38: {
                    return Normalizer.isNFSkippable(codepoint, Normalizer.NFKD);
                }
                case 39: {
                    return Normalizer.isNFSkippable(codepoint, Normalizer.NFC);
                }
                case 40: {
                    return Normalizer.isNFSkippable(codepoint, Normalizer.NFKC);
                }
                case 41: {
                    return NormalizerImpl.isCanonSafeStart(codepoint);
                }
            }
        } else if (column == 7) {
            UBiDiProps bdp;
            try {
                bdp = UBiDiProps.getSingleton();
            }
            catch (IOException e) {
                return false;
            }
            switch (property) {
                case 3: {
                    return bdp.isMirrored(codepoint);
                }
                case 2: {
                    return bdp.isBidiControl(codepoint);
                }
                case 20: {
                    return bdp.isJoinControl(codepoint);
                }
            }
        } else if (column == 1) {
            switch (property) {
                case 45: {
                    if (codepoint <= 159) {
                        return codepoint == 9 || codepoint == 32;
                    }
                    return UCharacter.getType(codepoint) == 12;
                }
                case 46: {
                    return UCharacterProperty.isgraphPOSIX(codepoint);
                }
                case 47: {
                    return UCharacter.getType(codepoint) == 12 || UCharacterProperty.isgraphPOSIX(codepoint);
                }
                case 48: {
                    if (codepoint <= 102 && codepoint >= 65 && (codepoint <= 70 || codepoint >= 97) || codepoint >= 65313 && codepoint <= 65350 && (codepoint <= 65318 || codepoint >= 65345)) {
                        return true;
                    }
                    return UCharacter.getType(codepoint) == 9;
                }
            }
        } else if (column == 8) {
            switch (property) {
                case 44: {
                    return UCharacter.isUAlphabetic(codepoint) || UCharacter.isDigit(codepoint);
                }
            }
        }
        return false;
    }

    public final int getSource(int which) {
        if (which < 0) {
            return 0;
        }
        if (which < 49) {
            if (this.binProps[which].mask != 0) {
                return 2;
            }
            return this.binProps[which].column;
        }
        if (which < 4096) {
            return 0;
        }
        if (which < 4117) {
            switch (which) {
                case 4101: 
                case 4105: {
                    return 1;
                }
                case 4107: {
                    return 3;
                }
                case 4098: 
                case 4108: 
                case 4109: 
                case 4110: 
                case 4111: 
                case 4112: 
                case 4113: {
                    return 5;
                }
                case 4096: 
                case 4102: 
                case 4103: {
                    return 7;
                }
            }
            return 2;
        }
        if (which < 16384) {
            switch (which) {
                case 8192: 
                case 12288: {
                    return 1;
                }
            }
            return 0;
        }
        if (which < 16397) {
            switch (which) {
                case 16384: {
                    return 2;
                }
                case 16385: {
                    return 7;
                }
                case 16386: 
                case 16388: 
                case 16390: 
                case 16391: 
                case 16392: 
                case 16393: 
                case 16394: 
                case 16396: {
                    return 6;
                }
                case 16387: 
                case 16389: 
                case 16395: {
                    return 4;
                }
            }
            return 0;
        }
        return 0;
    }

    public static int getRawSupplementary(char lead, char trail) {
        return (lead << 10) + trail + -56613888;
    }

    public static UCharacterProperty getInstance() {
        if (INSTANCE_ == null) {
            try {
                INSTANCE_ = new UCharacterProperty();
            }
            catch (Exception e) {
                throw new MissingResourceException(e.getMessage(), "", "");
            }
        }
        return INSTANCE_;
    }

    public static boolean isRuleWhiteSpace(int c) {
        return c >= 9 && c <= 8233 && (c <= 13 || c == 32 || c == 133 || c == 8206 || c == 8207 || c >= 8232);
    }

    public static final int getMask(int type) {
        return 1 << type;
    }

    private UCharacterProperty() throws IOException {
        InputStream is = ICUData.getRequiredStream("data/icudt40b/uprops.icu");
        BufferedInputStream b = new BufferedInputStream(is, 25000);
        UCharacterPropertyReader reader = new UCharacterPropertyReader(b);
        reader.read(this);
        b.close();
        this.m_trie_.putIndexData(this);
    }

    public void uhst_addPropertyStarts(UnicodeSet set) {
        int c;
        int value2;
        set.add(4352);
        int value = 1;
        for (c = 4442; c <= 4447; ++c) {
            value2 = UCharacter.getIntPropertyValue(c, 4107);
            if (value == value2) continue;
            value = value2;
            set.add(c);
        }
        set.add(4448);
        value = 2;
        for (c = 4515; c <= 4519; ++c) {
            value2 = UCharacter.getIntPropertyValue(c, 4107);
            if (value == value2) continue;
            value = value2;
            set.add(c);
        }
        set.add(4520);
        value = 3;
        for (c = 4602; c <= 4607; ++c) {
            value2 = UCharacter.getIntPropertyValue(c, 4107);
            if (value == value2) continue;
            value = value2;
            set.add(c);
        }
        for (c = 44032; c < 55204; c += 28) {
            set.add(c);
            set.add(c + 1);
        }
        set.add(c);
    }

    public UnicodeSet addPropertyStarts(UnicodeSet set) {
        TrieIterator propsIter = new TrieIterator(this.m_trie_);
        RangeValueIterator.Element propsResult = new RangeValueIterator.Element();
        while (propsIter.next(propsResult)) {
            set.add(propsResult.start);
        }
        set.add(9);
        set.add(10);
        set.add(14);
        set.add(28);
        set.add(32);
        set.add(133);
        set.add(134);
        set.add(127);
        set.add(8202);
        set.add(8208);
        set.add(8298);
        set.add(8304);
        set.add(65279);
        set.add(65280);
        set.add(160);
        set.add(161);
        set.add(8199);
        set.add(8200);
        set.add(8239);
        set.add(8240);
        set.add(12295);
        set.add(12296);
        set.add(19968);
        set.add(19969);
        set.add(20108);
        set.add(20109);
        set.add(19977);
        set.add(19978);
        set.add(22235);
        set.add(22236);
        set.add(20116);
        set.add(20117);
        set.add(20845);
        set.add(20846);
        set.add(19971);
        set.add(19972);
        set.add(20843);
        set.add(20844);
        set.add(20061);
        set.add(20062);
        set.add(97);
        set.add(123);
        set.add(65);
        set.add(91);
        set.add(65345);
        set.add(65371);
        set.add(65313);
        set.add(65339);
        set.add(103);
        set.add(71);
        set.add(65351);
        set.add(65319);
        set.add(8288);
        set.add(65520);
        set.add(65532);
        set.add(917504);
        set.add(921600);
        set.add(847);
        set.add(848);
        return set;
    }

    public void upropsvec_addPropertyStarts(UnicodeSet set) {
        if (this.m_additionalColumnsCount_ > 0) {
            TrieIterator propsVectorsIter = new TrieIterator(this.m_additionalTrie_);
            RangeValueIterator.Element propsVectorsResult = new RangeValueIterator.Element();
            while (propsVectorsIter.next(propsVectorsResult)) {
                set.add(propsVectorsResult.start);
            }
        }
    }

    private static final class BinaryProperties {
        int column;
        long mask;

        public BinaryProperties(int column, long mask) {
            this.column = column;
            this.mask = mask;
        }
    }

}