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;
}
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();
}
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());
}
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;
}
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;
}
Aggregations