public abstract static class TruffleString.ByteIndexOfCodePointSetNode extends Node
TruffleString.ByteIndexOfCodePointSetNode.execute(AbstractTruffleString, int, int, TruffleString.CodePointSet)
for details.Node.Child, Node.Children
Modifier and Type | Method and Description |
---|---|
static TruffleString.ByteIndexOfCodePointSetNode |
create()
Create a new
TruffleString.ByteIndexOfCodePointSetNode . |
abstract int |
execute(AbstractTruffleString a,
int fromByteIndex,
int toByteIndex,
TruffleString.CodePointSet codePointSet)
Returns the byte index of the first codepoint present in the given
TruffleString.CodePointSet ,
bounded by fromByteIndex (inclusive) and toByteIndex (exclusive). |
static TruffleString.ByteIndexOfCodePointSetNode |
getUncached()
Get the uncached version of
TruffleString.ByteIndexOfCodePointSetNode . |
accept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, getSourceSection, insert, insert, isAdoptable, isSafelyReplaceableBy, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecialize, toString
public abstract int execute(AbstractTruffleString a, int fromByteIndex, int toByteIndex, TruffleString.CodePointSet codePointSet)
TruffleString.CodePointSet
,
bounded by fromByteIndex
(inclusive) and toByteIndex
(exclusive).
TruffleString.ByteIndexOfCodePointSetNode
will specialize on the given TruffleString.CodePointSet
's
content, which is therefore required to be
partial evaluation constant
.
Usage example: A node that scans a string for a known set of code points and escapes them with '\'.
abstract static class StringEscapeNode extends Node {
public static final TruffleString.Encoding ENCODING = TruffleString.Encoding.UTF_32;
public static final TruffleString.ByteIndexOfCodePointSetNode.CodePointSet ESCAPE_CHARS = TruffleString.ByteIndexOfCodePointSetNode.CodePointSet.fromRanges(new int[]{
'\n', '\n',
'\r', '\r',
// ....
}, ENCODING);
abstract TruffleString execute(TruffleString input);
@Specialization
static TruffleString run(TruffleString input,
@Cached TruffleString.ByteIndexOfCodePointSetNode byteIndexOfCodePointSetNode,
@Cached TruffleStringBuilder.AppendSubstringByteIndexNode appendSubstringByteIndexNode,
@Cached TruffleString.CodePointAtByteIndexNode codePointAtByteIndexNode,
@Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode,
@Cached TruffleString.ByteLengthOfCodePointNode byteLengthOfCodePointNode,
@Cached TruffleStringBuilder.ToStringNode toStringNode) {
int byteLength = input.byteLength(ENCODING);
TruffleStringBuilder sb = TruffleStringBuilder.create(ENCODING, byteLength);
int lastPos = 0;
int pos = 0;
while (pos >= 0) {
pos = byteIndexOfCodePointSetNode.execute(input, lastPos, byteLength, ESCAPE_CHARS);
int substringLength = (pos < 0 ? byteLength : pos) - lastPos;
appendSubstringByteIndexNode.execute(sb, input, lastPos, substringLength);
if (pos >= 0) {
int codePoint = codePointAtByteIndexNode.execute(input, pos, ENCODING);
appendCodePointNode.execute(sb, '\\');
appendCodePointNode.execute(sb, codePoint);
int codePointLength = byteLengthOfCodePointNode.execute(input, pos, ENCODING);
lastPos = pos + codePointLength;
}
}
return toStringNode.execute(sb);
}
}
codePointSet
- The set of codepoints to look for. This parameter is expected to be
partial evaluation
constant
.public static TruffleString.ByteIndexOfCodePointSetNode create()
TruffleString.ByteIndexOfCodePointSetNode
.public static TruffleString.ByteIndexOfCodePointSetNode getUncached()
TruffleString.ByteIndexOfCodePointSetNode
.