Package net.sf.saxon.om

Examples of net.sf.saxon.om.FastStringBuffer


     * @throws XPathException if the file cannot be read or contains illegal characters
     */

    private static String readQueryFromReader(Reader reader, NameChecker nameChecker) throws XPathException {
        try {
            FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.LARGE);
            char[] buffer = new char[2048];
            boolean first = true;
            int actual;
            int line = 1;   // track line/column position for reporting bad characters
            int column = 1;
            while (true) {
                actual = reader.read(buffer, 0, 2048);
                if (actual < 0) {
                    break;
                }
                for (int c=0; c<actual;) {
                    int ch32 = buffer[c++];
                    if (ch32 == '\n') {
                        line++;
                        column = 0;
                    }
                    column++;
                    if (UTF16CharacterSet.isHighSurrogate(ch32)) {
                        char low = buffer[c++];
                        ch32 = UTF16CharacterSet.combinePair((char)ch32, low);
                    }
                    if (!nameChecker.isValidChar(ch32)) {
                        XPathException err = new XPathException("The query file contains a character illegal in XML " +
                                nameChecker.getXMLVersion() +
                                " (line=" + line +
                                " column=" + column +
                                " value=x" + Integer.toHexString(ch32) + ')');
                        err.setErrorCode("XPST0003");
                        err.setIsStaticError(true);
                        throw err;
                    }
                }
                if (first) {
                    first = false;
                    if (buffer[0]=='\ufeff') {
                        sb.append(buffer, 1, actual-1);
                    } else {
                        sb.append(buffer, 0, actual);
                    }
                } else {
                    sb.append(buffer, 0, actual);
                }
            }
            return sb.condense().toString();
        } catch (IOException ioErr) {
            throw new XPathException("Failed to read input file", ioErr);
        }
    }
View Full Code Here


            }
        }
        if (p>=len) {
            return new String(in, i, len-i);
        }
        FastStringBuffer sb = new FastStringBuffer(p-i+1);
        for (int c=i; c<=p; c++) {
            sb.append((char)ch(in[c]));
        }
        return sb.toString();
    }
View Full Code Here

            }
        }
    }

    protected CharSequence parseQuantExact() throws RegexSyntaxException {
        FastStringBuffer buf = new FastStringBuffer(FastStringBuffer.TINY);
        do {
            if ("0123456789".indexOf(curChar) < 0)
                throw makeException("expected digit in quantifier");
            buf.append(curChar);
            advance();
        } while (curChar != ',' && curChar != '}');
        return buf;
    }
View Full Code Here

        }
        return false;
    }

    protected static String highSurrogateRanges(List ranges) {
        FastStringBuffer highRanges = new FastStringBuffer(ranges.size() * 2);
        for (int i = 0, len = ranges.size(); i < len; i++) {
            Range r = (Range)ranges.get(i);
            char min1 = UTF16CharacterSet.highSurrogate(r.getMin());
            char min2 = UTF16CharacterSet.lowSurrogate(r.getMin());
            char max1 = UTF16CharacterSet.highSurrogate(r.getMax());
            char max2 = UTF16CharacterSet.lowSurrogate(r.getMax());
            if (min2 != UTF16CharacterSet.SURROGATE2_MIN) {
                min1++;
            }
            if (max2 != UTF16CharacterSet.SURROGATE2_MAX) {
                max1--;
            }
            if (max1 >= min1) {
                highRanges.append(min1);
                highRanges.append(max1);
            }
        }
        return highRanges.toString();
    }
View Full Code Here

        }
        return highRanges.toString();
    }

    protected static String lowSurrogateRanges(List ranges) {
        FastStringBuffer lowRanges = new FastStringBuffer(ranges.size() * 2);
        for (int i = 0, len = ranges.size(); i < len; i++) {
            Range r = (Range)ranges.get(i);
            char min1 = UTF16CharacterSet.highSurrogate(r.getMin());
            char min2 = UTF16CharacterSet.lowSurrogate(r.getMin());
            char max1 = UTF16CharacterSet.highSurrogate(r.getMax());
            char max2 = UTF16CharacterSet.lowSurrogate(r.getMax());
            if (min1 == max1) {
                if (min2 != UTF16CharacterSet.SURROGATE2_MIN || max2 != UTF16CharacterSet.SURROGATE2_MAX) {
                    lowRanges.append(min1);
                    lowRanges.append(min2);
                    lowRanges.append(max2);
                }
            } else {
                if (min2 != UTF16CharacterSet.SURROGATE2_MIN) {
                    lowRanges.append(min1);
                    lowRanges.append(min2);
                    lowRanges.append(UTF16CharacterSet.SURROGATE2_MAX);
                }
                if (max2 != UTF16CharacterSet.SURROGATE2_MAX) {
                    lowRanges.append(max1);
                    lowRanges.append(UTF16CharacterSet.SURROGATE2_MIN);
                    lowRanges.append(max2);
                }
            }
        }
        return lowRanges.toString();
    }
