Skip to content

Commit

Permalink
rubify first chunk method
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 5, 2015
1 parent 2ffc419 commit 42ce0a0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/types/src/modules/String.rb
Expand Up @@ -557,8 +557,8 @@ def EscapeTags(text)
# @param [String] separators characters which delimit components
# @return first component or ""
def FirstChunk(s, separators)
l = Builtins.splitstring(s, separators)
Ops.get(l, 0, "")
return "" if !s || !separators
s[/\A[^#{separators}]*/]
end

# The 26 lowercase ASCII letters
Expand Down
1 change: 1 addition & 0 deletions library/types/test/string_test.rb
Expand Up @@ -451,6 +451,7 @@
it "returns first part s splitted by any of separators" do
expect(subject.FirstChunk("a b", " ")).to eq "a"
expect(subject.FirstChunk("a b", "\n\t ")).to eq "a"
expect(subject.FirstChunk("abc def", "\n\t ")).to eq "abc"
end

it "returns s string if there is no match of separators" do
Expand Down

0 comments on commit 42ce0a0

Please sign in to comment.