Skip to content

Commit

Permalink
Showing 3 changed files with 12 additions and 31 deletions.
1 change: 1 addition & 0 deletions spec/truffle/tags/core/string/start_with_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:String#start_with? works for multibyte strings
Original file line number Diff line number Diff line change
@@ -1542,37 +1542,6 @@ private RubyArray splitHelper(RubyString string, String sep) {
}
}

@CoreMethod(names = "start_with?", argumentsAsArray = true)
public abstract static class StartWithNode extends CoreMethodNode {

@Child private ToStrNode toStrNode;

public StartWithNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
toStrNode = insert(ToStrNodeFactory.create(getContext(), getSourceSection(), null));
}

public StartWithNode(StartWithNode prev) {
super(prev);
toStrNode = prev.toStrNode;
}

@Specialization
public boolean startWith(VirtualFrame frame, RubyString string, Object... prefixes) {
notDesignedForCompilation();

for (Object prefix : prefixes) {
final RubyString coerced = toStrNode.executeRubyString(frame, prefix);

if (string.toString().startsWith(coerced.toString())) {
return true;
}
}

return false;
}
}

@CoreMethod(names = "sub", required = 2)
public abstract static class SubNode extends RegexpNodes.EscapingNode {

Original file line number Diff line number Diff line change
@@ -47,4 +47,15 @@ def chomp(separator=$/)
str.chomp!(separator) || str
end

def start_with?(*prefixes)
prefixes.each do |original_prefix|
prefix = Rubinius::Type.check_convert_type original_prefix, String, :to_str
unless prefix
raise TypeError, "no implicit conversion of #{original_prefix.class} into String"
end
return true if self[0, prefix.length] == prefix
end
false
end

end

0 comments on commit f8854d2

Please sign in to comment.