Examples of FastStringBuffer


Examples of client.net.sf.saxon.ce.tree.util.FastStringBuffer

//                return tzname;
//            } else {
//                return NamedTimeZone.getOlsenTimeZoneName(value, country);
//            }
//        }
        FastStringBuffer sbz = new FastStringBuffer(8);
        value.appendTimezone(sbz);
        return sbz.toString();
    }
View Full Code Here

Examples of client.net.sf.saxon.ce.tree.util.FastStringBuffer

        int[] a2 = sv2.expand();
        int[] a3 = sv3.expand();

        int length1 = a1.length;
        int length2 = a2.length;
        FastStringBuffer sb = new FastStringBuffer(length1);
    inputLoop:
        for (int i=0; i<length1; i++) {
            int ch = a1[i];
            for (int j=0; j<length2; j++) {
                 if (a2[j] == ch) {
                     if (j < a3.length) {
                        sb.appendWideChar(a3[j]);
                     } else {
                         // do nothing, delete the character
                     }
                     continue inputLoop;
                 }
            }
            sb.appendWideChar(ch);
        }

        return StringValue.makeStringValue(sb);
    }
View Full Code Here

Examples of client.net.sf.saxon.ce.tree.util.FastStringBuffer

    * Evaluate in a general context
    */

    public Item evaluateItem(XPathContext c) throws XPathException {
        int numArgs = argument.length;
        FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.SMALL);
        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

