Package jsonij.parser

Examples of jsonij.parser.ReaderParser


        JSON.String value = null;
        if (target.peek() != QUOTATION) {
            throw new JSONParserException("invalidStringExpecting1", target.getLineNumber(), target.getPositionNumber(), (char) QUOTATION, (char) target.peek());
        }
        StringBuilder valueStringBuilder = new StringBuilder();
        ReaderParser targetString = target.getStringReader();
        targetString.read();
        while (true) {
            if (targetString.peek() == QUOTATION) {
                break;
            } else if (targetString.peek() == REVERSE_SOLIDUS) {
                targetString.read();
                switch (targetString.peek()) {
                    case QUOTATION:
                        valueStringBuilder.append((char) QUOTATION_MARK);
                        targetString.read();
                        break;
                    case REVERSE_SOLIDUS:
                        valueStringBuilder.append((char) ESCAPE);
                        targetString.read();
                        break;
                    case SOLIDUS_CHAR:
                        valueStringBuilder.append((char) SOLIDUS_CHAR);
                        targetString.read();
                        break;
                    case BACKSPACE_CHAR:
                        valueStringBuilder.append((char) BACKSPACE);
                        targetString.read();
                        break;
                    case FORM_FEED_CHAR:
                        valueStringBuilder.append((char) FORM_FEED);
                        targetString.read();
                        break;
                    case NEW_LINE_CHAR:
                        valueStringBuilder.append((char) NEW_LINE);
                        targetString.read();
                        break;
                    case CARRIAGE_RETURN_CHAR:
                        valueStringBuilder.append((char) CARRIAGE_RETURN);
                        targetString.read();
                        break;
                    case TAB_CHAR:
                        valueStringBuilder.append((char) TAB);
                        targetString.read();
                        break;
                    case HEX_CHAR:
                        targetString.read();
                        StringBuilder unicodeStringBuilder = new StringBuilder();
                        for (int i = 0; i < 4; i++) {
                            if (ConstantUtility.isHexDigit(targetString.peek())) {
                                unicodeStringBuilder.append((char) targetString.read());
                            } else {
                                throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                            }
                        }
                        int unicodeInt = Integer.parseInt(unicodeStringBuilder.toString().toUpperCase(), 16);
                        if (Character.isHighSurrogate((char) unicodeInt)) {
                            String highSurrogateString = unicodeStringBuilder.toString();
                            int highSurrogate = unicodeInt;
                            unicodeStringBuilder = new StringBuilder();
                            if (targetString.peek() == REVERSE_SOLIDUS) {
                                targetString.read();
                            } else {
                                throw new JSONParserException("invalidStringMissingSurrogate", target.getLineNumber(), target.getPositionNumber(), REVERSE_SOLIDUS, targetString.peek());
                            }
                            if (targetString.peek() == HEX_CHAR) {
                                targetString.read();
                            } else {
                                throw new JSONParserException("invalidStringMissingSurrogate", target.getLineNumber(), target.getPositionNumber(), HEX_CHAR, targetString.peek());
                            }
                            for (int i = 0; i < 4; i++) {
                                if (ConstantUtility.isHexDigit(targetString.peek())) {
                                    unicodeStringBuilder.append((char) targetString.read());
                                } else {
                                    throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                                }
                            }
                            String lowSurrogateString = unicodeStringBuilder.toString();
                            int lowSurrogate = Integer.parseInt(lowSurrogateString.toUpperCase(), 16);
                            if (Character.isSurrogatePair((char) highSurrogate, (char) lowSurrogate)) {
                                valueStringBuilder.append(new String(Character.toChars(Character.toCodePoint((char) highSurrogate, (char) lowSurrogate))));
                            } else {
                                throw new JSONParserException("invalidStringSurrogates", target.getLineNumber(), target.getPositionNumber(), highSurrogateString, lowSurrogateString);
                            }
                        } else {
                            valueStringBuilder.append((char) unicodeInt);
                        }
                        break;
                    default:
                        throw new JSONParserException("invalidStringEscape", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                }
            } else {
                if (ConstantUtility.isValidStringChar(targetString.peek())) {
                    valueStringBuilder.append((char) targetString.read());
                } else {
                    throw new JSONParserException("invalidStringValue", target.getLineNumber(), target.getPositionNumber(), (char) targetString.peek());
                }
            }
        }
        if (targetString.peek() != QUOTATION) {
            throw new JSONParserException("invalidStringExpecting1", target.getLineNumber(), target.getPositionNumber(), (char) QUOTATION, (char) targetString.peek());
        } else {
            targetString.read();
        }
        targetString.close();
        value = new JSON.String(valueStringBuilder.toString());
        return value;
    }
View Full Code Here


        JSON.String value = null;
        if (target.peek() != QUOTATION) {
            throw new JSONParserException("invalidStringExpecting1", target.getLineNumber(), target.getPositionNumber(), (char) QUOTATION, (char) target.peek());
        }
        StringBuilder valueStringBuilder = new StringBuilder();
        ReaderParser targetString = target.getStringReader();
        targetString.read();
        while (true) {
            if (targetString.peek() == QUOTATION) {
                break;
            } else if (targetString.peek() == REVERSE_SOLIDUS) {
                targetString.read();
                switch (targetString.peek()) {
                    case QUOTATION:
                        valueStringBuilder.append((char) QUOTATION_MARK);
                        targetString.read();
                        break;
                    case REVERSE_SOLIDUS:
                        valueStringBuilder.append((char) ESCAPE);
                        targetString.read();
                        break;
                    case SOLIDUS_CHAR:
                        valueStringBuilder.append((char) SOLIDUS_CHAR);
                        targetString.read();
                        break;
                    case BACKSPACE_CHAR:
                        valueStringBuilder.append((char) BACKSPACE);
                        targetString.read();
                        break;
                    case FORM_FEED_CHAR:
                        valueStringBuilder.append((char) FORM_FEED);
                        targetString.read();
                        break;
                    case NEW_LINE_CHAR:
                        valueStringBuilder.append((char) NEW_LINE);
                        targetString.read();
                        break;
                    case CARRIAGE_RETURN_CHAR:
                        valueStringBuilder.append((char) CARRIAGE_RETURN);
                        targetString.read();
                        break;
                    case TAB_CHAR:
                        valueStringBuilder.append((char) TAB);
                        targetString.read();
                        break;
                    case HEX_CHAR:
                        targetString.read();
                        StringBuilder unicodeStringBuilder = new StringBuilder();
                        for (int i = 0; i < 4; i++) {
                            if (ConstantUtility.isHexDigit(targetString.peek())) {
                                unicodeStringBuilder.append((char) targetString.read());
                            } else {
                                throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                            }
                        }
                        int unicodeInt = Integer.parseInt(unicodeStringBuilder.toString().toUpperCase(), 16);
                        if (Character.isHighSurrogate((char) unicodeInt)) {
                            String highSurrogateString = unicodeStringBuilder.toString();
                            int highSurrogate = unicodeInt;
                            unicodeStringBuilder = new StringBuilder();
                            if (targetString.peek() == REVERSE_SOLIDUS) {
                                targetString.read();
                            } else {
                                throw new JSONParserException("invalidStringMissingSurrogate", target.getLineNumber(), target.getPositionNumber(), REVERSE_SOLIDUS, targetString.peek());
                            }
                            if (targetString.peek() == HEX_CHAR) {
                                targetString.read();
                            } else {
                                throw new JSONParserException("invalidStringMissingSurrogate", target.getLineNumber(), target.getPositionNumber(), HEX_CHAR, targetString.peek());
                            }
                            for (int i = 0; i < 4; i++) {
                                if (ConstantUtility.isHexDigit(targetString.peek())) {
                                    unicodeStringBuilder.append((char) targetString.read());
                                } else {
                                    throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                                }
                            }
                            String lowSurrogateString = unicodeStringBuilder.toString();
                            int lowSurrogate = Integer.parseInt(lowSurrogateString.toUpperCase(), 16);
                            if (Character.isSurrogatePair((char) highSurrogate, (char) lowSurrogate)) {
                                valueStringBuilder.append(new String(Character.toChars(Character.toCodePoint((char) highSurrogate, (char) lowSurrogate))));
                            } else {
                                throw new JSONParserException("invalidStringSurrogates", target.getLineNumber(), target.getPositionNumber(), highSurrogateString, lowSurrogateString);
                            }
                        } else {
                            valueStringBuilder.append((char) unicodeInt);
                        }
                        break;
                    default:
                        throw new JSONParserException("invalidStringEscape", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                }
            } else {
                if (ConstantUtility.isValidStringChar(targetString.peek())) {
                    valueStringBuilder.append((char) targetString.read());
                } else {
                    throw new JSONParserException("invalidStringValue", target.getLineNumber(), target.getPositionNumber(), (char) targetString.peek());
                }
            }
        }
        if (targetString.peek() != QUOTATION) {
            throw new JSONParserException("invalidStringExpecting1", target.getLineNumber(), target.getPositionNumber(), (char) QUOTATION, (char) targetString.peek());
        } else {
            targetString.read();
        }
        targetString.close();
        value = new JSON.String(valueStringBuilder.toString());
        return value;
    }
