Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: dfd1a6fc3018
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d05cd1202209
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Feb 4, 2015

  1. Copy the full SHA
    9c45d77 View commit details
  2. Copy the full SHA
    d05cd12 View commit details
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/string/chars_tags.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
fails:String#chars passes each char in self to the given block
fails:String#chars returns self
fails:String#chars is unicode aware
fails:String#chars returns characters in the same encoding as self
fails:String#chars works with multibyte characters
fails:String#chars works if the String's contents is invalid for its encoding
fails:String#chars returns a different character if the String is transcoded
fails:String#chars uses the String's encoding to determine what characters it contains
fails:String#chars returns an array when no block given
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/string/each_char_tags.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
fails:String#each_char passes each char in self to the given block
fails:String#each_char returns self
fails:String#each_char is unicode aware
fails:String#each_char returns characters in the same encoding as self
fails:String#each_char works with multibyte characters
fails:String#each_char works if the String's contents is invalid for its encoding
fails:String#each_char returns a different character if the String is transcoded
fails:String#each_char uses the String's encoding to determine what characters it contains
fails:String#each_char returns an enumerator when no block given
Original file line number Diff line number Diff line change
@@ -673,6 +673,47 @@ public RubyBasicObject downcase(RubyString string) {
}
}

@CoreMethod(names = "each_char", needsBlock = true)
public abstract static class EachCharNode extends YieldingCoreMethodNode {

@Child private CallDispatchHeadNode toEnumNode;

public EachCharNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public EachCharNode(EachCharNode prev) {
super(prev);
}

@Specialization
public Object eachChar(VirtualFrame frame, RubyString string, @SuppressWarnings("unused") UndefinedPlaceholder block) {
notDesignedForCompilation();

if (toEnumNode == null) {
CompilerDirectives.transferToInterpreter();
toEnumNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

return toEnumNode.call(frame, string, "to_enum", null, getContext().newSymbol("each_char"));
}

@Specialization
public RubyString eachChar(VirtualFrame frame, RubyString string, RubyProc block) {
notDesignedForCompilation();

// TODO (nirvdrum 04-Feb-15): This needs to support Ruby's encoding and code range semantics. For now, this hack will suffice for very simple Strings.
final String javaString = string.toString();

for (int i = 0; i < javaString.length(); i++) {
yield(frame, block, getContext().makeString(javaString.charAt(i)));
}

return string;
}

}

@CoreMethod(names = "each_line")
public abstract static class EachLineNode extends YieldingCoreMethodNode {

Original file line number Diff line number Diff line change
@@ -32,4 +32,14 @@ def include?(needle)
!!find_string(StringValue(needle), 0)
end

def chars
if block_given?
each_char do |char|
yield char
end
else
each_char.to_a
end
end

end