aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorErik Terpstra <erterpstra@gmail.com>2020-06-25 11:20:25 +0200
committerLouis Pilfold <louis@lpil.uk>2020-06-25 14:31:57 +0100
commit8de363f9d7ddd3df55df73b27a3a87cf7c9bd707 (patch)
treead2f3fbe34697ffe542573b552038bff2bae5bca /src
parent641c5050ed226ef9fc1dbbe35df579dcd2e504d3 (diff)
downloadgleam_stdlib-8de363f9d7ddd3df55df73b27a3a87cf7c9bd707.tar.gz
gleam_stdlib-8de363f9d7ddd3df55df73b27a3a87cf7c9bd707.zip
Remove Match.number
Diffstat (limited to 'src')
-rw-r--r--src/gleam/regex.gleam10
-rw-r--r--src/gleam_stdlib.erl10
2 files changed, 4 insertions, 16 deletions
diff --git a/src/gleam/regex.gleam b/src/gleam/regex.gleam
index dc2a3f8..6534095 100644
--- a/src/gleam/regex.gleam
+++ b/src/gleam/regex.gleam
@@ -11,16 +11,10 @@ pub external type Regex
///
/// - match — the full string of the match.
/// - index — the index of the match in the original string.
-/// - number — each match is numbered, starting from 1
/// - submatches — a Regex can have subpatterns, sup-parts that are in parentheses.
///
pub type Match {
- Match(
- match: String,
- index: Int,
- number: Int,
- submatches: List(Option(String)),
- )
+ Match(match: String, index: Int, submatches: List(Option(String)))
}
/// When a regular expression fails to compile:
@@ -113,13 +107,11 @@ pub external fn split(Regex, String) -> List(String) =
/// Match(
/// match: "on a boat",
/// index: 5,
-/// number: 1,
/// submatches: [Some("boat")]
/// ),
/// Match(
/// match: "in a lake",
/// index: 15,
-/// number: 2,
/// submatches: [Some("lake")]
/// )
/// ]
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index 217d4d1..85855d1 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -200,17 +200,13 @@ regex_submatches(String, {S, L}) ->
false -> {some, SubMatch}
end.
-regex_matches(String, [{S, L} | Submatches], Number) ->
- {match, binary:part(String, S, L), S, Number,
+regex_matches(String, [{S, L} | Submatches]) ->
+ {match, binary:part(String, S, L), S,
lists:map(fun(X) -> regex_submatches(String, X) end, Submatches)}.
-regex_captured(_, [], _) -> [];
-regex_captured(String, [ H | T ], Number) ->
- [ regex_matches(String, H, Number) | regex_captured(String, T, Number + 1) ].
-
regex_scan(Regex, String) ->
case re:run(String, Regex, [global]) of
- {match, Captured} -> regex_captured(String, Captured, 1);
+ {match, Captured} -> lists:map(fun(X) -> regex_matches(String, X) end, Captured);
_ -> []
end.