private int handleEntityInText()

in sdk/clientcore/core/src/main/java/io/clientcore/core/serialization/xml/implementation/aalto/in/ReaderScanner.java [1605:1809]


    private int handleEntityInText() throws XMLStreamException {
        if (_inputPtr >= _inputEnd) {
            loadMoreGuaranteed();
        }
        char c = _inputBuffer[_inputPtr++];
        if (c == '#') {
            return handleCharEntity();
        }
        String start;
        if (c == 'a') { // amp or apos?
            if (_inputPtr >= _inputEnd) {
                loadMoreGuaranteed();
            }
            c = _inputBuffer[_inputPtr++];
            if (c == 'm') { // amp?
                if (_inputPtr >= _inputEnd) {
                    loadMoreGuaranteed();
                }
                c = _inputBuffer[_inputPtr++];
                if (c == 'p') {
                    if (_inputPtr >= _inputEnd) {
                        loadMoreGuaranteed();
                    }
                    c = _inputBuffer[_inputPtr++];
                    if (c == ';') {
                        return INT_AMP;
                    }
                    start = "amp";
                } else {
                    start = "am";
                }
            } else if (c == 'p') { // apos?
                if (_inputPtr >= _inputEnd) {
                    loadMoreGuaranteed();
                }
                c = _inputBuffer[_inputPtr++];
                if (c == 'o') {
                    if (_inputPtr >= _inputEnd) {
                        loadMoreGuaranteed();
                    }
                    c = _inputBuffer[_inputPtr++];
                    if (c == 's') {
                        if (_inputPtr >= _inputEnd) {
                            loadMoreGuaranteed();
                        }
                        c = _inputBuffer[_inputPtr++];
                        if (c == ';') {
                            return INT_APOS;
                        }
                        start = "apos";
                    } else {
                        start = "apo";
                    }
                } else {
                    start = "ap";
                }
            } else {
                start = "a";
            }
        } else if (c == 'l') { // lt?
            if (_inputPtr >= _inputEnd) {
                loadMoreGuaranteed();
            }
            c = _inputBuffer[_inputPtr++];
            if (c == 't') {
                if (_inputPtr >= _inputEnd) {
                    loadMoreGuaranteed();
                }
                c = _inputBuffer[_inputPtr++];
                if (c == ';') {
                    return INT_LT;
                }
                start = "lt";
            } else {
                start = "l";
            }
        } else if (c == 'g') { // gt?
            if (_inputPtr >= _inputEnd) {
                loadMoreGuaranteed();
            }
            c = _inputBuffer[_inputPtr++];
            if (c == 't') {
                if (_inputPtr >= _inputEnd) {
                    loadMoreGuaranteed();
                }
                c = _inputBuffer[_inputPtr++];
                if (c == ';') {
                    return INT_GT;
                }
                start = "gt";
            } else {
                start = "g";
            }
        } else if (c == 'q') { // quot?
            if (_inputPtr >= _inputEnd) {
                loadMoreGuaranteed();
            }
            c = _inputBuffer[_inputPtr++];
            if (c == 'u') {
                if (_inputPtr >= _inputEnd) {
                    loadMoreGuaranteed();
                }
                c = _inputBuffer[_inputPtr++];
                if (c == 'o') {
                    if (_inputPtr >= _inputEnd) {
                        loadMoreGuaranteed();
                    }
                    c = _inputBuffer[_inputPtr++];
                    if (c == 't') {
                        if (_inputPtr >= _inputEnd) {
                            loadMoreGuaranteed();
                        }
                        c = _inputBuffer[_inputPtr++];
                        if (c == ';') {
                            return INT_QUOTE;
                        }
                        start = "quot";
                    } else {
                        start = "quo";
                    }
                } else {
                    start = "qu";
                }
            } else {
                start = "q";
            }
        } else {
            start = "";
        }

        final int[] TYPES = sCharTypes.NAME_CHARS;

        /* All righty: we have the beginning of the name, plus the first
         * char too. So let's see what we can do with it.
         */
        char[] cbuf = _nameBuffer;
        int cix = 0;
        for (int len = start.length(); cix < len; ++cix) {
            cbuf[cix] = start.charAt(cix);
        }
        //int colon = -1;
        while (c != ';') {
            boolean ok;

            // Has to be a valid name start char though:
            if (c <= 0xFF) {
                switch (TYPES[c]) {
                    case XmlCharTypes.CT_NAME_NONE:
                    case XmlCharTypes.CT_NAME_COLON: // not ok for entities?
                    case XmlCharTypes.CT_NAME_NONFIRST:
                        ok = (cix > 0);
                        break;

                    case XmlCharTypes.CT_NAME_ANY:
                        ok = true;
                        break;

                    default:
                        ok = false;
                        break;
                }
            } else {
                if (c < 0xE000) {
                    // if ok, returns second surrogate; otherwise exception
                    int value = decodeSurrogate(c);
                    if (cix >= cbuf.length) {
                        _nameBuffer = cbuf = DataUtil.growArrayBy(cbuf, cbuf.length);
                    }
                    cbuf[cix++] = c;
                    c = _inputBuffer[_inputPtr - 1]; // was read by decode func
                    ok = XmlChars.is10NameChar(value);
                } else if (c >= 0xFFFE) {
                    c = handleInvalidXmlChar(c);
                    ok = false; // never gets here
                } else {
                    ok = true;
                }
            }
            if (!ok) {
                reportInvalidNameChar(c, cix);
            }
            if (cix >= cbuf.length) {
                _nameBuffer = cbuf = DataUtil.growArrayBy(cbuf, cbuf.length);
            }
            cbuf[cix++] = c;
            if (_inputPtr >= _inputEnd) {
                loadMoreGuaranteed();
            }
            c = _inputBuffer[_inputPtr++];
        }

        // Ok, let's construct a (temporary) entity name, then:
        String pname = new String(cbuf, 0, cix);
        // (note: hash is dummy... not to be compared to anything etc)
        _tokenName = new PNameC(pname, null, pname, 0);

        /* One more thing: do we actually allow entities in this mode
         * and with this event?
         */
        if (_config.willExpandEntities()) {
            reportInputProblem("General entity reference (&" + pname
                + ";) encountered in entity expanding mode: operation not (yet) implemented");
        }
        return 0;
    }