Skip to content

Commit

Permalink
#143 - updated text.contains
Browse files Browse the repository at this point in the history
  • Loading branch information
Graur committed Mar 7, 2023
1 parent 6ed62d5 commit 9026a96
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/main/eo/org/eolang/txt/text.eo
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,34 @@

# Checks that string contains substr
[substr] > contains
index-of. > idx!
text
s
substr
gt. > @
idx
-1
substr.length > len!
s.length > s-len!
memory 0 > start
memory FALSE > res
[] > loop
while. > @
and.
start.lt s-len
lte.
start.plus len
s-len
[i]
if. > @
lte.
start.plus len
s-len
if.
eq.
s.slice start len
substr
seq
res.write TRUE
start.write s-len
start.write (start.plus 1)
FALSE
seq > @
loop
res

# Checks that string ends with substr
[substr] > ends-with
Expand Down
20 changes: 20 additions & 0 deletions src/test/eo/org/eolang/txt/text-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -651,3 +651,23 @@
text "漢 "
0
$.equal-to "漢"

[] > simple-contains-string
assert-that > @
contains.
text "Привет, 世界"
"世"
$.equal-to TRUE
"constains-string"

[] > check-all-contains-string
assert-that > @
and.
contains.
text "世界世界世界世界世界世界世界世界"
"界"
contains.
text "世界世界世界世界世界世界й世界世界"
"й"
$.equal-to TRUE
"constains-all-of-string"

0 comments on commit 9026a96

Please sign in to comment.