Package jsonij.json.JSONReader

Examples of jsonij.json.JSONReader.JSONStringReader


        JSON.String value = null;
        if (target.peek() != QUOTATION) {
            throw new JSONParserException("invalidStringExpecting1", target.getLineNumber(), target.getPositionNumber(), (char) QUOTATION, (char) target.peek());
        }
        String valueString = "";
        JSONStringReader 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:
                        valueString += (char) QUOTATION_MARK;
                        targetString.read();
                        break;
                    case REVERSE_SOLIDUS:
                        valueString += (char) ESCAPE;
                        targetString.read();
                        break;
                    case SOLIDUS_CHAR:
                        valueString += (char) SOLIDUS_CHAR;
                        targetString.read();
                        break;
                    case BACKSPACE_CHAR:
                        valueString += (char) BACKSPACE;
                        targetString.read();
                        break;
                    case FORM_FEED_CHAR:
                        valueString += (char) FORM_FEED;
                        targetString.read();
                        break;
                    case NEW_LINE_CHAR:
                        valueString += (char) NEW_LINE;
                        targetString.read();
                        break;
                    case CARRIAGE_RETURN_CHAR:
                        valueString += (char) CARRIAGE_RETURN;
                        targetString.read();
                        break;
                    case TAB_CHAR:
                        valueString += (char) TAB;
                        targetString.read();
                        break;
                    case HEX_CHAR:
                        targetString.read();
                        String unicodeString = "";
                        for (int i = 0; i < 4; i++) {
                            if (ConstantUtility.isHexDigit(targetString.peek())) {
                                unicodeString += (char) targetString.read();
                            } else {
                                throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                            }
                        }
                        int unicodeInt = Integer.parseInt(unicodeString.toUpperCase(), 16);
                        if (Character.isHighSurrogate((char) unicodeInt)) {
                            String highSurrogateString = unicodeString;
                            int highSurrogate = unicodeInt;
                            unicodeString = "";
                            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())) {
                                    unicodeString += (char) targetString.read();
                                } else {
                                    throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                                }
                            }
                            String lowSurrogateString = unicodeString;
                            int lowSurrogate = Integer.parseInt(unicodeString.toUpperCase(), 16);
                            if (Character.isSurrogatePair((char) highSurrogate, (char) lowSurrogate)) {
                                valueString += new String(Character.toChars(Character.toCodePoint((char) highSurrogate, (char) lowSurrogate)));
                            } else {
                                throw new JSONParserException("invalidStringSurrogates", target.getLineNumber(), target.getPositionNumber(), highSurrogateString, lowSurrogateString);
                            }
                        } else {
                            valueString += (char) unicodeInt;
                        }
                        break;
                    default:
                        throw new JSONParserException("invalidStringEscape", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                }
            } else {
                if (ConstantUtility.isValidStringChar(targetString.peek())) {
                    valueString += (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(valueString);
        if (logger.isLoggable(Level.FINER)) {
            logger.exiting(getClass().getName(), method, value);
        }
        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());
        }
        String valueString = "";
        JSONStringReader 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:
                        valueString += (char) QUOTATION_MARK;
                        targetString.read();
                        break;
                    case REVERSE_SOLIDUS:
                        valueString += (char) ESCAPE;
                        targetString.read();
                        break;
                    case SOLIDUS_CHAR:
                        valueString += (char) SOLIDUS_CHAR;
                        targetString.read();
                        break;
                    case BACKSPACE_CHAR:
                        valueString += (char) BACKSPACE;
                        targetString.read();
                        break;
                    case FORM_FEED_CHAR:
                        valueString += (char) FORM_FEED;
                        targetString.read();
                        break;
                    case NEW_LINE_CHAR:
                        valueString += (char) NEW_LINE;
                        targetString.read();
                        break;
                    case CARRIAGE_RETURN_CHAR:
                        valueString += (char) CARRIAGE_RETURN;
                        targetString.read();
                        break;
                    case TAB_CHAR:
                        valueString += (char) TAB;
                        targetString.read();
                        break;
                    case HEX_CHAR:
                        targetString.read();
                        String unicodeString = "";
                        for (int i = 0; i < 4; i++) {
                            if (ConstantUtility.isHexDigit(targetString.peek())) {
                                unicodeString += (char) targetString.read();
                            } else {
                                throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                            }
                        }
                        int unicodeInt = Integer.parseInt(unicodeString.toUpperCase(), 16);
                        if (Character.isHighSurrogate((char) unicodeInt)) {
                            String highSurrogateString = unicodeString;
                            int highSurrogate = unicodeInt;
                            unicodeString = "";
                            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())) {
                                    unicodeString += (char) targetString.read();
                                } else {
                                    throw new JSONParserException("invalidStringHex", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                                }
                            }
                            String lowSurrogateString = unicodeString;
                            int lowSurrogate = Integer.parseInt(unicodeString.toUpperCase(), 16);
                            if (Character.isSurrogatePair((char) highSurrogate, (char) lowSurrogate)) {
                                valueString += new String(Character.toChars(Character.toCodePoint((char) highSurrogate, (char) lowSurrogate)));
                            } else {
                                throw new JSONParserException("invalidStringSurrogates", target.getLineNumber(), target.getPositionNumber(), highSurrogateString, lowSurrogateString);
                            }
                        } else {
                            valueString += (char) unicodeInt;
                        }
                        break;
                    default:
                        throw new JSONParserException("invalidStringEscape", target.getLineNumber(), target.getPositionNumber(), targetString.peek());
                }
            } else {
                if (ConstantUtility.isValidStringChar(targetString.peek())) {
                    valueString += (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(valueString);
        if (logger.isLoggable(Level.FINER)) {
            logger.exiting(getClass().getName(), method, value);
        }
        return value;
View Full Code Here

TOP

Related Classes of jsonij.json.JSONReader.JSONStringReader

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.