sun.text.normalizer.UCharacter Java Examples

The following examples show how to use sun.text.normalizer.UCharacter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bug6850113.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #2
Source File: Bug6850113.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #3
Source File: BidiBase.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: Bug6850113.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #5
Source File: BidiBase.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #6
Source File: BidiBase.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #7
Source File: Bug6850113.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #8
Source File: BidiBase.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #9
Source File: Bug6850113.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #10
Source File: BidiBase.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #11
Source File: StringPrep.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an StringPrep object after reading the input stream.
 * The object does not hold a reference to the input steam, so the stream can be
 * closed after the method returns.
 *
 * @param inputStream The stream for reading the StringPrep profile binarySun
 * @throws IOException
 * @draft ICU 2.8
 */
public StringPrep(InputStream inputStream) throws IOException{

    BufferedInputStream b = new BufferedInputStream(inputStream,DATA_BUFFER_SIZE);

    StringPrepDataReader reader = new StringPrepDataReader(b);

    // read the indexes
    indexes = reader.readIndexes(INDEX_TOP);

    byte[] sprepBytes = new byte[indexes[INDEX_TRIE_SIZE]];


    //indexes[INDEX_MAPPING_DATA_SIZE] store the size of mappingData in bytes
    mappingData = new char[indexes[INDEX_MAPPING_DATA_SIZE]/2];
    // load the rest of the data data and initialize the data members
    reader.read(sprepBytes,mappingData);

    sprepTrieImpl           = new StringPrepTrieImpl();
    sprepTrieImpl.sprepTrie = new CharTrie( new ByteArrayInputStream(sprepBytes),sprepTrieImpl  );

    // get the data format version
    formatVersion = reader.getDataFormatVersion();

    // get the options
    doNFKC            = ((indexes[OPTIONS] & NORMALIZATION_ON) > 0);
    checkBiDi         = ((indexes[OPTIONS] & CHECK_BIDI_ON) > 0);
    sprepUniVer   = getVersionInfo(reader.getUnicodeVersion());
    normCorrVer   = getVersionInfo(indexes[NORM_CORRECTNS_LAST_UNI_VERSION]);
    VersionInfo normUniVer = UCharacter.getUnicodeVersion();
    if(normUniVer.compareTo(sprepUniVer) < 0 && /* the Unicode version of SPREP file must be less than the Unicode Vesion of the normalization data */
       normUniVer.compareTo(normCorrVer) < 0 && /* the Unicode version of the NormalizationCorrections.txt file should be less than the Unicode Vesion of the normalization data */
       ((indexes[OPTIONS] & NORMALIZATION_ON) > 0) /* normalization turned on*/
       ){
        throw new IOException("Normalization Correction version not supported");
    }
    b.close();
}
 
Example #12
Source File: Bug6850113.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #13
Source File: BidiBase.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #14
Source File: StringPrep.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an StringPrep object after reading the input stream.
 * The object does not hold a reference to the input steam, so the stream can be
 * closed after the method returns.
 *
 * @param inputStream The stream for reading the StringPrep profile binarySun
 * @throws IOException
 * @draft ICU 2.8
 */
public StringPrep(InputStream inputStream) throws IOException{

    BufferedInputStream b = new BufferedInputStream(inputStream,DATA_BUFFER_SIZE);

    StringPrepDataReader reader = new StringPrepDataReader(b);

    // read the indexes
    indexes = reader.readIndexes(INDEX_TOP);

    byte[] sprepBytes = new byte[indexes[INDEX_TRIE_SIZE]];


    //indexes[INDEX_MAPPING_DATA_SIZE] store the size of mappingData in bytes
    mappingData = new char[indexes[INDEX_MAPPING_DATA_SIZE]/2];
    // load the rest of the data and initialize the data members
    reader.read(sprepBytes,mappingData);

    sprepTrieImpl           = new StringPrepTrieImpl();
    sprepTrieImpl.sprepTrie = new CharTrie( new ByteArrayInputStream(sprepBytes),sprepTrieImpl  );

    // get the data format version
    formatVersion = reader.getDataFormatVersion();

    // get the options
    doNFKC            = ((indexes[OPTIONS] & NORMALIZATION_ON) > 0);
    checkBiDi         = ((indexes[OPTIONS] & CHECK_BIDI_ON) > 0);
    sprepUniVer   = getVersionInfo(reader.getUnicodeVersion());
    normCorrVer   = getVersionInfo(indexes[NORM_CORRECTNS_LAST_UNI_VERSION]);
    VersionInfo normUniVer = UCharacter.getUnicodeVersion();
    if(normUniVer.compareTo(sprepUniVer) < 0 && /* the Unicode version of SPREP file must be less than the Unicode Vesion of the normalization data */
       normUniVer.compareTo(normCorrVer) < 0 && /* the Unicode version of the NormalizationCorrections.txt file should be less than the Unicode Vesion of the normalization data */
       ((indexes[OPTIONS] & NORMALIZATION_ON) > 0) /* normalization turned on*/
       ){
        throw new IOException("Normalization Correction version not supported");
    }
    b.close();
}
 