View Full Code Here

        JSON.String value = null;
        if (target.peek() != QUOTATION) {
            throw new JSONParserException("invalidStringExpecting1", target.getLineNumber(), target.getPositionNumber(), (char) QUOTATION, (char) target.peek());
        }
        StringBuilder valueStringBuilder = new StringBuilder();
        ReaderParser targetString = target.getStringReader();
        targetString.read();
        int p;
        while (true) {
            p = targetString.peek();
            if (p == QUOTATION) {
                break;
            } else if (p == REVERSE_SOLIDUS) {
                targetString.read();
                p = targetString.peek();
                switch (p) {
                    case QUOTATION:
                        valueStringBuilder.append((char) QUOTATION_MARK);
                        targetString.read();
                        break;
                    case REVERSE_SOLIDUS:
                        valueStringBuilder.append((char) ESCAPE);
                        targetString.read();
                        break;
                    case SOLIDUS_CHAR:
                        valueStringBuilder.append((char) SOLIDUS_CHAR);
                        targetString.read();
                        break;
                    case BACKSPACE_CHAR:
                        valueStringBuilder.append((char) BACKSPACE);
                        targetString.read();
                        break;
                    case FORM_FEED_CHAR:
                        valueStringBuilder.append((char) FORM_FEED);
                        targetString.read();
                        break;
                    case NEW_LINE_CHAR:
                        valueStringBuilder.append((char) NEW_LINE);
                        targetString.read();
                        break;
                    case CARRIAGE_RETURN_CHAR:
                        valueStringBuilder.append((char) CARRIAGE_RETURN);
                        targetString.read();
                        break;
                    case TAB_CHAR:
                        valueStringBuilder.append((char) TAB);
                        targetString.read();
                        break;
                    case HEX_CHAR:
                        targetString.read();
                        StringBuilder unicodeStringBuilder = new StringBuilder();
                        for (int i = 0; i < 4; i++) {
                            if (ConstantUtility.isHexDigit(targetString.peek())) {
                                unicodeStringBuilder.append((char) targetString.read());
                            } else {
                                throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                            }
                        }
                        int unicodeInt = Integer.parseInt(unicodeStringBuilder.toString().toUpperCase(), 16);
                        if (Character.isHighSurrogate((char) unicodeInt)) {
                            String highSurrogateString = unicodeStringBuilder.toString();
                            int highSurrogate = unicodeInt;
                            unicodeStringBuilder = new StringBuilder();
                            if (targetString.peek() == REVERSE_SOLIDUS) {
                                targetString.read();
                            } else {
                                throw new JSONParserException("invalidStringMissingSurrogate", target.getLineNumber(), target.getPositionNumber(), REVERSE_SOLIDUS, targetString.peek());
                            }
                            if (targetString.peek() == HEX_CHAR) {
                                targetString.read();
                            } else {
                                throw new JSONParserException("invalidStringMissingSurrogate", target.getLineNumber(), target.getPositionNumber(), HEX_CHAR, targetString.peek());
                            }
                            for (int i = 0; i < 4; i++) {
                                if (ConstantUtility.isHexDigit(targetString.peek())) {
                                    unicodeStringBuilder.append((char) targetString.read());
                                } else {
                                    throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                                }
                            }
                            String lowSurrogateString = unicodeStringBuilder.toString();
                            int lowSurrogate = Integer.parseInt(lowSurrogateString.toUpperCase(), 16);
                            if (Character.isSurrogatePair((char) highSurrogate, (char) lowSurrogate)) {
                                char[] c = Character.toChars(Character.toCodePoint((char) highSurrogate, (char) lowSurrogate));
                                valueStringBuilder.append(new String(c));
                            } else {
                                throw new JSONParserException("invalidStringSurrogates", target.getLineNumber(), target.getPositionNumber(), highSurrogateString, lowSurrogateString);
                            }
                        } else {    
                            if (ConstantUtility.isValidStringChar(unicodeInt)) {
                                valueStringBuilder.append((char) unicodeInt);
                            } else {
                                throw new JSONParserException("invalidStringValue", target.getLineNumber(), target.getPositionNumber(), unicodeInt, unicodeStringBuilder.toString());
                            }
                        }
                        break;
                    default:
                        throw new JSONParserException("invalidStringEscape", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                }
            } else {
                if (ConstantUtility.isValidStringChar(p)) {
                    valueStringBuilder.append((char) targetString.read());
                } else {
                    throw new JSONParserException("invalidStringValue", target.getLineNumber(), target.getPositionNumber(), targetString.peek(), (char) targetString.peek());
                }
            }
        }
        if (targetString.peek() != QUOTATION) {
            throw new JSONParserException("invalidStringExpecting1", target.getLineNumber(), target.getPositionNumber(), (char) QUOTATION, (char) targetString.peek());
        } else {
            targetString.read();
        }
        targetString.close();
        value = new JSON.String(valueStringBuilder.toString());
        return value;
    }
