-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
73 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
from Standard.Base import all | ||
|
||
import Standard.Base.Data.Text.Regex | ||
import Standard.Base.Data.Text.Regex.Mode | ||
|
||
import Standard.Base.Data.Text.Matching_Mode | ||
import Standard.Base.Data.Text.Case | ||
|
@@ -158,9 +157,10 @@ Text.characters self = | |
- pattern: The pattern to match `self` against. We recommend using _raw text_ | ||
to write your patterns. | ||
- mode: This argument specifies how many matches the engine will try and | ||
find. When mode is set to either `Mode.First` or `Mode.Full`, this method | ||
will return either a single `Match` or `Nothing`. If set to an `Integer` or | ||
`Mode.All`, this method will return either a `Vector Match` or `Nothing`. | ||
find. When mode is set to either `Regex_Mode.First` or `Regex_Mode.Full`, | ||
this method will return either a single `Match` or `Nothing`. If set to an | ||
`Integer` or `Regex_Mode.All`, this method will return either | ||
a `Vector Match` or `Nothing`. | ||
- match_ascii: Enables or disables pure-ASCII matching for the regex. If you | ||
know your data only contains ASCII then you can enable this for a | ||
performance boost on some regex engines. | ||
|
@@ -206,8 +206,8 @@ Text.characters self = | |
example_match = | ||
regex = ".+@.+" | ||
"[email protected]".match regex | ||
Text.match : Text | Engine.Pattern -> Mode.Mode -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Vector.Vector Option.Option -> Match | Vector.Vector Match | Nothing ! Regex.Compile_Error | ||
Text.match self pattern mode=Mode.All match_ascii=Nothing case_insensitive=Nothing dot_matches_newline=Nothing multiline=Nothing comments=Nothing extra_opts=[] = | ||
Text.match : Text | Engine.Pattern -> (Regex_Mode | Matching_Mode) -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Vector.Vector Option.Option -> Match | Vector.Vector Match | Nothing ! Regex.Compile_Error | ||
Text.match self pattern mode=Regex_Mode.All match_ascii=Nothing case_insensitive=Nothing dot_matches_newline=Nothing multiline=Nothing comments=Nothing extra_opts=[] = | ||
compiled_pattern = Regex.compile pattern match_ascii=match_ascii case_insensitive=case_insensitive dot_matches_newline=dot_matches_newline multiline=multiline comments=comments extra_opts=extra_opts | ||
compiled_pattern.match self mode | ||
|
||
|
@@ -220,9 +220,10 @@ Text.match self pattern mode=Mode.All match_ascii=Nothing case_insensitive=Nothi | |
- pattern: The pattern to match `self` against. We recommend using _raw text_ | ||
to write your patterns. | ||
- mode: This argument specifies how many matches the engine will try and | ||
find. When mode is set to either `Mode.First` or `Mode.Full`, this method | ||
will return either a single `Match` or `Nothing`. If set to an `Integer` or | ||
`Mode.All`, this method will return either a `Vector Match` or `Nothing`. | ||
find. When mode is set to either `Regex_Mode.First` or `Regex_Mode.Full`, | ||
this method will return either a single `Match` or `Nothing`. If set to an | ||
`Integer` or `Regex_Mode.All`, this method will return either | ||
a `Vector Match` or `Nothing`. | ||
- match_ascii: Enables or disables pure-ASCII matching for the regex. If you | ||
know your data only contains ASCII then you can enable this for a | ||
performance boost on some regex engines. | ||
|
@@ -282,9 +283,10 @@ Text.matches self pattern match_ascii=Nothing case_insensitive=Nothing dot_match | |
- pattern: The pattern to match `self` against. We recommend using _raw text_ | ||
to write your patterns. | ||
- mode: This argument specifies how many matches the engine will try and | ||
find. When mode is set to either `Mode.First` or `Mode.Full`, this method | ||
will return either a single `Text` or `Nothing`. If set to an `Integer` or | ||
`Mode.All`, this method will return either a `Vector Text` or `Nothing`. | ||
find. When mode is set to either `Regex_Mode.First` or `Regex_Mode.Full`, | ||
this method will return either a single `Text` or `Nothing`. If set to an | ||
`Integer` or `Regex_Mode.All`, this method will return either | ||
a `Vector Text` or `Nothing`. | ||
- match_ascii: Enables or disables pure-ASCII matching for the regex. If you | ||
know your data only contains ASCII then you can enable this for a | ||
performance boost on some regex engines. | ||
|
@@ -329,8 +331,8 @@ Text.matches self pattern match_ascii=Nothing case_insensitive=Nothing dot_match | |
example_find = | ||
text = "Now I know my ABCs" | ||
text.find "\w{1,3}" | ||
Text.find : Text | Engine.Pattern -> Mode.Mode -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Vector.Vector Option.Option -> Text | Vector.Vector Text | Nothing | ||
Text.find self pattern mode=Mode.All match_ascii=Nothing case_insensitive=Nothing dot_matches_newline=Nothing multiline=Nothing comments=Nothing extra_opts=[] = | ||
Text.find : Text | Engine.Pattern -> (Regex_Mode | Matching_Mode) -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Vector.Vector Option.Option -> Text | Vector.Vector Text | Nothing | ||
Text.find self pattern mode=Regex_Mode.All match_ascii=Nothing case_insensitive=Nothing dot_matches_newline=Nothing multiline=Nothing comments=Nothing extra_opts=[] = | ||
compiled_pattern = Regex.compile pattern match_ascii=match_ascii case_insensitive=case_insensitive dot_matches_newline=dot_matches_newline multiline=multiline comments=comments extra_opts=extra_opts | ||
compiled_pattern.find self mode | ||
|
||
|
@@ -378,7 +380,7 @@ Text.split self delimiter="," matcher=Text_Matcher_Data = if delimiter.is_empty | |
Text_Utils.substring self start end | ||
Regex_Matcher_Data _ _ _ _ _ -> | ||
compiled_pattern = matcher.compile delimiter | ||
compiled_pattern.split self mode=Mode.All | ||
compiled_pattern.split self mode=Regex_Mode.All | ||
|
||
## ALIAS Replace Text | ||
Replaces the first, last, or all occurrences of term with new_text in the | ||
|
@@ -456,30 +458,32 @@ Text.split self delimiter="," matcher=Text_Matcher_Data = if delimiter.is_empty | |
"aaa aaa".replace "aa" "c" matcher=Regex_Matcher . should_equal "ca ca" | ||
"aaa aaa".replace "aa" "c" mode=Matching_Mode.First matcher=Regex_Matcher . should_equal "ca aaa" | ||
"aaa aaa".replace "aa" "c" mode=Matching_Mode.Last matcher=Regex_Matcher . should_equal "aaa ca" | ||
Text.replace : Text -> Text -> (Matching_Mode.First | Matching_Mode.Last | Mode.All) -> (Text_Matcher | Regex_Matcher) -> Text | ||
Text.replace self term="" new_text="" mode=Mode.All matcher=Text_Matcher_Data = if term.is_empty then self else | ||
Text.replace : Text -> Text -> Matching_Mode | Regex_Mode -> (Text_Matcher | Regex_Matcher) -> Text | ||
Text.replace self term="" new_text="" mode=Regex_Mode.All matcher=Text_Matcher_Data = if term.is_empty then self else | ||
case matcher of | ||
Text_Matcher_Data case_sensitivity -> | ||
array_from_single_result result = case result of | ||
Nothing -> Array.empty | ||
_ -> Array.new_1 result | ||
spans_array = case case_sensitivity of | ||
True -> case mode of | ||
Mode.All -> | ||
Regex_Mode.All -> | ||
Text_Utils.span_of_all self term | ||
Matching_Mode.First -> | ||
array_from_single_result <| Text_Utils.span_of self term | ||
Matching_Mode.Last -> | ||
array_from_single_result <| Text_Utils.last_span_of self term | ||
_ -> Error.throw (Illegal_Argument_Error_Data "Invalid mode.") | ||
Case_Insensitive_Data locale -> case mode of | ||
Mode.All -> | ||
Regex_Mode.All -> | ||
Text_Utils.span_of_all_case_insensitive self term locale.java_locale | ||
Matching_Mode.First -> | ||
array_from_single_result <| | ||
Text_Utils.span_of_case_insensitive self term locale.java_locale False | ||
Matching_Mode.Last -> | ||
array_from_single_result <| | ||
Text_Utils.span_of_case_insensitive self term locale.java_locale True | ||
_ -> Error.throw (Illegal_Argument_Error_Data "Invalid mode.") | ||
Text_Utils.replace_spans self spans_array new_text | ||
Regex_Matcher_Data _ _ _ _ _ -> | ||
compiled_pattern = matcher.compile term | ||
|
@@ -903,7 +907,7 @@ Text.starts_with self prefix matcher=Text_Matcher_Data = case matcher of | |
Regex_Matcher_Data _ _ _ _ _ -> | ||
preprocessed_pattern = "\A(?:" + prefix + ")" | ||
compiled_pattern = matcher.compile preprocessed_pattern | ||
match = compiled_pattern.match self Mode.First | ||
match = compiled_pattern.match self Regex_Mode.First | ||
match.is_nothing.not | ||
|
||
## ALIAS Check Suffix | ||
|
@@ -940,7 +944,7 @@ Text.ends_with self suffix matcher=Text_Matcher_Data = case matcher of | |
Regex_Matcher_Data _ _ _ _ _ -> | ||
preprocessed_pattern = "(?:" + suffix + ")\z" | ||
compiled_pattern = matcher.compile preprocessed_pattern | ||
match = compiled_pattern.match self Mode.First | ||
match = compiled_pattern.match self Regex_Mode.First | ||
match.is_nothing.not | ||
|
||
## ALIAS Contains | ||
|
@@ -1002,7 +1006,7 @@ Text.contains self term="" matcher=Text_Matcher_Data = case matcher of | |
Text_Utils.contains_case_insensitive self term locale.java_locale | ||
Regex_Matcher_Data _ _ _ _ _ -> | ||
compiled_pattern = matcher.compile term | ||
match = compiled_pattern.match self Mode.First | ||
match = compiled_pattern.match self Regex_Mode.First | ||
match.is_nothing.not | ||
|
||
## Text to JSON conversion. | ||
|
@@ -1405,11 +1409,11 @@ Text.location_of self term="" mode=Matching_Mode.First matcher=Text_Matcher_Data | |
Span_Data (Range_Data grapheme_span.grapheme_start grapheme_span.grapheme_end) self | ||
Regex_Matcher_Data _ _ _ _ _ -> case mode of | ||
Matching_Mode.First -> | ||
case matcher.compile term . match self Mode.First of | ||
case matcher.compile term . match self Matching_Mode.First of | ||
Nothing -> Nothing | ||
match -> match.span 0 . to_grapheme_span | ||
Matching_Mode.Last -> | ||
case matcher.compile term . match self Mode.All of | ||
case matcher.compile term . match self Regex_Mode.All of | ||
Nothing -> Nothing | ||
matches -> matches.last.span 0 . to_grapheme_span | ||
|
||
|
@@ -1496,7 +1500,7 @@ Text.location_of_all self term="" matcher=Text_Matcher_Data = case matcher of | |
grapheme_spans.map grapheme_span-> | ||
Span_Data (Range_Data grapheme_span.grapheme_start grapheme_span.grapheme_end) self | ||
Regex_Matcher_Data _ _ _ _ _ -> | ||
case matcher.compile term . match self Mode.All of | ||
case matcher.compile term . match self Regex_Mode.All of | ||
Nothing -> [] | ||
matches -> matches.map m-> m.span 0 . to_grapheme_span | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.