Example #15
Source File: BidiBase.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #16
Source File: Bug6850113.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #17
Source File: Bug6850113.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #18
Source File: Bug6850113.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #19
Source File: BidiBase.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #20
Source File: Bug6850113.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #21
Source File: BidiBase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #22
Source File: BidiBase.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #23
Source File: Bug6850113.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #24
Source File: BidiBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #25
Source File: Bug6850113.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #26
Source File: Bug6850113.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
     boolean err = false;

     // Fullwidth Latin capital letters
     for (int i = 0xff21, j = 10; i <= 0xff3a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     // Fullwidth Latin small letters
     for (int i = 0xff41, j = 10; i <= 0xff5a; i++, j++) {
         if (UCharacter.digit(i, 36) != j) {
             err = true;
             System.out.println("Error: UCharacter.digit(0x" +
                 Integer.toHexString(i) + ", 36) returned " +
                 UCharacter.digit(i, 36) + ", expected=" + j);
         }
     }

     if (err) {
         throw new RuntimeException("UCharacter.digit():  Wrong return value");
     }
}
 
Example #27
Source File: BidiBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #28
Source File: StringPrep.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
 * checks for prohited and BiDi characters in the order defined by RFC 3454
 * depending on the options specified in the profile.
 *
 * @param src           A UCharacterIterator object containing the source string
 * @param options       A bit set of options:
 *
 *  - StringPrep.NONE               Prohibit processing of unassigned code points in the input
 *
 *  - StringPrep.ALLOW_UNASSIGNED   Treat the unassigned code points are in the input
 *                                  as normal Unicode code points.
 *
 * @return StringBuffer A StringBuffer containing the output
 * @throws ParseException
 * @draft ICU 2.8
 */
public StringBuffer prepare(UCharacterIterator src, int options)
                    throws ParseException{

    // map
    StringBuffer mapOut = map(src,options);
    StringBuffer normOut = mapOut;// initialize

    if(doNFKC){
        // normalize
        normOut = normalize(mapOut);
    }

    int ch;
    char result;
    UCharacterIterator iter = UCharacterIterator.getInstance(normOut);
    Values val = new Values();
    int direction=UCharacterDirection.CHAR_DIRECTION_COUNT,
        firstCharDir=UCharacterDirection.CHAR_DIRECTION_COUNT;
    int rtlPos=-1, ltrPos=-1;
    boolean rightToLeft=false, leftToRight=false;

    while((ch=iter.nextCodePoint())!= UCharacterIterator.DONE){
        result = getCodePointValue(ch);
        getValues(result,val);

        if(val.type == PROHIBITED ){
            throw new ParseException("A prohibited code point was found in the input" +
                                     iter.getText(), val.value);
        }

        direction = UCharacter.getDirection(ch);
        if(firstCharDir == UCharacterDirection.CHAR_DIRECTION_COUNT){
            firstCharDir = direction;
        }
        if(direction == UCharacterDirection.LEFT_TO_RIGHT){
            leftToRight = true;
            ltrPos = iter.getIndex()-1;
        }
        if(direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC){
            rightToLeft = true;
            rtlPos = iter.getIndex()-1;
        }
    }
    if(checkBiDi == true){
        // satisfy 2
        if( leftToRight == true && rightToLeft == true){
            throw new ParseException("The input does not conform to the rules for BiDi code points." +
                                     iter.getText(),
                                     (rtlPos>ltrPos) ? rtlPos : ltrPos);
         }

        //satisfy 3
        if( rightToLeft == true &&
            !((firstCharDir == UCharacterDirection.RIGHT_TO_LEFT || firstCharDir == UCharacterDirection.RIGHT_TO_LEFT_ARABIC) &&
            (direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC))
          ){
            throw new ParseException("The input does not conform to the rules for BiDi code points." +
                                     iter.getText(),
                                     (rtlPos>ltrPos) ? rtlPos : ltrPos);
        }
    }
    return normOut;

  }
 
Example #29
Source File: StringPrep.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
 * checks for prohited and BiDi characters in the order defined by RFC 3454
 * depending on the options specified in the profile.
 *
 * @param src           A UCharacterIterator object containing the source string
 * @param options       A bit set of options:
 *
 *  - StringPrep.NONE               Prohibit processing of unassigned code points in the input
 *
 *  - StringPrep.ALLOW_UNASSIGNED   Treat the unassigned code points are in the input
 *                                  as normal Unicode code points.
 *
 * @return StringBuffer A StringBuffer containing the output
 * @throws ParseException
 * @draft ICU 2.8
 */
