Package net.sf.saxon.om

Examples of net.sf.saxon.om.FastStringBuffer


        if (picture==null || picture.length()==0) {
            return "" + number;
        }

        int pictureLength = StringValue.getStringLength(picture);
        FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.TINY);
        int formchar = picture.charAt(0);
        if (UTF16CharacterSet.isHighSurrogate(formchar)) {
            formchar = UTF16CharacterSet.combinePair((char)formchar, picture.charAt(1));
        }

        switch(formchar) {

        case '0':
        case '1':
            sb.append(toRadical(number, westernDigits, pictureLength, groupSize, groupSeparator));
            if (ordinal != null && ordinal.length() > 0) {
                sb.append(ordinalSuffix(ordinal, number));
            }
            break;

        case 'A':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, latinUpper);

        case 'a':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, latinLower);

        case 'w':
        case 'W':
            int wordCase;
            if (picture.equals("W")) {
                wordCase = UPPER_CASE;
            } else if (picture.equals("w")) {
                wordCase = LOWER_CASE;
            } else {
                // includes cases like "ww" or "Wz". The action here is conformant, but it's not clear what's best
                wordCase = TITLE_CASE;
            }
            if (ordinal != null && ordinal.length() > 0) {
                return toOrdinalWords(ordinal, number, wordCase);
            } else {
                return toWords(number, wordCase);
            }

        case 'i':
            if (number==0) {
                return "0";
            }
            if (letterValue==null || letterValue.length() == 0 ||
                    letterValue.equals("traditional")) {
                return toRoman(number);
            } else {
                alphaDefault(number, 'i', sb);
            }
            break;

        case 'I':
            if (number==0) {
                return "0";
            }
            if (letterValue==null || letterValue.length() == 0 ||
                    letterValue.equals("traditional")) {
                return toRoman(number).toUpperCase();
            } else {
                alphaDefault(number, 'I', sb);
            }
            break;

        case '\u2460':
            // circled digits
            if (number == 0 || number > 20) {
                return "" + number;
            }
            return "" + (char)(0x2460 + number);

        case '\u2474':
            // parenthesized digits
            if (number == 0 || number > 20) {
                return "" + number;
            }
            return "" + (char)(0x2474 + number);

        case '\u2488':
            // digit full stop
            if (number == 0 || number > 20) {
                return "" + number;
            }
            return "" + (char)(0x2488 + number);            

        case '\u0391':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, greekUpper);

        case '\u03b1':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, greekLower);

        case '\u0410':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, cyrillicUpper);

        case '\u0430':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, cyrillicLower);

        case '\u05d0':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, hebrew);

        case '\u3042':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, hiraganaA);

        case '\u30a2':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, katakanaA);

        case '\u3044':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, hiraganaI);

        case '\u30a4':
            if (number==0) {
                return "0";
            }
            return toAlphaSequence(number, katakanaI);

        case '\u4e00':
            if (number==0) {
                return "0";
            }
            return toRadical(number, kanjiDigits, pictureLength, groupSize, groupSeparator);

        default:

            int digitValue = Alphanumeric.getDigitValue(formchar);
            if (digitValue >= 0) {

                int zero = formchar - digitValue;
                int[] digits = new int[10];
                for (int z=0; z<=9; z++) {
                    digits[z] = zero+z;
                }                                    

                return toRadical(number, digits, pictureLength, groupSize, groupSeparator);

            } else {
                if (number==0) return "0";
                if (formchar < '\u1100') {
                    alphaDefault(number, (char)formchar, sb);
                } else {
                    // fallback to western numbering
                    return
                        toRadical(number, westernDigits, pictureLength, groupSize, groupSeparator);
                }
                break;

            }
        }

        return sb.toString();
    }
View Full Code Here


                        // null should no longer be returned, but the spec has changed, so it's
                        // better to be defensive
                return new AnyURIValue(s);

            case GENERATE_ID:
                FastStringBuffer buffer = new FastStringBuffer(FastStringBuffer.TINY);
                node.generateId(buffer);
                buffer.condense();
                return new StringValue(buffer);

            case DOCUMENT_URI:
                // If the node is in the document pool, get the URI under which it is registered.
                // Otherwise, return its systemId.
