sun.net.idn.Punycode Java Examples

The following examples show how to use sun.net.idn.Punycode. 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: PunycodeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #2
Source File: PunycodeTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #3
Source File: PunycodeTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #4
Source File: PunycodeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #5
Source File: PunycodeTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #6
Source File: PunycodeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #7
Source File: PunycodeTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #8
Source File: PunycodeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #9
Source File: PunycodeTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #10
Source File: PunycodeTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #11
Source File: PunycodeTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #12
Source File: PunycodeTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #13
Source File: PunycodeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public String testDecoding(String inputS) {
    char input[] = new char[0];
    int pp;
    StringBuffer output;

    /* Read the Punycode input string and convert to ASCII: */

    if (inputS.length() <= ace_max_length+2) {
        input = inputS.toCharArray();
    } else {
        fail(invalid_input, inputS);
    }
    input_length = input.length;

    /* Decode: */

    output_length[0] = unicode_max_length;
    try {
        output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    /* Output the result: */
    StringBuffer result = new StringBuffer();
    for (j = 0;  j < output.length();  ++j) {
        result.append(String.format("%s+%04X ",
                case_flags[j] ? "U" : "u",
                (int)output.charAt(j) ));
    }

    testCount++;
    return result.substring(0, result.length() - 1);
}
 
Example #14
Source File: PunycodeTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example #15
Source File: PunycodeTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example #16
Source File: PunycodeTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example #17
Source File: PunycodeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example #18
Source File: IDN.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static String toUnicodeInternal(String label, int flag) {
    boolean[] caseFlags = null;
    StringBuffer dest;

    // step 1
    // find out if all the codepoints in input are ASCII
    boolean isASCII = isAllASCII(label);

    if(!isASCII){
        // step 2
        // perform the nameprep operation; flag ALLOW_UNASSIGNED is used here
        try {
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            dest = namePrep.prepare(iter, flag);
        } catch (Exception e) {
            // toUnicode never fails; if any step fails, return the input string
            return label;
        }
    } else {
        dest = new StringBuffer(label);
    }

    // step 3
    // verify ACE Prefix
    if(startsWithACEPrefix(dest)) {

        // step 4
        // Remove the ACE Prefix
        String temp = dest.substring(ACE_PREFIX_LENGTH, dest.length());

        try {
            // step 5
            // Decode using punycode
            StringBuffer decodeOut = Punycode.decode(new StringBuffer(temp), null);

            // step 6
            // Apply toASCII
            String toASCIIOut = toASCII(decodeOut.toString(), flag);

            // step 7
            // verify
            if (toASCIIOut.equalsIgnoreCase(dest.toString())) {
                // step 8
                // return output of step 5
                return decodeOut.toString();
            }
        } catch (Exception ignored) {
            // no-op
        }
    }

    // just return the input
    return label;
}
 
Example #19
Source File: PunycodeTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example #20
Source File: IDN.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static String toUnicodeInternal(String label, int flag) {
    boolean[] caseFlags = null;
    StringBuffer dest;

    // step 1
    // find out if all the codepoints in input are ASCII
    boolean isASCII = isAllASCII(label);

    if(!isASCII){
        // step 2
        // perform the nameprep operation; flag ALLOW_UNASSIGNED is used here
        try {
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            dest = namePrep.prepare(iter, flag);
        } catch (Exception e) {
            // toUnicode never fails; if any step fails, return the input string
            return label;
        }
    } else {
        dest = new StringBuffer(label);
    }

    // step 3
    // verify ACE Prefix
    if(startsWithACEPrefix(dest)) {

        // step 4
        // Remove the ACE Prefix
        String temp = dest.substring(ACE_PREFIX_LENGTH, dest.length());

        try {
            // step 5
            // Decode using punycode
            StringBuffer decodeOut = Punycode.decode(new StringBuffer(temp), null);

            // step 6
            // Apply toASCII
            String toASCIIOut = toASCII(decodeOut.toString(), flag);

            // step 7
            // verify
            if (toASCIIOut.equalsIgnoreCase(dest.toString())) {
                // step 8
                // return output of step 5
                return decodeOut.toString();
            }
        } catch (Exception ignored) {
            // no-op
        }
    }

    // just return the input
    return label;
}
 
Example #21
Source File: IDN.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static String toUnicodeInternal(String label, int flag) {
    boolean[] caseFlags = null;
    StringBuffer dest;

    // step 1
    // find out if all the codepoints in input are ASCII
    boolean isASCII = isAllASCII(label);

    if(!isASCII){
        // step 2
        // perform the nameprep operation; flag ALLOW_UNASSIGNED is used here
        try {
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            dest = namePrep.prepare(iter, flag);
        } catch (Exception e) {
            // toUnicode never fails; if any step fails, return the input string
            return label;
        }
    } else {
        dest = new StringBuffer(label);
    }

    // step 3
    // verify ACE Prefix
    if(startsWithACEPrefix(dest)) {

        // step 4
        // Remove the ACE Prefix
        String temp = dest.substring(ACE_PREFIX_LENGTH, dest.length());

        try {
            // step 5
            // Decode using punycode
            StringBuffer decodeOut = Punycode.decode(new StringBuffer(temp), null);

            // step 6
            // Apply toASCII
            String toASCIIOut = toASCII(decodeOut.toString(), flag);

            // step 7
            // verify
            if (toASCIIOut.equalsIgnoreCase(dest.toString())) {
                // step 8
                // return output of step 5
                return decodeOut.toString();
            }
        } catch (Exception ignored) {
            // no-op
        }
    }

    // just return the input
    return label;
}
 
Example #22
Source File: IDN.java    From jdk-1.7-annotated with Apache License 2.0 4 votes vote down vote up
private static String toUnicodeInternal(String label, int flag) {
    boolean[] caseFlags = null;
    StringBuffer dest;

    // step 1
    // find out if all the codepoints in input are ASCII
    boolean isASCII = isAllASCII(label);

    if(!isASCII){
        // step 2
        // perform the nameprep operation; flag ALLOW_UNASSIGNED is used here
        try {
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            dest = namePrep.prepare(iter, flag);
        } catch (Exception e) {
            // toUnicode never fails; if any step fails, return the input string
            return label;
        }
    } else {
        dest = new StringBuffer(label);
    }

    // step 3
    // verify ACE Prefix
    if(startsWithACEPrefix(dest)) {

        // step 4
        // Remove the ACE Prefix
        String temp = dest.substring(ACE_PREFIX_LENGTH, dest.length());

        try {
            // step 5
            // Decode using punycode
            StringBuffer decodeOut = Punycode.decode(new StringBuffer(temp), null);

            // step 6
            // Apply toASCII
            String toASCIIOut = toASCII(decodeOut.toString(), flag);

            // step 7
            // verify
            if (toASCIIOut.equalsIgnoreCase(dest.toString())) {
                // step 8
                // return output of step 5
                return decodeOut.toString();
            }
        } catch (Exception ignored) {
            // no-op
        }
    }

    // just return the input
    return label;
}
 
Example #23
Source File: IDN.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static String toUnicodeInternal(String label, int flag) {
    boolean[] caseFlags = null;
    StringBuffer dest;

    // step 1
    // find out if all the codepoints in input are ASCII
    boolean isASCII = isAllASCII(label);

    if(!isASCII){
        // step 2
        // perform the nameprep operation; flag ALLOW_UNASSIGNED is used here
        try {
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            dest = namePrep.prepare(iter, flag);
        } catch (Exception e) {
            // toUnicode never fails; if any step fails, return the input string
            return label;
        }
    } else {
        dest = new StringBuffer(label);
    }

    // step 3
    // verify ACE Prefix
    if(startsWithACEPrefix(dest)) {

        // step 4
        // Remove the ACE Prefix
        String temp = dest.substring(ACE_PREFIX_LENGTH, dest.length());

        try {
            // step 5
            // Decode using punycode
            StringBuffer decodeOut = Punycode.decode(new StringBuffer(temp), null);

            // step 6
            // Apply toASCII
            String toASCIIOut = toASCII(decodeOut.toString(), flag);

            // step 7
            // verify
            if (toASCIIOut.equalsIgnoreCase(dest.toString())) {
                // step 8
                // return output of step 5
                return decodeOut.toString();
            }
        } catch (Exception ignored) {
            // no-op
        }
    }

    // just return the input
    return label;
}
 
Example #24
Source File: PunycodeTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example #25
Source File: PunycodeTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example #26
Source File: IDN.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static String toUnicodeInternal(String label, int flag) {
    boolean[] caseFlags = null;
    StringBuffer dest;

    // step 1
    // find out if all the codepoints in input are ASCII
    boolean isASCII = isAllASCII(label);

    if(!isASCII){
        // step 2
        // perform the nameprep operation; flag ALLOW_UNASSIGNED is used here
        try {
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            dest = namePrep.prepare(iter, flag);
        } catch (Exception e) {
            // toUnicode never fails; if any step fails, return the input string
            return label;
        }
    } else {
        dest = new StringBuffer(label);
    }

    // step 3
    // verify ACE Prefix
    if(startsWithACEPrefix(dest)) {

        // step 4
        // Remove the ACE Prefix
        String temp = dest.substring(ACE_PREFIX_LENGTH, dest.length());

        try {
            // step 5
            // Decode using punycode
            StringBuffer decodeOut = Punycode.decode(new StringBuffer(temp), null);

            // step 6
            // Apply toASCII
            String toASCIIOut = toASCII(decodeOut.toString(), flag);

            // step 7
            // verify
            if (toASCIIOut.equalsIgnoreCase(dest.toString())) {
                // step 8
                // return output of step 5
                return decodeOut.toString();
            }
        } catch (Exception ignored) {
            // no-op
        }
    }

    // just return the input
    return label;
}
 
Example #27
Source File: PunycodeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example #28
Source File: IDN.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static String toUnicodeInternal(String label, int flag) {
    boolean[] caseFlags = null;
    StringBuffer dest;

    // step 1
    // find out if all the codepoints in input are ASCII
    boolean isASCII = isAllASCII(label);

    if(!isASCII){
        // step 2
        // perform the nameprep operation; flag ALLOW_UNASSIGNED is used here
        try {
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            dest = namePrep.prepare(iter, flag);
        } catch (Exception e) {
            // toUnicode never fails; if any step fails, return the input string
            return label;
        }
    } else {
        dest = new StringBuffer(label);
    }

    // step 3
    // verify ACE Prefix
    if(startsWithACEPrefix(dest)) {

        // step 4
        // Remove the ACE Prefix
        String temp = dest.substring(ACE_PREFIX_LENGTH, dest.length());

        try {
            // step 5
            // Decode using punycode
            StringBuffer decodeOut = Punycode.decode(new StringBuffer(temp), null);

            // step 6
            // Apply toASCII
            String toASCIIOut = toASCII(decodeOut.toString(), flag);

            // step 7
            // verify
            if (toASCIIOut.equalsIgnoreCase(dest.toString())) {
                // step 8
                // return output of step 5
                return decodeOut.toString();
            }
        } catch (Exception ignored) {
            // no-op
        }
    }

    // just return the input
    return label;
}
 
Example #29
Source File: PunycodeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example #30
Source File: IDN.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static String toUnicodeInternal(String label, int flag) {
    boolean[] caseFlags = null;
    StringBuffer dest;

    // step 1
    // find out if all the codepoints in input are ASCII
    boolean isASCII = isAllASCII(label);

    if(!isASCII){
        // step 2
        // perform the nameprep operation; flag ALLOW_UNASSIGNED is used here
        try {
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            dest = namePrep.prepare(iter, flag);
        } catch (Exception e) {
            // toUnicode never fails; if any step fails, return the input string
            return label;
        }
    } else {
        dest = new StringBuffer(label);
    }

    // step 3
    // verify ACE Prefix
    if(startsWithACEPrefix(dest)) {

        // step 4
        // Remove the ACE Prefix
        String temp = dest.substring(ACE_PREFIX_LENGTH, dest.length());

        try {
            // step 5
            // Decode using punycode
            StringBuffer decodeOut = Punycode.decode(new StringBuffer(temp), null);

            // step 6
            // Apply toASCII
            String toASCIIOut = toASCII(decodeOut.toString(), flag);

            // step 7
            // verify
            if (toASCIIOut.equalsIgnoreCase(dest.toString())) {
                // step 8
                // return output of step 5
                return decodeOut.toString();
            }
        } catch (Exception ignored) {
            // no-op
        }
    }

    // just return the input
    return label;
}