Examples of client.net.sf.saxon.ce.tree.util.FastStringBuffer

    public static BigDecimal adjustToDecimal(double value, int precision) {
        final String zeros = (precision == 1 ? "00000" : "000000000");
        final String nines = (precision == 1 ? "99999" : "999999999");
        BigDecimal initial = new BigDecimal(value);
        BigDecimal trial = null;
        FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.TINY);
        DecimalValue.decimalToString(initial, fsb);
        String s = fsb.toString();
        int start = (s.charAt(0) == '-' ? 1 : 0);
        int p = s.indexOf(".");
        int i = s.lastIndexOf(zeros);
        if (i > 0) {
            if (p < 0 || i < p) {
                // we're in the integer part
                // try replacing all following digits with zeros and seeing if we get the same double back
                FastStringBuffer sb = new FastStringBuffer(s.length());
                sb.append(s.substring(0, i));
                for (int n=i; n<s.length(); n++) {
                    sb.append(s.charAt(n)=='.' ? '.' : '0');
                }
                trial = new BigDecimal(sb.toString());
            } else {
                // we're in the fractional part
                // try truncating the number before the zeros and seeing if we get the same double back
                trial = new BigDecimal(s.substring(0, i));

            }
        } else {
            i = s.indexOf(nines);
            if (i >= 0) {
                if (i == start) {
                    // number starts with 99999... or -99999. Try rounding up to 100000.. or -100000...
                    FastStringBuffer sb = new FastStringBuffer(s.length() + 1);
                    if (start == 1) {
                        sb.append('-');
                    }
                    sb.append('1');
                    for (int n=start; n<s.length(); n++) {
                        sb.append(s.charAt(n)=='.' ? '.' : '0');
                    }
                    trial = new BigDecimal(sb.toString());
                } else {
                    // try rounding up
                    while (i >= 0 && (s.charAt(i) == '9' || s.charAt(i) == '.')) {
                        i--;
                    }
                    if (i < 0 || s.charAt(i) == '-') {
                        return initial;     // can't happen: we've already handled numbers starting 99999..
                    } else if (p < 0 || i < p) {
                        // we're in the integer part
                        FastStringBuffer sb = new FastStringBuffer(s.length());
                        sb.append(s.substring(0, i));
                        sb.append((char)((int)s.charAt(i) + 1));
                        for (int n=i; n<s.length(); n++) {
                            sb.append(s.charAt(n)=='.' ? '.' : '0');
                        }
                        trial = new BigDecimal(sb.toString());
                    } else {
                        // we're in the fractional part - can ignore following digits
                        String s2 = s.substring(0, i) + (char)((int)s.charAt(i) + 1);
                        trial = new BigDecimal(s2);
                    }
View Full Code Here

Examples of client.net.sf.saxon.ce.tree.util.FastStringBuffer

                } catch (XPathException e) {
                    value = new DoubleValue(value.getDoubleValue() * multiplier);
                }
            }

            FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.TINY);
            if (value instanceof DoubleValue || value instanceof FloatValue) {
                BigDecimal dec = adjustToDecimal(value.getDoubleValue(), 2);
                formatDecimal(dec, sb);

                //formatDouble(value.getDoubleValue(), sb);

            } else if (value instanceof IntegerValue) {
                formatInteger(value, sb);

            } else if (value instanceof DecimalValue) {
                //noinspection RedundantCast
                formatDecimal(((DecimalValue)value).getDecimalValue(), sb);
            }

            // System.err.println("Justified number: " + sb.toString());

            // Map the digits and decimal point to use the selected characters

            int[] ib = StringValue.expand(sb);
            int ibused = ib.length;
            int point = sb.indexOf('.');
            if (point == -1) {
                point = sb.length();
            } else {
                ib[point] = dfs.decimalSeparator;

                // If there is no fractional part, delete the decimal point
                if (maxFractionPartSize == 0) {
                    ibused--;
                }
            }

            // Map the digits

            if (dfs.zeroDigit != '0') {
                int newZero = dfs.zeroDigit;
                for (int i=0; i<ibused; i++) {
                    int c = ib[i];
                    if (c>='0' && c<='9') {
                        ib[i] = (c-'0'+newZero);
                    }
                }
            }

            // Add the whole-part grouping separators

            if (wholePartGroupingPositions != null) {
                if (wholePartGroupingPositions.length == 1) {
                    // grouping separators are at regular positions
                    int g = wholePartGroupingPositions[0];
                    int p = point - g;
                    while (p > 0) {
                        ib = insert(ib, ibused++, dfs.groupingSeparator, p);
                        //sb.insert(p, unicodeChar(dfs.groupingSeparator));
                        p -= g;
                    }
                } else {
                    // grouping separators are at irregular positions
                    for (int i=0; i<wholePartGroupingPositions.length; i++) {
                        int p = point - wholePartGroupingPositions[i];
                        if (p > 0) {
                            ib = insert(ib, ibused++, dfs.groupingSeparator, p);
                            //sb.insert(p, unicodeChar(dfs.groupingSeparator));
                        }
                    }
                }
            }

            // Add the fractional-part grouping separators

            if (fractionalPartGroupingPositions != null) {
                    // grouping separators are at irregular positions.
                for (int i=0; i<fractionalPartGroupingPositions.length; i++) {
                    int p = point + 1 + fractionalPartGroupingPositions[i] + i;
                    if (p < ibused-1) {
                        ib = insert(ib, ibused++, dfs.groupingSeparator, p);
                        //sb.insert(p, dfs.groupingSeparator);
                    } else {
                        break;
                    }
                }
            }

            // System.err.println("Grouped number: " + sb.toString());

            //sb.insert(0, prefix);
            //sb.insert(0, minusSign);
            //sb.append(suffix);
            FastStringBuffer res = new FastStringBuffer(prefix.length() + minusSign.length() + suffix.length() + ibused);
            res.append(minusSign);
            res.append(prefix);
            res.append(StringValue.contract(ib, ibused));
            res.append(suffix);
            return res;
        }
View Full Code Here

Examples of client.net.sf.saxon.ce.tree.util.FastStringBuffer

     * @return a representation of the expression as a string
     */

    public String toString() {
        // fallback implementation
        FastStringBuffer buff = new FastStringBuffer(FastStringBuffer.SMALL);
        String className = getClass().getName();
        while (true) {
            int dot = className.indexOf('.');
            if (dot >= 0) {
                className = className.substring(dot+1);
            } else {
                break;
            }
        }
        buff.append(className);
        Iterator iter = iterateSubExpressions();
        boolean first = true;
        while (iter.hasNext()) {
            buff.append(first ? "(" : ", ");
            buff.append(iter.next().toString());
            first = false;
        }
        if (!first) {
            buff.append(")");
        }
        return buff.toString();
    }
View Full Code Here

Examples of client.net.sf.saxon.ce.tree.util.FastStringBuffer

     * has been deferred, and if a failure occurs during the deferred evaluation.
     * No failure is possible in the case of an AtomicValue.
     */

    public String getStringValue() throws XPathException {
        FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.SMALL);
        SequenceIterator iter = iterate();
        Item item = iter.next();
        if (item != null) {
            while (true) {
                sb.append(item.getStringValueCS());
                item = iter.next();
                if (item == null) {
                    break;
                }
                sb.append(' ');
            }
        }
        return sb.toString();
    }
