Search in sources :

Example 21 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnStringToCodepoints method expected_args.

/**
 * Obtain a list of expected arguments.
 *
 * @return Result of operation.
 */
public static synchronized Collection expected_args() {
    if (_expected_args == null) {
        _expected_args = new ArrayList();
        _expected_args.add(new SeqType(new XSString(), SeqType.OCC_QMARK));
    }
    return _expected_args;
}
Also used : SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 22 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnStringToCodepoints method string_to_codepoints.

/**
 * Base-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:base-uri operation.
 */
public static ResultSequence string_to_codepoints(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    XSString xstr = (XSString) arg1.first();
    CodePointIterator cpi = new StringCodePointIterator(xstr.value());
    ResultBuffer rs = new ResultBuffer();
    for (int codePoint = cpi.current(); codePoint != CodePointIterator.DONE; codePoint = cpi.next()) {
        rs.add(new XSInteger(BigInteger.valueOf(codePoint)));
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) CodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.CodePointIterator) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator)

Example 23 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnSubstring method substring.

/**
 * Obtain a substring from the arguments.
 *
 * @param args
 *            are used to obtain a substring.
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of obtaining a substring from the arguments.
 */
public static ResultSequence substring(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args(args));
    Iterator argi = cargs.iterator();
    ResultSequence stringArg = (ResultSequence) argi.next();
    ResultSequence startPosArg = (ResultSequence) argi.next();
    ResultSequence lengthArg = null;
    if (argi.hasNext()) {
        lengthArg = (ResultSequence) argi.next();
    }
    if (stringArg.empty()) {
        return emptyString();
    }
    String str = ((XSString) stringArg.first()).value();
    double dstart = ((XSDouble) startPosArg.first()).double_value();
    // is start is NaN, no chars are returned
    if (Double.isNaN(dstart) || Double.NEGATIVE_INFINITY == dstart) {
        return emptyString();
    }
    long istart = Math.round(dstart);
    long ilength = Long.MAX_VALUE;
    if (lengthArg != null) {
        double dlength = ((XSDouble) lengthArg.first()).double_value();
        if (Double.isNaN(dlength))
            return emptyString();
        // Switch to the rounded kind
        ilength = Math.round(dlength);
        if (ilength <= 0)
            return emptyString();
    }
    // could guess too short in cases supplementary chars
    StringBuffer sb = new StringBuffer((int) Math.min(str.length(), ilength));
    // This looks like an inefficient way to iterate, but due to surrogate handling,
    // string indexes are no good here. Welcome to UTF-16!
    CodePointIterator strIter = new StringCodePointIterator(str);
    for (long p = 1; strIter.current() != CodePointIterator.DONE; ++p, strIter.next()) {
        if (istart <= p && p - istart < ilength)
            sb.append(UCharacter.toChars(strIter.current()));
    }
    return new XSString(sb.toString());
}
Also used : XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) CodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.CodePointIterator) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator) CodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.CodePointIterator) Iterator(java.util.Iterator) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator)

Example 24 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnSubstringBefore method expected_args.

/**
 * Obtain a list of expected arguments.
 *
 * @return Result of operation.
 */
public static synchronized Collection expected_args() {
    if (_expected_args == null) {
        _expected_args = new ArrayList();
        SeqType arg = new SeqType(new XSString(), SeqType.OCC_QMARK);
        _expected_args.add(arg);
        _expected_args.add(arg);
    }
    return _expected_args;
}
Also used : SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 25 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnTrace method trace.

/**
 * Trace operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:trace operation.
 */
public static ResultSequence trace(Collection args) throws DynamicError {
    // sanity check args
    if (args.size() != 2)
        DynamicError.throw_type_error();
    Iterator argsi = args.iterator();
    ResultSequence arg1 = (ResultSequence) argsi.next();
    ResultSequence arg2 = (ResultSequence) argsi.next();
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg2.first();
    if (!(at instanceof XSString))
        DynamicError.throw_type_error();
    XSString label = (XSString) at;
    int index = 1;
    for (Iterator i = arg1.iterator(); i.hasNext(); index++) {
        at = (AnyType) i.next();
        System.out.println(label.value() + " [" + index + "] " + ((AnyType) at).string_type() + ":" + at.getStringValue());
    }
    return arg1;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Aggregations

XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)73 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)37 ArrayList (java.util.ArrayList)32 Collection (java.util.Collection)32 Iterator (java.util.Iterator)29 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)29 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)9 Item (org.eclipse.wst.xml.xpath2.api.Item)7 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)7 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)6 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)6 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)5 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)5 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)5 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)5 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)5 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)4 XSUntypedAtomic (org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic)4 URL (java.net.URL)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3