Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit 9026a96

Browse files
committed
#143 - updated text.contains
1 parent 6ed62d5 commit 9026a96

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

src/main/eo/org/eolang/txt/text.eo

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,34 @@
105105

106106
# Checks that string contains substr
107107
[substr] > contains
108-
index-of. > idx!
109-
text
110-
s
111-
substr
112-
gt. > @
113-
idx
114-
-1
108+
substr.length > len!
109+
s.length > s-len!
110+
memory 0 > start
111+
memory FALSE > res
112+
[] > loop
113+
while. > @
114+
and.
115+
start.lt s-len
116+
lte.
117+
start.plus len
118+
s-len
119+
[i]
120+
if. > @
121+
lte.
122+
start.plus len
123+
s-len
124+
if.
125+
eq.
126+
s.slice start len
127+
substr
128+
seq
129+
res.write TRUE
130+
start.write s-len
131+
start.write (start.plus 1)
132+
FALSE
133+
seq > @
134+
loop
135+
res
115136

116137
# Checks that string ends with substr
117138
[substr] > ends-with

src/test/eo/org/eolang/txt/text-tests.eo

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,3 +651,23 @@
651651
text "漢 "
652652
0
653653
$.equal-to "漢"
654+
655+
[] > simple-contains-string
656+
assert-that > @
657+
contains.
658+
text "Привет, 世界"
659+
"世"
660+
$.equal-to TRUE
661+
"constains-string"
662+
663+
[] > check-all-contains-string
664+
assert-that > @
665+
and.
666+
contains.
667+
text "世界世界世界世界世界世界世界世界"
668+
"界"
669+
contains.
670+
text "世界世界世界世界世界世界й世界世界"
671+
"й"
672+
$.equal-to TRUE
673+
"constains-all-of-string"

0 commit comments

Comments
 (0)