View Full Code Here

Examples of client.net.sf.saxon.ce.tree.util.FastStringBuffer

    public String getDisplayName() {
        if (prefixStart == content.length) {
            return getLocalName();
        } else {
            FastStringBuffer buff = new FastStringBuffer(content.length - localNameStart + 1);
            buff.append(content, prefixStart, content.length - prefixStart);
            buff.append(':');
            buff.append(content, localNameStart, prefixStart - localNameStart);
            return buff.toString();
        }
    }
View Full Code Here

Examples of client.net.sf.saxon.ce.tree.util.FastStringBuffer

     * otherwise.
     * @return the QName in Clark notation
     */

    public String getClarkName() {
        FastStringBuffer buff = new FastStringBuffer(content.length - prefixStart + 2);
        if (localNameStart > 0) {
            buff.append('{');
            buff.append(content, 0, localNameStart);
            buff.append('}');
        }
        buff.append(content, localNameStart, prefixStart - localNameStart);
        return buff.toString();
    }
View Full Code Here

Examples of client.net.sf.saxon.ce.tree.util.FastStringBuffer

     *         expression object doesn't match at any position, the original String is returned
     *         unchanged).
     */
    public CharSequence subst(UnicodeString in, UnicodeString replacement) {
        // String to return
        FastStringBuffer sb = new FastStringBuffer(in.length() * 2);

        // Start at position 0 and search the whole string
        int pos = 0;
        int len = in.length();

        // Try a match at each position
        while (pos < len && match(in, pos)) {
            // Append chars from input string before match
            for (int i = pos; i < getParenStart(0); i++) {
                sb.appendWideChar(in.charAt(i));
            }

            if (!program.flags.isLiteral()) {
                // Process references to captured substrings
                int maxCapture = getParenCount() - 1;

                for (int i = 0; i < replacement.length(); i++) {
                    int ch = replacement.charAt(i);
                    if (ch == '\\') {
                        ch = replacement.charAt(++i);
                        if (ch == '\\' || ch == '$') {
                            sb.append((char) ch);
                        } else {
                            throw new RESyntaxException("Invalid escape in replacement string");
                        }
                    } else if (ch == '$') {
                        ch = replacement.charAt(++i);
                        if (!(ch >= '0' && ch <= '9')) {
                            throw new RESyntaxException("$ in replacement must be followed by a digit");
                        }
                        int n = (ch - '0');
                        if (maxCapture <= 9) {
                            if (maxCapture >= n) {
                                UnicodeString captured = getParen(n);
                                if (captured != null) {
                                    for (int j = 0; j < captured.length(); j++) {
                                        sb.appendWideChar(captured.charAt(j));
                                    }
                                }
                            } else {
                                // append a zero-length string (no-op)
                            }
                        } else {
                            while (true) {
                                if (i >= replacement.length()) {
                                    break;
                                }
                                ch = replacement.charAt(++i);
                                if (ch >= '0' && ch <= '9') {
                                    int m = n * 10 + (ch - '0');
                                    if (m > maxCapture) {
                                        i--;
                                        break;
                                    } else {
                                        n = m;
                                    }
                                } else {
                                    i--;
                                    break;
                                }
                            }
                            UnicodeString captured = getParen(n);
                            for (int j = 0; j < captured.length(); j++) {
                                sb.appendWideChar(captured.charAt(j));
                            }
                        }
                    } else {
                        sb.appendWideChar(ch);
                    }
                }

            } else {
                // Append substitution without processing backreferences
                for (int i = 0; i < replacement.length(); i++) {
                    sb.appendWideChar(replacement.charAt(i));
                }
            }

            // Move forward, skipping past match
            int newpos = getParenEnd(0);

            // We always want to make progress!
            if (newpos == pos) {
                newpos++;
            }

            // Try new position
            pos = newpos;

        }

        // If there's remaining input, append it
        for (int i = pos; i < len; i++) {
            sb.appendWideChar(in.charAt(i));
        }

        // Return string buffer
        return sb.condense();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.