Created
October 4, 2010 09:13
-
-
Save kronos/609427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 561d512870022dc2affc5c6de7e930064cf85212 Mon Sep 17 00:00:00 2001 | |
From: Ivan Samsonov <[email protected]> | |
Date: Mon, 4 Oct 2010 13:11:06 +0400 | |
Subject: [PATCH 1/2] Add spec for StringIO: method gets accepts string as separator | |
--- | |
spec/ruby/library/stringio/gets_spec.rb | 11 +++++++++++ | |
1 files changed, 11 insertions(+), 0 deletions(-) | |
diff --git a/spec/ruby/library/stringio/gets_spec.rb b/spec/ruby/library/stringio/gets_spec.rb | |
index a2e4d0f..1e8fd1f 100644 | |
--- a/spec/ruby/library/stringio/gets_spec.rb | |
+++ b/spec/ruby/library/stringio/gets_spec.rb | |
@@ -26,6 +26,17 @@ describe "StringIO#gets when passed [separator]" do | |
$_.should be_nil | |
end | |
+ it "accepts string as separator" do | |
+ @io.gets("is>") | |
+ $_.should == "this>" | |
+ @io.gets("an>") | |
+ $_.should == "is>an>" | |
+ @io.gets("example") | |
+ $_.should == "example" | |
+ @io.gets("ple") | |
+ $_.should be_nil | |
+ end | |
+ | |
it "updates self's lineno by one" do | |
@io.gets(">") | |
@io.lineno.should eql(1) | |
-- | |
1.6.6.1 | |
From 1e1061296607afdac53d67005637cf2258bbf4f2 Mon Sep 17 00:00:00 2001 | |
From: Ivan Samsonov <[email protected]> | |
Date: Mon, 4 Oct 2010 13:12:31 +0400 | |
Subject: [PATCH 2/2] StringIO#gets can accepts string as separator. Fixes #513 | |
--- | |
lib/stringio.rb | 7 ++++--- | |
1 files changed, 4 insertions(+), 3 deletions(-) | |
diff --git a/lib/stringio.rb b/lib/stringio.rb | |
index 6ff5a7a..a9505e3 100644 | |
--- a/lib/stringio.rb | |
+++ b/lib/stringio.rb | |
@@ -512,7 +512,7 @@ class StringIO | |
elsif sep.empty? | |
if stop = @string.index("\n\n", @pos) | |
stop += 2 | |
- line = @string[@pos .. stop - 2] | |
+ line = @string[@pos ... stop] | |
while @string[stop] == ?\n | |
stop += 1 | |
end | |
@@ -523,8 +523,9 @@ class StringIO | |
end | |
else | |
if stop = @string.index(sep, @pos) | |
- line = @string[@pos .. stop] | |
- @pos = stop + 1 | |
+ stop += sep.length | |
+ line = @string[@pos ... stop] | |
+ @pos = stop | |
else | |
line = @string[@pos .. -1] | |
@pos = @string.size | |
-- | |
1.6.6.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment