public static int escapeXmlChar(Writer out, char ch, int buffIndex, char[] buff, int buffLength) throws IOException {
        int nextIndex;
        if (ch < 0xA0) {
            // If "?" or over, no escaping is needed (this covers
            // most of the Latin alphabet)
            if (ch >= 0x3f) {
                nextIndex = addToBuffer(out, buff, buffIndex,
                        buffLength, ch);
            } else if (ch >= 0x27) {  // If above "'"...
                // If between "'" and ";", no escaping is needed
                if (ch < 0x3c) {
                    nextIndex = addToBuffer(out, buff, buffIndex,
                            buffLength, ch);
                } else if (ch == '<') {
                    nextIndex = addToBuffer(out,
                            buff,
                            buffIndex,
                            buffLength,
                            LT_CHARS);
                } else if (ch == '>') {
                    nextIndex = addToBuffer(out,
                            buff,
                            buffIndex,
                            buffLength,
                            GT_CHARS);
                } else {
                    nextIndex = addToBuffer(out, buff, buffIndex,
                            buffLength, ch);
                }
            } else {
                if (ch == '&') {
                    nextIndex = addToBuffer(out,
                            buff,
                            buffIndex,
                            buffLength,
                            AMP_CHARS);
                } else if (ch == '"') {
                    nextIndex = addToBuffer(out,
                            buff,
                            buffIndex,
                            buffLength,
                            QUOT_CHARS);
                } else {
                    nextIndex = addToBuffer(out, buff, buffIndex,
                            buffLength, ch);
                }
            }
        } else {
            nextIndex = addToBuffer(out, buff, buffIndex,
                    buffLength, ch);
        }
        return nextIndex;
    }