Package org.pdf4j.saxon.om

Examples of org.pdf4j.saxon.om.FastStringBuffer


        }
    }

    public CharSequence getStringValueCS() {

        FastStringBuffer sb = new FastStringBuffer(16);
        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));

        if (hasTimezone()) {
View Full Code Here


    */

    public CharSequence format(List numbers, int groupSize, String groupSeparator,
                        String letterValue, String ordinal, Numberer numberer) {

        FastStringBuffer sb = new FastStringBuffer(20);
        int num = 0;
        int tok = 0;
        // output first punctuation token
        if (startsWithPunctuation) {
            sb.append((String)punctuationTokens.get(tok));
        }
        // output the list of numbers
        while (num<numbers.size()) {
            if (num>0) {
                if (tok==0 && startsWithPunctuation) {
                    // The first punctuation token isn't a separator if it appears before the first
                    // formatting token. Such a punctuation token is used only once, at the start.
                    sb.append(".");
                } else {
                    sb.append((String)punctuationTokens.get(tok));
                }
            }
            Object o = numbers.get(num++);
            String s;
            if (o instanceof Long) {
                long nr = ((Long)o).longValue();

                s = numberer.format(nr, (String)formatTokens.get(tok),
                             groupSize, groupSeparator, letterValue, ordinal);
            } else {
                s = o.toString();
            }
            sb.append(s);
            tok++;
            if (tok==formatTokens.size()) tok--;
        }
        // output the final punctuation token
        if (punctuationTokens.size()>formatTokens.size()) {
            sb.append((String)punctuationTokens.get(punctuationTokens.size()-1));
        }
        return sb.condense();
    }
View Full Code Here

            }
        }
    }

    protected CharSequence parseQuantExact() throws RegexSyntaxException {
        FastStringBuffer buf = new FastStringBuffer(10);
        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 = UTF16.highSurrogate(r.getMin());
            char min2 = UTF16.lowSurrogate(r.getMin());
            char max1 = UTF16.highSurrogate(r.getMax());
            char max2 = UTF16.lowSurrogate(r.getMax());
            if (min2 != UTF16.SURROGATE2_MIN) {
                min1++;
            }
            if (max2 != UTF16.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 = UTF16.highSurrogate(r.getMin());
            char min2 = UTF16.lowSurrogate(r.getMin());
            char max1 = UTF16.highSurrogate(r.getMax());
            char max2 = UTF16.lowSurrogate(r.getMax());
            if (min1 == max1) {
                if (min2 != UTF16.SURROGATE2_MIN || max2 != UTF16.SURROGATE2_MAX) {
                    lowRanges.append(min1);
                    lowRanges.append(min2);
                    lowRanges.append(max2);
                }
            } else {
                if (min2 != UTF16.SURROGATE2_MIN) {
                    lowRanges.append(min1);
                    lowRanges.append(min2);
                    lowRanges.append(UTF16.SURROGATE2_MAX);
                }
                if (max2 != UTF16.SURROGATE2_MAX) {
                    lowRanges.append(max1);
                    lowRanges.append(UTF16.SURROGATE2_MIN);
                    lowRanges.append(max2);
                }
            }
        }
        return lowRanges.toString();
    }
View Full Code Here

    * of size maxAllocation.
    */
    public LargeStringBuffer(int minAllocation, int maxAllocation) {
        this.minAllocation = Math.min(minAllocation, maxAllocation);
        this.maxAllocation = maxAllocation;
        FastStringBuffer initial = new FastStringBuffer(minAllocation);
        segments = new ArrayList(4);
        segments.add(initial);
        startOffsets = new int[1];
        startOffsets[0] = 0;
        length = 0;
View Full Code Here

    public void append(CharSequence data) {
        final int increment = data.length();
        if (increment == 0) {
            return;
        }
        FastStringBuffer last = ((FastStringBuffer)segments.get(segments.size()-1));
        if (last.length() + increment <= maxAllocation) {
            last.append(data);
        } else {
            int[] s2 = new int[startOffsets.length+1];
            System.arraycopy(startOffsets, 0, s2, 0, startOffsets.length);
            s2[startOffsets.length] = length;
            startOffsets = s2;
            last = new FastStringBuffer(Math.max(minAllocation, increment));
            segments.add(last);
            last.append(data);
        }
        length += increment;
    }
View Full Code Here

     * @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(2048);
            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 (UTF16.isHighSurrogate(ch32)) {
                        char low = buffer[c++];
                        ch32 = UTF16.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

     * as the result of casting to a string according to the XPath rules. For xs:double, the canonical
     * representation always uses exponential notation.
     */

    public CharSequence getCanonicalLexicalRepresentation() {
        FastStringBuffer fsb = new FastStringBuffer(20);
        return FloatingPointConverter.appendDoubleExponential(fsb, value);
    }
View Full Code Here

TOP

Related Classes of org.pdf4j.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.