public StringBuffer prepare(UCharacterIterator src, int options)
                    throws ParseException{

    // map
    StringBuffer mapOut = map(src,options);
    StringBuffer normOut = mapOut;// initialize

    if(doNFKC){
        // normalize
        normOut = normalize(mapOut);
    }

    int ch;
    char result;
    UCharacterIterator iter = UCharacterIterator.getInstance(normOut);
    Values val = new Values();
    int direction=UCharacterDirection.CHAR_DIRECTION_COUNT,
        firstCharDir=UCharacterDirection.CHAR_DIRECTION_COUNT;
    int rtlPos=-1, ltrPos=-1;
    boolean rightToLeft=false, leftToRight=false;

    while((ch=iter.nextCodePoint())!= UCharacterIterator.DONE){
        result = getCodePointValue(ch);
        getValues(result,val);

        if(val.type == PROHIBITED ){
            throw new ParseException("A prohibited code point was found in the input" +
                                     iter.getText(), val.value);
        }

        direction = UCharacter.getDirection(ch);
        if(firstCharDir == UCharacterDirection.CHAR_DIRECTION_COUNT){
            firstCharDir = direction;
        }
        if(direction == UCharacterDirection.LEFT_TO_RIGHT){
            leftToRight = true;
            ltrPos = iter.getIndex()-1;
        }
        if(direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC){
            rightToLeft = true;
            rtlPos = iter.getIndex()-1;
        }
    }
    if(checkBiDi == true){
        // satisfy 2
        if( leftToRight == true && rightToLeft == true){
            throw new ParseException("The input does not conform to the rules for BiDi code points." +
                                     iter.getText(),
                                     (rtlPos>ltrPos) ? rtlPos : ltrPos);
         }

        //satisfy 3
        if( rightToLeft == true &&
            !((firstCharDir == UCharacterDirection.RIGHT_TO_LEFT || firstCharDir == UCharacterDirection.RIGHT_TO_LEFT_ARABIC) &&
            (direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC))
          ){
            throw new ParseException("The input does not conform to the rules for BiDi code points." +
                                     iter.getText(),
                                     (rtlPos>ltrPos) ? rtlPos : ltrPos);
        }
    }
    return normOut;

  }
 
Example #30
Source File: StringPrep.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
 * checks for prohited and BiDi characters in the order defined by RFC 3454
 * depending on the options specified in the profile.
 *
 * @param src           A UCharacterIterator object containing the source string
 * @param options       A bit set of options:
 *
 *  - StringPrep.NONE               Prohibit processing of unassigned code points in the input
 *
 *  - StringPrep.ALLOW_UNASSIGNED   Treat the unassigned code points are in the input
 *                                  as normal Unicode code points.
 *
 * @return StringBuffer A StringBuffer containing the output
 * @throws ParseException
 * @draft ICU 2.8
 */
public StringBuffer prepare(UCharacterIterator src, int options)
                    throws ParseException{

    // map
    StringBuffer mapOut = map(src,options);
    StringBuffer normOut = mapOut;// initialize

    if(doNFKC){
        // normalize
        normOut = normalize(mapOut);
    }

    int ch;
    char result;
    UCharacterIterator iter = UCharacterIterator.getInstance(normOut);
    Values val = new Values();
    int direction=UCharacterDirection.CHAR_DIRECTION_COUNT,
        firstCharDir=UCharacterDirection.CHAR_DIRECTION_COUNT;
    int rtlPos=-1, ltrPos=-1;
    boolean rightToLeft=false, leftToRight=false;

    while((ch=iter.nextCodePoint())!= UCharacterIterator.DONE){
        result = getCodePointValue(ch);
        getValues(result,val);

        if(val.type == PROHIBITED ){
            throw new ParseException("A prohibited code point was found in the input" +
                                     iter.getText(), val.value);
        }

        direction = UCharacter.getDirection(ch);
        if(firstCharDir == UCharacterDirection.CHAR_DIRECTION_COUNT){
            firstCharDir = direction;
        }
        if(direction == UCharacterDirection.LEFT_TO_RIGHT){
            leftToRight = true;
            ltrPos = iter.getIndex()-1;
        }
        if(direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC){
            rightToLeft = true;
            rtlPos = iter.getIndex()-1;
        }
    }
    if(checkBiDi == true){
        // satisfy 2
        if( leftToRight == true && rightToLeft == true){
            throw new ParseException("The input does not conform to the rules for BiDi code points." +
                                     iter.getText(),
                                     (rtlPos>ltrPos) ? rtlPos : ltrPos);
         }

        //satisfy 3
        if( rightToLeft == true &&
            !((firstCharDir == UCharacterDirection.RIGHT_TO_LEFT || firstCharDir == UCharacterDirection.RIGHT_TO_LEFT_ARABIC) &&
            (direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC))
          ){
            throw new ParseException("The input does not conform to the rules for BiDi code points." +
                                     iter.getText(),
                                     (rtlPos>ltrPos) ? rtlPos : ltrPos);
        }
    }
    return normOut;

  }