Example usage for java.lang Character toChars

List of usage examples for java.lang Character toChars

Introduction

In this page you can find the example usage for java.lang Character toChars.

Prototype

public static char[] toChars(int codePoint) 

Source Link

Document

Converts the specified character (Unicode code point) to its UTF-16 representation stored in a char array.

Usage

From source file:org.openrdf.rio.ntriples.NTriplesParser.java

protected int parseObject(int c) throws IOException, RDFParseException {
    StringBuilder sb = getBuffer();

    // object is either an uriref (<foo://bar>), a nodeID (_:node1) or a
    // literal ("foo"-en or "1"^^<xsd:integer>).
    if (c == '<') {
        // object is an uriref
        c = parseUriRef(c, sb);//from  www  .j  ava2 s  .c om
        object = createURI(sb.toString());
    } else if (c == '_') {
        // object is a bNode
        c = parseNodeID(c, sb);
        object = createBNode(sb.toString());
    } else if (c == '"') {
        // object is a literal
        StringBuilder lang = getLanguageTagBuffer();
        StringBuilder datatype = getDatatypeUriBuffer();
        c = parseLiteral(c, sb, lang, datatype);
        object = createLiteral(sb.toString(), lang.toString(), datatype.toString());
    } else if (c == -1) {
        throwEOFException();
    } else {
        reportFatalError("Expected '<', '_' or '\"', found: " + new String(Character.toChars(c)) + "");
    }

    return c;
}

From source file:org.eclipse.rdf4j.rio.ntriples.NTriplesParser.java

