Skip to content

Commit

Permalink
Merge branch 'master' into 127
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 3, 2023
2 parents 58bcfe4 + 7d05fd5 commit 6acb4a2
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 90 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ This is how it works:
The object `QQ.txt.text` is a decorator of `QQ.string`.

The attribute `is-empty` is TRUE if the length of the
array is zero.
tuple is zero.

The attribute `trim` is a new string trimmed from both sides.

The attribute `joined` is a string that was obtained by concatenating
the strings from the array with the current string as a delimiter.
the strings from the tuple with the current string as a delimiter.

The attribute `contains` is TRUE if current string contains
`substr` as a substring.
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SOFTWARE.
<parent>
<groupId>com.jcabi</groupId>
<artifactId>parent</artifactId>
<version>0.65.0</version>
<version>0.66.0</version>
</parent>
<groupId>org.eolang</groupId>
<artifactId>eo-strings</artifactId>
Expand Down Expand Up @@ -87,7 +87,7 @@ SOFTWARE.
<dependency>
<groupId>org.eolang</groupId>
<artifactId>eo-runtime</artifactId>
<version>0.28.18</version>
<version>0.29.5</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -119,7 +119,7 @@ SOFTWARE.
<plugin>
<groupId>org.eolang</groupId>
<artifactId>eo-maven-plugin</artifactId>
<version>0.29.0</version>
<version>0.29.5</version>
<executions>
<execution>
<id>compile</id>
Expand All @@ -135,7 +135,7 @@ SOFTWARE.
<keepBinaries>
<glob>EOorg/EOeolang/EOtxt/**</glob>
</keepBinaries>
<failOnWarning>true</failOnWarning>
<failOnWarning>false</failOnWarning>
</configuration>
</execution>
<execution>
Expand Down
8 changes: 4 additions & 4 deletions src/main/eo/org/eolang/txt/regex.eo
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
[r] > regex
[] > compile /regex

# Match the text and return the array of matched blocks.
# Match the text and return the tuple of matched blocks.
# Each matched block consists of
# - start position in which match was found
# - matched string
# - array of identified matched groups
[txt] > match /array
# - tuple of identified matched groups
[txt] > match /tuple

# Matches
[txt] > matches
Expand All @@ -64,7 +64,7 @@
# pt - next unhandled index in text
# acc - replaced text so far
# pa - next unhandled index in replaced text
# m - matched segments array
# m - matched segments tuple
[pt acc pa m] > replacei
# Replace groups signs ($i) in old-rpl by the group of
# the list groups
Expand Down
4 changes: 2 additions & 2 deletions src/main/eo/org/eolang/txt/sscanf.eo
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
# This object with two free attributes:
# 1. format - is a formatter string (e.g. "Hello, %s!")
# 2. read - is a string where data exists (e.g. "Hello, John!")
# returns an array of formatted values (e.g. * "John").
[format read] > sscanf /array
# returns an tuple of formatted values (e.g. * "John").
[format read] > sscanf /tuple
88 changes: 76 additions & 12 deletions src/main/eo/org/eolang/txt/text.eo
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
-1
const-str

# Joins an array of strings, using current string
# Joins an tuple of strings, using current string
# as a delimiter
[items] > joined
reducedi. > res!
Expand All @@ -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 Expand Up @@ -354,13 +375,13 @@
length.
other

# Returns an array of strings, separated by a given string
# Returns an tuple of strings, separated by a given string
# @todo #22:30min Current implementation using Java.
# We should implement splitting string to array of strings
# We should implement splitting string to tuple of strings
# only via EOLANG code. We can do it by using reduce method.
[delimiter] > split /array
[delimiter] > split /tuple

# Check that all signs in string are letters.
# Check that all signs in string are numbers or letters.
# Works only for english letters
[] > is-alphabetic
reduced. > @
Expand All @@ -376,6 +397,49 @@
bytes-1-to-8
as-bytes.
x
and. > @
a
int-is-alphabetic
value

[b] > int-is-alphabetic
or. > @
and.
gte.
b
48
lte.
b
57
and.
gte.
b
97
lte.
b
122

[b] > bytes-1-to-8
concat. > @
00-00-00-00-00-00-00
b

# Check that all signs in string are letters.
# Works only for english letters
[] > is-alpha
reduced. > @
list
bytes-as-array
as-bytes.
low-cased.
text
s
TRUE
[a x]
as-int. > value!
is-alphabetic.bytes-1-to-8
as-bytes.
x
and. > @
a
int-is-alpha
Expand Down
122 changes: 67 additions & 55 deletions src/test/eo/org/eolang/txt/regex-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo-strings
+package org.eolang.txt
+junit
+tests
+version 0.0.0

# @todo #148:30min To enable tests with regex.replaced object.
# For some unknown reason, the tests with regex.replaced object
# are not working. The tests are commented out for now, but
# should be fixed. The reason is that somwhere in the code
# tuple.as-bytes object was called, but it doesn't exist.
[] > matches-string-against-pattern
assert-that > @
is-empty.
Expand Down Expand Up @@ -187,13 +192,14 @@
$.equal-to "Wrong regex syntax: \"/\" is missing"

[] > test-simple-replace
assert-that > @
replaced.
compile.
QQ.txt.regex "/([b])/"
"abc"
"11"
$.equal-to "a11c"
nop > @
assert-that
replaced.
compile.
QQ.txt.regex "/([b])/"
"abc"
"11"
$.equal-to "a11c"

[] > test-no-match-replace
assert-that > @
Expand All @@ -214,60 +220,66 @@
$.equal-to ""

[] > test-replace-with-empty
assert-that > @
replaced.
compile.
QQ.txt.regex "/([xyz]+)/"
"abxxxxxcd"
""
$.equal-to "abcd"
nop > @
assert-that
replaced.
compile.
QQ.txt.regex "/([xyz]+)/"
"abxxxxxcd"
""
$.equal-to "abcd"

[] > replace-groups-1
assert-that > @
regex.replaced.replacei.replace-by-groups
QQ.txt.text "q$0wer$1ty"
list
*
"GR0"
"GR1"
$.equal-to
"qGR0werGR1ty"
nop > @
assert-that
regex.replaced.replacei.replace-by-groups
QQ.txt.text "q$0wer$1ty"
list
*
"GR0"
"GR1"
$.equal-to
"qGR0werGR1ty"

[] > group-ref-0
assert-that > @
replaced.
compile.
QQ.txt.regex "/(([A-Za-z])[0-9])/"
"A2B"
"G$1G"
$.equal-to
"GA2GB"
nop > @
assert-that
replaced.
compile.
regex "/(([A-Za-z])[0-9])/"
"A2B"
"G$1G"
$.equal-to
"GA2GB"

[] > group-ref-1
assert-that > @
replaced.
compile.
QQ.txt.regex "/(([A-Za-z])[0-9])/"
"a1a"
"G$1G"
$.equal-to
"Ga1Ga"
nop > @
assert-that
replaced.
compile.
QQ.txt.regex "/(([A-Za-z])[0-9])/"
"a1a"
"G$1G"
$.equal-to
"Ga1Ga"

[] > group-ref-2
assert-that > @
replaced.
compile.
QQ.txt.regex "/([xyz]+)/"
"abxxxcd"
"$0"
$.equal-to "abxxxcd"
nop > @
assert-that
replaced.
compile.
QQ.txt.regex "/([xyz]+)/"
"abxxxcd"
"$0"
$.equal-to "abxxxcd"

[] > group-ref-3
assert-that > @
replaced.
compile.
QQ.txt.regex "/(([A-Za-z])[0-9])/"
"a1a\n"
"$1世"
$.equal-to
"a1世a\n"
nop > @
assert-that
replaced.
compile.
QQ.txt.regex "/(([A-Za-z])[0-9])/"
"a1a\n"
"$1世"
$.equal-to
"a1世a\n"
2 changes: 1 addition & 1 deletion src/test/eo/org/eolang/txt/sprintf-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
+alias org.eolang.txt.sprintf
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo-strings
+junit
+package org.eolang.txt
+tests
+version 0.0.0

[] > prints-simple-string
Expand Down
2 changes: 1 addition & 1 deletion src/test/eo/org/eolang/txt/sscanf-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
+alias org.eolang.txt.sscanf
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo-strings
+junit
+package org.eolang.txt
+tests
+version 0.0.0

[] > sscanf-with-string
Expand Down
Loading

0 comments on commit 6acb4a2

Please sign in to comment.