use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnStringLength method string_length.
/**
* Obtain the string length of the arguments.
*
* @param args
* are used to obtain the string length.
* @throws DynamicError
* Dynamic error.
* @return The result of obtaining the string length from the arguments.
*/
public static ResultSequence string_length(Collection args, EvaluationContext ec) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultSequence arg1 = null;
if (cargs.isEmpty()) {
// support for arity = 0
return getResultSetForArityZero(ec);
} else {
arg1 = (ResultSequence) cargs.iterator().next();
}
String str = "";
if (!arg1.empty()) {
str = ((XSString) arg1.first()).value();
}
return new XSInteger(BigInteger.valueOf(UTF16.countCodePoint(str)));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnSubstringAfter 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 FnSubstringAfter method substring_after.
/**
* Substring-After operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:substring-after operation.
*/
public static ResultSequence substring_after(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
String str1 = "";
String str2 = "";
if (!arg1.empty()) {
str1 = ((XSString) arg1.first()).value();
}
ResultSequence arg2 = (ResultSequence) argiter.next();
if (!arg2.empty()) {
str2 = ((XSString) arg2.first()).value();
}
int str1len = str1.length();
int str2len = str2.length();
if (str2len == 0) {
return new XSString(str1);
}
int index = str1.indexOf(str2);
if (index == -1) {
return new XSString("");
}
String result = "";
if ((index + str2len) < str1len) {
index += str2len;
result = str1.substring(index, str1len);
}
return new XSString(result);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnTokenize method tokenize.
/**
* Tokenize operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:tokenize operation.
*/
public static ResultSequence tokenize(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultBuffer rs = new ResultBuffer();
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
String str1 = "";
if (!arg1.empty()) {
str1 = ((XSString) arg1.first()).value();
}
ResultSequence arg2 = (ResultSequence) argiter.next();
String pattern = ((XSString) arg2.first()).value();
String flags = null;
if (argiter.hasNext()) {
ResultSequence flagRS = null;
flagRS = (ResultSequence) argiter.next();
flags = flagRS.first().getStringValue();
if (validflags.indexOf(flags) == -1 && flags.length() > 0) {
throw DynamicError.regex_flags_error(null);
}
}
try {
ArrayList ret = tokenize(pattern, flags, str1);
for (Iterator retIter = ret.iterator(); retIter.hasNext(); ) {
rs.add(new XSString((String) retIter.next()));
}
} catch (PatternSyntaxException err) {
throw DynamicError.regex_error(null);
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FnNormalizeUnicode method expected_args.
/**
* Calculate the expected arguments.
*
* @return The expected arguments.
*/
public static synchronized Collection expected_args() {
if (_expected_args == null) {
_expected_args = new ArrayList();
_expected_args.add(new SeqType(new XSString(), SeqType.OCC_QMARK));
_expected_args.add(new SeqType(new XSString(), SeqType.OCC_NONE));
}
return _expected_args;
}
Aggregations