protected int parseUriRef(int c, StringBuilder uriRef) throws IOException, RDFParseException {
    if (c != '<') {
        reportError("Supplied char should be a '<', is: " + new String(Character.toChars(c)),
                NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
    }//from   ww  w  .  j a  v  a  2 s  .c o m
    // Read up to the next '>' character
    c = readCodePoint();
    while (c != '>') {
        if (c == -1) {
            throwEOFException();
        }
        if (c == ' ') {
            reportError("IRI included an unencoded space: " + new String(Character.toChars(c)),
                    BasicParserSettings.VERIFY_URI_SYNTAX);
        }
        uriRef.append(Character.toChars(c));

        if (c == '\\') {
            // This escapes the next character, which might be a '>'
            c = readCodePoint();
            if (c == -1) {
                throwEOFException();
            }
            if (c != 'u' && c != 'U') {
                reportError("IRI includes string escapes: '\\" + c + "'",
                        BasicParserSettings.VERIFY_URI_SYNTAX);
            }
            uriRef.append(Character.toChars(c));
        }

        c = readCodePoint();
    }

    // c == '>', read next char
    c = readCodePoint();

    return c;
}

From source file:org.openrdf.rio.ntriples.NTriplesParser.java

protected int parseUriRef(int c, StringBuilder uriRef) throws IOException, RDFParseException {
    if (c != '<') {
        reportError("Supplied char should be a '<', is: " + new String(Character.toChars(c)),
                NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
    }//from  ww w  .  j  a va2  s  . c o  m
    // Read up to the next '>' character
    c = readCodePoint();
    while (c != '>') {
        if (c == -1) {
            throwEOFException();
        }
        if (c == ' ') {
            reportError("IRI included an unencoded space: " + new String(Character.toChars(c)),
                    NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
        }
        uriRef.append(Character.toChars(c));

        if (c == '\\') {
            // This escapes the next character, which might be a '>'
            c = readCodePoint();
            if (c == -1) {
                throwEOFException();
            }
            if (c != 'u' && c != 'U') {
                reportError("IRI includes string escapes: '\\" + c + "'",
                        NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
            }
            uriRef.append(Character.toChars(c));
        }

        c = readCodePoint();
    }

    // c == '>', read next char
    c = readCodePoint();

    return c;
}

From source file:de.vandermeer.asciithemes.u8.U8_NumberingSchemes.java

/**
 * Numbering scheme case UTF Subscript characters `?-`.
 * /*from ww  w  .j av a 2  s .  c o  m*/
 * ----
 * ? item 1
 *  item 2
 *  item 3
 * ...
 *  item 9
 * ----
 * 
 * @return the line
 */
public static TA_Numbering numberSubscript() {
    return new TA_Numbering() {
        @Override
        public String getNumber(int number) {
            Validate.validState(0 < number && number < 10,
                    "numbering supported 0<number<10 - number was: " + number);
            return new String(Character.toChars(number + 8320));
        }

        @Override
        public int getMinNumber() {
            return 1;
        }

        @Override
        public int getMaxNumber() {
            return 9;
        }

        @Override
        public String getDescription() {
            return "numbering scheme using UTF Subscript characters '?-'";
        }
    };
}

From source file:spark.help.CustomNTriplesParser.java

protected int parseObject(int c, StringBuilder sb) throws IOException, RDFParseException {
    //StringBuilder sb = getBuffer();

    // object is either an uriref (<foo://bar>), a nodeID (_:node1) or a
    // literal ("foo"-en or "1"^^<xsd:integer>).
    if (c == '<') {
        // object is an uriref
        //object = "";
        c = parseUriRef(c, sb);/*from  w  ww  . ja v a2  s . co m*/
        //object = sb.toString();
        //object = createURI(sb.toString());
    } else if (c == '_') {
        // object is a bNode
        //object = "";
        c = parseNodeID(c, sb);
        //object = sb.toString();
        //object = createBNode(sb.toString());
    } else if (c == '"') {
        // object is a literal
        //object = "";
        //String lang = getLanguageTagBuffer();
        //String datatype = getDatatypeUriBuffer();
        c = parseLiteral(c, sb, this.languageTag, this.datatypeUri);

        //String o = "";
        //StringBuilder sb = new StringBuilder(label.length() * 2);

        sb.insert(0, '"');
        sb.append('"');
        //object = '"' + object + '"';

        if (this.languageTag.length() != 0) {
            sb.append('@');
            sb.append(this.languageTag.toString());
        } else if (this.datatypeUri.length() != 0) {
            sb.append("^^<");
            sb.append(this.datatypeUri.toString());
            sb.append(">");
        }

        //createLiteral(sb.toString(), lang.toString(), datatype.toString());
    } else if (c == -1) {
        throwEOFException();
    } else {
        reportFatalError("Expected '<', '_' or '\"', found: " + new String(Character.toChars(c)) + "");
    }

    return c;
}

From source file:org.commoncrawl.util.shared.ArcFileReaderTests.java

static String randomString(final Random random, final int minLength, final int maxLength) {
    final int length = random.nextInt(maxLength - minLength) + minLength;
    final char[] chars = new char[length];
    for (int i = 0, x = chars.length; i < x;)
        do {/*w ww  .  j  a  v  a  2  s  .  co m*/
            final int cp = random.nextInt(0x10FFFF + 1);
            if (!Character.isDefined(cp))
                continue;
            final char[] chs = Character.toChars(cp);
            if (chs.length > x - i)
                continue;
            for (final char ch : chs) {
                if (!Character.isWhitespace(ch)) {
                    chars[i++] = ch;
                }
            }
            break;

        } while (true);

    return new String(chars);
}

From source file:spark.help.CustomNTriplesParser.java

protected int parseUriRef(int c, StringBuilder sb) throws IOException, RDFParseException {
    if (c != '<') {
        reportError("Supplied char should be a '<', is: " + new String(Character.toChars(c)),
                NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
    }//from   w w w .  j ava2  s  .c  om
    // Read up to the next '>' character
    c = readCodePoint();
    while (c != '>') {
        if (c == -1) {
            throwEOFException();
        }
        if (c == ' ') {
            reportError("IRI included an unencoded space: " + new String(Character.toChars(c)),
                    NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
        }
        sb.append(Character.toChars(c));

        if (c == '\\') {
            // This escapes the next character, which might be a '>'
            c = readCodePoint();
            if (c == -1) {
                throwEOFException();
            }
            if (c != 'u' && c != 'U') {
                reportError("IRI includes string escapes: '\\" + c + "'",
                        NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
            }
            sb.append(Character.toChars(c));
        }

        c = readCodePoint();
    }

    // c == '>', read next char
    c = readCodePoint();

    return c;
}

From source file:org.sweble.wikitext.engine.MassExpansionTest.java

/**
 * Convert XML char refs to chars and convert "<nowiki></nowiki>" to an
 * empty tag.//from   ww  w  . j  av a2  s  .c o  m
 */
private String polishRawResult(String raw) {
    StringBuilder b = new StringBuilder();

    int copyFrom = 0;
    int searchFrom = 0;
    int i;
    while ((i = raw.indexOf("&#x", searchFrom)) != -1) {
        searchFrom = i + 3;
        int j = raw.indexOf(';', searchFrom);
        if (j == -1 || j > i + 12)
            continue;

        int ch = Integer.valueOf(raw.substring(i + 3, j), 0x10);
        switch (ch) {
        case 0x7B: // {
        case 0x7D: // }
        case 0x7C: // |
        case 0x3D: // =
            break;
        default:
            continue;
        }
        b.append(raw.substring(copyFrom, i));
        b.append(Character.toChars(ch));

        searchFrom = copyFrom = j + 1;
    }
    b.append(raw.substring(copyFrom, raw.length()));

    return b.toString().replace("<nowiki></nowiki>", "<nowiki />");
}

From source file:org.eclipse.rdf4j.rio.ntriples.NTriplesParser.java

protected int parseNodeID(int c, StringBuilder name) throws IOException, RDFParseException {
    if (c != '_') {
        reportError("Supplied char should be a '_', is: " + new String(Character.toChars(c)),
                NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
    }//from   www  .j a v  a  2s  .  com

    c = readCodePoint();
    if (c == -1) {
        throwEOFException();
    } else if (c != ':') {
        reportError("Expected ':', found: " + new String(Character.toChars(c)),
                NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
    }

    c = readCodePoint();
    if (c == -1) {
        throwEOFException();
    } else if (!NTriplesUtil.isLetterOrNumber(c)) {
        reportError("Expected a letter or number, found: " + new String(Character.toChars(c)),
                NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
    }
    name.append(Character.toChars(c));

    // Read all following letter and numbers, they are part of the name
    c = readCodePoint();
    while (c != -1 && NTriplesUtil.isLetterOrNumber(c)) {
        name.append(Character.toChars(c));
        c = readCodePoint();
    }

    return c;
}

From source file:de.vandermeer.asciithemes.u8.U8_NumberingSchemes.java

/**
 * Numbering scheme case UTF Full Stop characters `-`.
 * // ww w . ja  v a2 s  . co m
 * ----
 *  item 1
 *  item 2
 *  item 3
 * ...
 *  item 20
 * ----
 * 
 * @return the line
 */
public static TA_Numbering numberFullStop() {
    return new TA_Numbering() {
        @Override
        public String getNumber(int number) {
            Validate.validState(0 < number && number < 21,
                    "numbering supported 0<number<21 - number was: " + number);
            return new String(Character.toChars(number + 9351));
        }

        @Override
        public int getMinNumber() {
            return 1;
        }

        @Override
        public int getMaxNumber() {
            return 20;
        }

        @Override
        public String getDescription() {
            return "numbering scheme using UTF Full Stop characters '-'";
        }
    };
}