View Full Code Here

        if (months == 0 && seconds == 0L && microseconds == 0) {
            return "PT0S";
        }

        FastStringBuffer sb = new FastStringBuffer(32);
        if (negative) {
            sb.append('-');
        }
        int years = getYears();
        int months = getMonths();
        int days = getDays();
        int hours = getHours();
        int minutes = getMinutes();
        int seconds = getSeconds();

        sb.append("P");
        if (years != 0) {
            sb.append(years + "Y");
        }
        if (months != 0) {
            sb.append(months + "M");
        }
        if (days != 0) {
            sb.append(days + "D");
        }
        if (hours != 0 || minutes != 0 || seconds != 0 || microseconds != 0) {
            sb.append("T");
        }
        if (hours != 0) {
            sb.append(hours + "H");
        }
        if (minutes != 0) {
            sb.append(minutes + "M");
        }
        if (seconds != 0 || microseconds != 0) {
            if (seconds != 0 && microseconds == 0) {
                sb.append(seconds + "S");
            } else {
                long ms = (seconds * 1000000) + microseconds;
                String mss = ms + "";
                if (seconds == 0) {
                    mss = "0000000" + mss;
                    mss = mss.substring(mss.length() - 7);
                }
                sb.append(mss.substring(0, mss.length() - 6));
                sb.append('.');
                int lastSigDigit = mss.length() - 1;
                while (mss.charAt(lastSigDigit) == '0') {
                    lastSigDigit--;
                }
                sb.append(mss.substring(mss.length() - 6, lastSigDigit + 1));
                sb.append('S');
            }
        }

        return sb;

View Full Code Here

        case Component.HOURS:
            return Int64Value.makeIntegerValue((negative ? -getHours() : getHours()));
        case Component.MINUTES:
            return Int64Value.makeIntegerValue((negative ? -getMinutes() : getMinutes()));
        case Component.SECONDS:
            FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.TINY);
            String ms = ("000000" + microseconds);
            ms = ms.substring(ms.length() - 6);
            sb.append((negative ? "-" : "") + getSeconds() + '.' + ms);
            return (AtomicValue)DecimalValue.makeDecimalValue(sb, false);
        case Component.WHOLE_SECONDS:
            return Int64Value.makeIntegerValue((negative ? -seconds : seconds));
        case Component.MICROSECONDS:
            return new Int64Value((negative ? -microseconds : microseconds));
View Full Code Here

    * @return ISO 8601 representation.
    */

    public CharSequence getPrimitiveStringValue() {

        FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.TINY);
        int yr = year;
        if (year <= 0) {
            sb.append('-');
            yr = -yr +1;           // no year zero in lexical space
        }
        appendString(sb, yr, (yr>9999 ? (yr+"").length() : 4));
        sb.append('-');
        appendTwoDigits(sb, month);
        sb.append('-');
        appendTwoDigits(sb, day);

        if (hasTimezone()) {
            appendTimezone(sb);
        }
View Full Code Here

        }
        if (!move) {
            return in;
        }

        FastStringBuffer buffer = new FastStringBuffer(in.length()*2);
        int i = 0;
        while(i < in.length()) {
            char c = in.charAt(i++);
            if (c >= min && c <= max) {
                if (UTF16CharacterSet.isHighSurrogate(c)) {
                    // assume the string is properly formed
                    char d = in.charAt(i++);
                    int s = UTF16CharacterSet.combinePair(c, d);
                    String rep = (String)charMap.get(s);
                    if (rep == null) {
                        buffer.append(c);
                        buffer.append(d);
                    } else {
                        if (insertNulls) {
                            buffer.append((char)0);
                            buffer.append(rep);
                            buffer.append((char)0);
                        } else {
                            buffer.append(rep);
                        }
                    }
                } else {
                    String rep = (String)charMap.get(c);
                    if (rep == null) {
                        buffer.append(c);
                    } else {
                        if (insertNulls) {
                            buffer.append((char)0);
                            buffer.append(rep);
                            buffer.append((char)0);
                        } else {
                            buffer.append(rep);
                        }
                    }
                }
            } else {
                buffer.append(c);
            }
        }
        return buffer;
    }
View Full Code Here

        }
        return url;
    }

    private static CharSequence reallyEscapeURL(CharSequence url) {
        FastStringBuffer sb = new FastStringBuffer(url.length() + 20);
        final String hex = "0123456789ABCDEF";
        byte[] array = new byte[4];

        for (int i=0; i<url.length(); i++) {
            char ch = url.charAt(i);
            if (ch<32 || ch>126) {
                int used = UTF8CharacterSet.getUTF8Encoding(ch,
                                                 (i+1 < url.length() ? url.charAt(i+1): ' '), array);
                for (int b=0; b<used; b++) {
                    //int v = (array[b]>=0 ? array[b] : 256 + array[b]);
                    int v = ((int)array[b]) & 0xff;
                    sb.append('%');
                    sb.append(hex.charAt(v/16));
                    sb.append(hex.charAt(v%16));
                }

            } else {
                sb.append(ch);
            }
        }
        return sb;
    }
View Full Code Here

TOP

Related Classes of net.sf.saxon.om.FastStringBuffer

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.