Skip to content

Commit

Permalink
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions spec/std/string_spec.cr
Original file line number Diff line number Diff line change
@@ -546,6 +546,7 @@ describe "String" do
assert { "bar".index('r').should eq(2) }
assert { "日本語".index('本').should eq(1) }
assert { "bar".index('あ').should be_nil }
assert { "あいう_えお".index('_').should eq(3) }

describe "with offset" do
assert { "foobarbaz".index('a', 5).should eq(7) }
@@ -594,6 +595,7 @@ describe "String" do
assert { "foobar".rindex('a').should eq(4) }
assert { "foobar".rindex('g').should be_nil }
assert { "日本語日本語".rindex('本').should eq(4) }
assert { "あいう_えお".rindex('_').should eq(3) }

describe "with offset" do
assert { "faobar".rindex('a', 3).should eq(1) }
@@ -801,6 +803,7 @@ describe "String" do
assert { "foobar".ends_with?('x').should be_false }
assert { "よし".ends_with?('し').should be_true }
assert { "よし".ends_with?('な').should be_false }
assert { "あいう_".ends_with?('_').should be_true }
end

describe "=~" do
4 changes: 2 additions & 2 deletions src/string.cr
Original file line number Diff line number Diff line change
@@ -2093,7 +2093,7 @@ class String
# ```
def index(search : Char, offset = 0)
# If it's ASCII we can delegate to slice
if search.ascii?
if search.ascii? && ascii_only?
return to_slice.index(search.ord.to_u8, offset)
end

@@ -2150,7 +2150,7 @@ class String
# ```
def rindex(search : Char, offset = size - 1)
# If it's ASCII we can delegate to slice
if search.ascii?
if search.ascii? && ascii_only?
return to_slice.rindex(search.ord.to_u8, offset)
end

0 comments on commit b8a18c1

Please sign in to comment.