Package net.sf.saxon.om

Examples of net.sf.saxon.om.FastStringBuffer


    * Callback interface for SAX: not for application use
    */

    public void comment (CharSequence chars, int locationId, int properties) throws XPathException {
        if (tree.commentBuffer==null) {
            tree.commentBuffer = new FastStringBuffer(200);
        }
        int s = tree.commentBuffer.length();
        tree.commentBuffer.append(chars.toString());
        nodeNr = tree.addNode(Type.COMMENT, currentDepth, s, chars.length(), -1);

View Full Code Here


            return TinyTextImpl.getStringValue(tree, next);
        }

        // now handle the general case

        FastStringBuffer sb = null;
        while (next < tree.numberOfNodes && tree.depth[next] > level) {
            final byte kind = tree.nodeKind[next];
            if (kind==Type.TEXT) {
//                int length = tree.beta[next];
//                int start = tree.alpha[next];
                if (sb==null) {
                    sb = new FastStringBuffer(1024);
                }
                //sb.append(tree.charBuffer, start, length);
                //sb.append(tree.charBuffer.subSequence(start, start+length));
                sb.append(TinyTextImpl.getStringValue(tree, next));
            } else if (kind==Type.WHITESPACE_TEXT) {
                if (sb==null) {
                    sb = new FastStringBuffer(1024);
                }
                WhitespaceTextImpl.appendStringValue(tree, next, sb);
            }
            next++;
        }
        if (sb==null) return "";
        return sb.condense();
    }
View Full Code Here

            if (ch(start[0]) == '<' && ch(start[1]) == '?' &&
                    ch(start[2]) == 'x' && ch(start[3]) == 'm' && ch(start[4]) == 'l') {
                if (debug) {
                    System.err.println("unparsed-text(): found XML declaration");
                }
                FastStringBuffer sb = new FastStringBuffer(read);
                for (int b = 0; b < read; b++) {
                    sb.append((char)start[b]);
                }
                String p = sb.toString();
                int v = p.indexOf("encoding");
                if (v >= 0) {
                    v += 8;
                    while (v < p.length() && " \n\r\t=\"'".indexOf(p.charAt(v)) >= 0) {
                        v++;
                    }
                    sb.setLength(0);
                    while (v < p.length() && p.charAt(v) != '"' && p.charAt(v) != '\'') {
                        sb.append(p.charAt(v++));
                    }
                    if (debug) {
                        System.err.println("unparsed-text(): encoding in XML declaration = " + sb.toString());
                    }
                    return sb.toString();
                }
                if (debug) {
                    System.err.println("unparsed-text(): no encoding found in XML declaration");
                }
            }
View Full Code Here

     * compare correctly under the equals() method.
     */

    public Object getCollationKey(String s) {
        // The string is normalized by removing leading zeros in a numeric component
        FastStringBuffer sb = new FastStringBuffer(s.length()*2);
        int pos1 = 0;
        Matcher m1 = pattern.matcher(s);
        while (true) {

            // find the next number in the string

            boolean b1 = m1.find(pos1);
            int m1start = (b1 ? m1.start() : s.length());

            // handle an alphabetic part (even if zero-length)

            sb.append(s.substring(pos1, m1start));

            // reached end?

            if (!b1) {
                return sb.toString();
            }

            // handle a numeric part

            int n1 = Integer.parseInt(s.substring(m1start, m1.end()));
            sb.append(n1 + "");

            // move on to the next part of the string

            pos1 = m1.end();
        }
View Full Code Here

     * @param inAttribute Set to true if the text is in an attribute value
     */

    protected void writeEscape(final CharSequence chars, final boolean inAttribute) throws IOException, XPathException {
        boolean inBraces = false;
        FastStringBuffer buff = new FastStringBuffer(chars.length());
        for (int i=0; i<chars.length(); i++) {
            char c = chars.charAt(i);
            if (!inBraces && c=='{' && chars.charAt(i+1)!='{') {
                inBraces = true;
                buff.append((char)0);   // switch disable-output-escaping on
            } else if (inBraces && c=='}') {
                inBraces = false;
                buff.append((char)0);   // switch disable-output-escaping off
            } else if (inBraces && c=='"') {
                buff.append((char)0);
                i++;
                do {
                    buff.append(c);
                    c = chars.charAt(i++);
                } while (c != '"');
                buff.append((char)0);
                i--;
            } else if (inBraces && c=='\'') {
                buff.append((char)0);
                i++;
                do {
                    buff.append(c);
                    c = chars.charAt(i++);
                } while (c != '\'');
                buff.append((char)0);
                i--;
            }
            buff.append(c);
        }
        super.writeEscape(buff, inAttribute);
    }
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 (UTF16.isHighSurrogate(c)) {
                    // assume the string is properly formed
                    char d = in.charAt(i++);
                    int s = UTF16.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

     * @param context the evaluation context
     * @throws net.sf.saxon.trans.XPathException if any of the integers is not the codepoint of a valid XML character
    */

    public static CharSequence unicodeToString(SequenceIterator chars, XPathContext context) throws XPathException {
        FastStringBuffer sb = new FastStringBuffer(256);
        NameChecker checker = context.getConfiguration().getNameChecker();
        while (true) {
            NumericValue nextInt = (NumericValue)chars.next();
            if (nextInt == null) {
                return sb.condense();
            }
            long next = nextInt.longValue();
            if (next < 0 || next > Integer.MAX_VALUE || !checker.isValidChar((int)next)) {
                XPathException e = new XPathException("Invalid XML character [x " + Integer.toHexString((int)next) + ']');
                e.setErrorCode("FOCH0001");
                if (context instanceof XPathContext) {
                    e.setXPathContext((XPathContext)context);
                }
                throw e;
            }
            if (next<65536) {
                sb.append((char)next);
            } else // output a surrogate pair
                sb.append(UTF16.highSurrogate((int)next));
                sb.append(UTF16.lowSurrogate((int)next));
            }
        }
    }
View Full Code Here

     * @return a message display of the contents of the sequence
     */

    public static String depictSequenceStart(SequenceIterator seq, int max) {
        try {
            FastStringBuffer sb = new FastStringBuffer(100);
            int count = 0;
            sb.append(" (");
            while (true) {
                Item next = seq.next();
                if (next == null) {
                    sb.append(") ");
                    return sb.toString();
                }
                if (count++ > 0) {
                    sb.append(", ");
                }
                if (count > max) {
                    sb.append("...) ");
                    return sb.toString();
                }

                sb.append(Err.depict(next));
            }
        } catch (XPathException e) {
            return "";
        }
    }
View Full Code Here

        }
    }

    public CharSequence getStringValueCS() {

        FastStringBuffer sb = new FastStringBuffer(16);

        sb.append("---");
        appendTwoDigits(sb, day);

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

    * Evaluate in a general context
    */

    public Item evaluateItem(XPathContext c) throws XPathException {
        int numArgs = argument.length;
        FastStringBuffer sb = new FastStringBuffer(1024);
        for (int i=0; i<numArgs; i++) {
            AtomicValue val = (AtomicValue)argument[i].evaluateItem(c);
            if (val!=null) {
                sb.append(val.getStringValueCS());
            }
        }
        return StringValue.makeStringValue(sb.condense());
    }
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.