View Full Code Here

        // for example "\", must be %-encoded.
        if (allAllowedAscii(s)) {
            // it's worth doing a prescan to avoid the cost of copying in the common all-ASCII case
            return s;
        }
        FastStringBuffer sb = new FastStringBuffer(s.length()+20);
        for (int i=0; i<s.length(); i++) {
            final char c = s.charAt(i);
            if (c>=0x7f || !allowedASCII[(int)c]) {
                escapeChar(c, ((i+1)<s.length() ? s.charAt(i+1) : ' '), sb);
            } else {
                sb.append(c);
            }
        }
        return sb;
    }
View Full Code Here

     * should NOT be %HH-encoded
     * @return the %HH-encoded string
     */

    public static CharSequence escape(CharSequence s, String allowedPunctuation) {
        FastStringBuffer sb = new FastStringBuffer(s.length());
        for (int i=0; i<s.length(); i++) {
            char c = s.charAt(i);
            if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9')) {
                sb.append(c);
            } else if (c<=0x20 || c>=0x7f) {
                escapeChar(c, ((i+1)<s.length() ? s.charAt(i+1) : ' '), sb);
            } else if (allowedPunctuation.indexOf(c) >= 0) {
                sb.append(c);
            } else {
                escapeChar(c, ' ', sb);
            }

        }
View Full Code Here

                         int groupSize,
                         String groupSeparator,
                         String letterValue,
                         String ordinal) {

        FastStringBuffer sb = new FastStringBuffer(16);
        int formchar = picture.charAt(0);
        if (UTF16CharacterSet.isHighSurrogate(formchar)) {
            formchar = UTF16CharacterSet.combinePair((char)formchar, picture.charAt(1));
        }

        /* only catch traditional formatting. */
        if (!"traditional".equals(letterValue)) {
          return super.format(number, picture, groupSize, groupSeparator, letterValue, ordinal);
        }

        switch(formchar) {
        case '\u05d0':
            if (number==0) return "0";
            sb.append(toTraditionalSequence(number, groupSeparator));
            break;
        default:
          return super.format(number, picture, groupSize, groupSeparator, letterValue, ordinal);
        }

        return sb.toString();
    }
View Full Code Here

    private static CharSequence formatDate(CalendarValue value, String format, String language, String country, XPathContext context)
    throws XPathException {

        Numberer numberer = context.getConfiguration().makeNumberer(language, country);
        FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.SMALL);
        if (numberer instanceof Numberer_en && !"en".equals(language)) {
            sb.append("[Language: en]");
        }
        int i = 0;
        while (true) {
            while (i < format.length() && format.charAt(i) != '[') {
                sb.append(format.charAt(i));
                if (format.charAt(i) == ']') {
                    i++;
                    if (i == format.length() || format.charAt(i) != ']') {
                        XPathException e = new XPathException("Closing ']' in date picture must be written as ']]'");
                        e.setErrorCode("XTDE1340");
                        e.setXPathContext(context);
                        throw e;
                    }
                }
                i++;
            }
            if (i == format.length()) {
                break;
            }
            // look for '[['
            i++;
            if (i < format.length() && format.charAt(i) == '[') {
                sb.append('[');
                i++;
            } else {
                int close = (i < format.length() ? format.indexOf("]", i) : -1);
                if (close == -1) {
                    XPathException e = new XPathException("Date format contains a '[' with no matching ']'");
                    e.setErrorCode("XTDE1340");
                    e.setXPathContext(context);
                    throw e;
                }
                String componentFormat = format.substring(i, close);
                sb.append(formatComponent(value, Whitespace.removeAllWhitespace(componentFormat), numberer, context));
                i = close+1;
            }
        }
        return sb;
    }
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(FastStringBuffer.SMALL);
        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(UTF16CharacterSet.highSurrogate((int)next));
                sb.append(UTF16CharacterSet.lowSurrogate((int)next));
            }
        }
    }
View Full Code Here

    * 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

            min = range[0];
            max = range[1];
            if (defaultFormat) {
                // if format was defaulted, the explicit widths override the implicit format
                if (primary.endsWith("1") && min != primary.length()) {
                    FastStringBuffer sb = new FastStringBuffer(min+1);
                    for (int i=1; i<min; i++) {
                        sb.append('0');
                    }
                    sb.append('1');
                    primary = sb.toString();
                }
            }
        }

        if ("P".equals(component)) {
View Full Code Here

                return tzname;
            } else {
                return NamedTimeZone.getOlsenTimeZoneName(value, country);
            }
        }
        FastStringBuffer sbz = new FastStringBuffer(8);
        value.appendTimezone(sbz);
        return sbz.toString();
    }
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.