Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Commit c232fd4e authored by Ary Borenszweig's avatar Ary Borenszweig
Browse files

Fixed String#split(Int32)

parent 9884b5f2
No related merge requests found
......@@ -283,6 +283,7 @@ describe "String" do
assert { " foo bar".split(' ').should eq(["foo", "bar"]) }
assert { " foo bar\n\t baz ".split(' ').should eq(["foo", "bar", "baz"]) }
assert { " foo bar\n\t baz ".split.should eq(["foo", "bar", "baz"]) }
assert { " foo bar\n\t baz ".split(2).should eq(["foo", "bar\n\t baz "]) }
assert { " foo bar\n\t baz ".split(" ").should eq(["foo", "bar", "baz"]) }
assert { "foo,bar,baz,qux".split(',', 1).should eq(["foo,bar,baz,qux"]) }
assert { "foo,bar,baz,qux".split(',', 3).should eq(["foo", "bar", "baz,qux"]) }
......
......@@ -574,7 +574,7 @@ class String
i = 0
looking_for_space = false
limit_reached = false
while i < bytesize && !limit_reached
while i < bytesize
if looking_for_space
while i < bytesize
c = cstr[i]
......@@ -586,9 +586,7 @@ class String
looking_for_space = false
if limit && ary.length + 1 == limit
looking_for_space = true # To push the rest of the string
limit_reached = true
index = i
end
break
......@@ -604,6 +602,8 @@ class String
break
end
end
break if limit_reached
end
end
if looking_for_space
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment