Examples of TStringBuilder


Examples of org.teavm.classlib.java.lang.TStringBuilder

    public TString readLine() throws TIOException {
        requireOpened();
        if (eof && index >= count) {
            return null;
        }
        TStringBuilder line = new TStringBuilder();
        while (true) {
            if (index >= count) {
                if (!fillBuffer(0)) {
                    break;
                }
            }
            char ch = buffer[index++];
            if (ch == '\n') {
                break;
            } else if (ch == '\r') {
                if (index >= count) {
                    if (!fillBuffer(0)) {
                        break;
                    }
                }
                if (buffer[index] == '\n') {
                    ++index;
                }
                break;
            } else {
                line.append(ch);
            }
        }
        return TString.wrap(line.toString());
    }
View Full Code Here

Examples of org.teavm.classlib.java.lang.TStringBuilder

     *            java.lang.String the characters allowed to be preserved in the
     *            string s
     * @return java.lang.String the converted string
     */
    static TString quoteIllegal(TString s, TString legal) {
        TStringBuilder buf = new TStringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if ((ch >= 'a' && ch <= 'z')
                    || (ch >= 'A' && ch <= 'Z')
                    || (ch >= '0' && ch <= '9')
                    || legal.indexOf(ch) > -1
                    || (ch > 127 && !isSpaceChar(ch) && !TCharacter.isISOControl(ch))) {
                buf.append(ch);
            } else {
                byte[] bytes = new TString(new char[] { ch }).getBytes();
                for (int j = 0; j < bytes.length; j++) {
                    buf.append('%');
                    buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
                    buf.append(digits.charAt(bytes[j] & 0xf));
                }
            }
        }
        return TString.wrap(buf.toString());
    }
View Full Code Here

Examples of org.teavm.classlib.java.lang.TStringBuilder

     * @param s
     *            java.lang.String the string to be converted
     * @return java.lang.String the converted string
     */
    static TString encodeOthers(TString s) {
        TStringBuilder buf = new TStringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch <= 127) {
                buf.append(ch);
            } else {
                byte[] bytes = new TString(new char[] { ch }).getBytes();
                for (int j = 0; j < bytes.length; j++) {
                    buf.append('%');
                    buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
                    buf.append(digits.charAt(bytes[j] & 0xf));
                }
            }
        }
        return TString.wrap(buf.toString());
    }
View Full Code Here

Examples of org.teavm.classlib.java.lang.TStringBuilder

     *            java.lang.String The encoded string.
     * @return java.lang.String The decoded version.
     */
    static TString decode(TString s) {

        TStringBuilder result = new TStringBuilder();
        TByteArrayOutputStream out = new TByteArrayOutputStream();
        for (int i = 0; i < s.length();) {
            char c = s.charAt(i);
            if (c == '%') {
                out.reset();
                do {
                    if (i + 2 >= s.length()) {
                        throw new TIllegalArgumentException();
                    }
                    int d1 = TCharacter.digit(s.charAt(i + 1), 16);
                    int d2 = TCharacter.digit(s.charAt(i + 2), 16);
                    if (d1 == -1 || d2 == -1) {
                        throw new TIllegalArgumentException();
                    }
                    out.write((byte) ((d1 << 4) + d2));
                    i += 3;
                } while (i < s.length() && s.charAt(i) == '%');
                result.append(TString.wrap(out.toString()));
                continue;
            }
            result.append(c);
            i++;
        }
        return TString.wrap(result.toString());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.