View Full Code Here

        JSON.String value = null;
        if (target.peek() != QUOTATION) {
            throw new JSONParserException("invalidStringExpecting1", target.getLineNumber(), target.getPositionNumber(), (char) QUOTATION, (char) target.peek());
        }
        StringBuilder valueStringBuilder = new StringBuilder();
        ReaderParser targetString = target.getStringReader();
        targetString.read();
        while (true) {
            if (targetString.peek() == QUOTATION) {
                break;
            } else if (targetString.peek() == REVERSE_SOLIDUS) {
                targetString.read();
                switch (targetString.peek()) {
                    case QUOTATION:
                        valueStringBuilder.append((char) QUOTATION_MARK);
                        targetString.read();
                        break;
                    case REVERSE_SOLIDUS:
                        valueStringBuilder.append((char) ESCAPE);
                        targetString.read();
                        break;
                    case SOLIDUS_CHAR:
                        valueStringBuilder.append((char) SOLIDUS_CHAR);
                        targetString.read();
                        break;
                    case BACKSPACE_CHAR:
                        valueStringBuilder.append((char) BACKSPACE);
                        targetString.read();
                        break;
                    case FORM_FEED_CHAR:
                        valueStringBuilder.append((char) FORM_FEED);
                        targetString.read();
                        break;
                    case NEW_LINE_CHAR:
                        valueStringBuilder.append((char) NEW_LINE);
                        targetString.read();
                        break;
                    case CARRIAGE_RETURN_CHAR:
                        valueStringBuilder.append((char) CARRIAGE_RETURN);
                        targetString.read();
                        break;
                    case TAB_CHAR:
                        valueStringBuilder.append((char) TAB);
                        targetString.read();
                        break;
                    case HEX_CHAR:
                        targetString.read();
                        StringBuilder unicodeStringBuilder = new StringBuilder();
                        for (int i = 0; i < 4; i++) {
                            if (ConstantUtility.isHexDigit(targetString.peek())) {
                                unicodeStringBuilder.append((char) targetString.read());
                            } else {
                                throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                            }
                        }
                        int unicodeInt = Integer.parseInt(unicodeStringBuilder.toString().toUpperCase(), 16);
                        if (Character.isHighSurrogate((char) unicodeInt)) {
                            String highSurrogateString = unicodeStringBuilder.toString();
                            int highSurrogate = unicodeInt;
                            unicodeStringBuilder = new StringBuilder();
                            if (targetString.peek() == REVERSE_SOLIDUS) {
                                targetString.read();
                            } else {
                                throw new JSONParserException("invalidStringMissingSurrogate", target.getLineNumber(), target.getPositionNumber(), REVERSE_SOLIDUS, targetString.peek());
                            }
                            if (targetString.peek() == HEX_CHAR) {
                                targetString.read();
                            } else {
                                throw new JSONParserException("invalidStringMissingSurrogate", target.getLineNumber(), target.getPositionNumber(), HEX_CHAR, targetString.peek());
                            }
                            for (int i = 0; i < 4; i++) {
                                if (ConstantUtility.isHexDigit(targetString.peek())) {
                                    unicodeStringBuilder.append((char) targetString.read());
                                } else {
                                    throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                                }
                            }
                            String lowSurrogateString = unicodeStringBuilder.toString();
                            int lowSurrogate = Integer.parseInt(lowSurrogateString.toUpperCase(), 16);
                            if (Character.isSurrogatePair((char) highSurrogate, (char) lowSurrogate)) {
                                valueStringBuilder.append(new String(Character.toChars(Character.toCodePoint((char) highSurrogate, (char) lowSurrogate))));
                            } else {
                                throw new JSONParserException("invalidStringSurrogates", target.getLineNumber(), target.getPositionNumber(), highSurrogateString, lowSurrogateString);
                            }
                        } else {
                            valueStringBuilder.append((char) unicodeInt);
                        }
                        break;
                    default:
                        throw new JSONParserException("invalidStringEscape", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                }
            } else {
                if (ConstantUtility.isValidStringChar(targetString.peek())) {
                    valueStringBuilder.append((char) targetString.read());
                } else {
                    throw new JSONParserException("invalidStringValue", target.getLineNumber(), target.getPositionNumber(), targetString.peek(), (char) targetString.peek());
                }
            }
        }
        if (targetString.peek() != QUOTATION) {
            throw new JSONParserException("invalidStringExpecting1", target.getLineNumber(), target.getPositionNumber(), (char) QUOTATION, (char) targetString.peek());
        } else {
            targetString.read();
        }
        targetString.close();
        value = new JSON.String(valueStringBuilder.toString());
        return value;
    }
View Full Code Here

TOP

Related Classes of jsonij.parser.ReaderParser

Copyright © 2018 www.massapicom. 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.