Java Code Examples for sun.text.normalizer.UCharacter#getDirection()

The following examples show how to use sun.text.normalizer.UCharacter#getDirection() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 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: 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 10
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;

  }
 
Example 11
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 12
Source File: StringPrep.java    From openjdk-8-source 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 13
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 14
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;

  }
 
Example 15
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;

  }
 
Example 16
Source File: StringPrep.java    From openjdk-jdk8u-backup 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 17
Source File: StringPrep.java    From openjdk-jdk8u 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 18
Source File: StringPrep.java    From jdk8u60 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 19
Source File: StringPrep.java    From TencentKona-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 20
Source File: StringPrep.java    From dragonwell8_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;

  }