diff options
author | Erik Terpstra <erterpstra@gmail.com> | 2020-06-25 11:08:34 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2020-06-25 14:31:57 +0100 |
commit | 641c5050ed226ef9fc1dbbe35df579dcd2e504d3 (patch) | |
tree | 4a02f28b37979599e9556d07229178aef2b0f8cd | |
parent | ce82cffc8a03fed1e4421a0ba24bcd8652b48e77 (diff) | |
download | gleam_stdlib-641c5050ed226ef9fc1dbbe35df579dcd2e504d3.tar.gz gleam_stdlib-641c5050ed226ef9fc1dbbe35df579dcd2e504d3.zip |
Return byte indexes
-rw-r--r-- | src/gleam_stdlib.erl | 2 | ||||
-rw-r--r-- | test/gleam/regex_test.gleam | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl index e89458b..217d4d1 100644 --- a/src/gleam_stdlib.erl +++ b/src/gleam_stdlib.erl @@ -201,7 +201,7 @@ regex_submatches(String, {S, L}) -> end. regex_matches(String, [{S, L} | Submatches], Number) -> - {match, string:slice(String, S, L), S, Number, + {match, binary:part(String, S, L), S, Number, lists:map(fun(X) -> regex_submatches(String, X) end, Submatches)}. regex_captured(_, [], _) -> []; diff --git a/test/gleam/regex_test.gleam b/test/gleam/regex_test.gleam index da98cd8..fec4bd5 100644 --- a/test/gleam/regex_test.gleam +++ b/test/gleam/regex_test.gleam @@ -54,6 +54,17 @@ pub fn split_test() { } pub fn scan_test() { + assert Ok(re) = regex.from_string("Gl\\w+") + + regex.scan(re, "!Gleam") + |> should.equal([Match(match: "Gleam", index: 1, number: 1, submatches: [])]) + + regex.scan(re, "हGleam") + |> should.equal([Match(match: "Gleam", index: 3, number: 1, submatches: [])]) + + regex.scan(re, "𐍈Gleam") + |> should.equal([Match(match: "Gleam", index: 4, number: 1, submatches: [])]) + assert Ok(re) = regex.from_string("[oi]n a(.?) (\\w+)") regex.scan(re, "I am on a boat in a lake.") |