use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class FunNormalizeSpace method eval.
@Override
public Sequence eval(Sequence contextSequence, final Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
if (contextItem != null) {
contextSequence = contextItem.toSequence();
}
String value = null;
if (getSignature().getArgumentCount() == 0) {
if (contextSequence == null) {
throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");
}
value = !contextSequence.isEmpty() ? contextSequence.itemAt(0).getStringValue() : "";
} else {
final Sequence seq = getArgument(0).eval(contextSequence);
if (seq == null) {
throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");
}
if (!seq.isEmpty()) {
value = seq.getStringValue();
}
}
final Sequence result;
if (value == null) {
result = StringValue.EMPTY_STRING;
} else {
result = new StringValue(normalize(value));
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class FunCodepointsToString method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
}
Sequence result;
if (args[0].isEmpty()) {
result = StringValue.EMPTY_STRING;
} else {
final StringBuilder buf = new StringBuilder();
for (final SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
final long next = ((NumericValue) i.nextItem()).getLong();
if (next < 0 || next > Integer.MAX_VALUE || !XMLChar.isValid((int) next)) {
throw new XPathException(this, ErrorCodes.FOCH0001, "Codepoint " + next + " is not a valid character.");
}
if (next < 65536) {
buf.append((char) next);
} else {
// output a surrogate pair
buf.append(XMLChar.highSurrogate((int) next));
buf.append(XMLChar.lowSurrogate((int) next));
}
}
result = new StringValue(buf.toString());
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class FunConcat method eval.
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
if (getArgumentCount() < 2) {
throw new XPathException(this, ErrorCodes.XPST0017, "concat() requires at least two arguments");
}
final StringBuilder concat = new StringBuilder();
for (int i = 0; i < getArgumentCount(); i++) {
concat.append(getArgument(i).eval(contextSequence, contextItem).getStringValue());
}
final Sequence result = new StringValue(concat.toString());
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class FunDefaultCollation method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
}
final Sequence result = new StringValue(context.getDefaultCollation());
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class FunEncodeForURI method eval.
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
Sequence result;
final Sequence seq = getArgument(0).eval(contextSequence, contextItem);
if (seq.isEmpty()) {
// If $uri-part is the empty sequence, returns the zero-length string.
result = StringValue.EMPTY_STRING;
} else {
String value;
value = URIUtils.encodeForURI(seq.getStringValue());
result = new StringValue(value);
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
Aggregations