std::matcher
The Matcher interface: what String.split, String.replace,
String.starts_with, String.ends_with, String.find and
String.find_all accept as the thing to look for. A String matches its
own text, a Regex matches its pattern, and a Codepoint matches itself.
String.contains takes the same three, as String’s Contains impls.
Import with import std::matcher.
Exports
Section titled “Exports”Interfaces
interface Matcher
Section titled “interface Matcher”interface Matcher fn is_contained_in(m: self, text: String) -> Bool fn is_prefix_of(m: self, text: String) -> Bool fn is_suffix_of(m: self, text: String) -> Bool fn split_in(m: self, text: String) -> List<String> fn replace_in(m: self, text: String, replacement: String) -> String fn find_all_in(m: self, text: String) -> List<String> fn find_in(m: self, text: String) -> Maybe<String> end
Something to look for in a string. String, Regex and Codepoint
implement it, so the String search functions take any of them:
String.split("a,b", ",") // ["a", "b"] String.split("a1b22c", Regex`\d+`) // ["a", "b", "c"]
Each function returns one String operation for text, with the matcher
first. Call the String functions rather than these; they exist so a type can
say how it is found, and so a function of your own can take any matcher as a
Matcher parameter.
import std::regex.Regex
digits = Regex`\d+`
assert String.contains("order 66", digits)
assert String.contains("order 66", "66")
assert Matcher.split_in(",", "a,b") == ["a", "b"]
Matcher.is_contained_in
Section titled “Matcher.is_contained_in”fn is_contained_in(m: self, text: String) -> Bool
interface Matcher
True if the matcher matches anywhere in text.
Matcher.is_prefix_of
Section titled “Matcher.is_prefix_of”fn is_prefix_of(m: self, text: String) -> Bool
interface Matcher
True if a match starts at the beginning of text.
Matcher.is_suffix_of
Section titled “Matcher.is_suffix_of”fn is_suffix_of(m: self, text: String) -> Bool
interface Matcher
True if a match ends at the end of text.
Matcher.split_in
Section titled “Matcher.split_in”fn split_in(m: self, text: String) -> List<String>
interface Matcher
The pieces of text between non-overlapping matches.
Matcher.replace_in
Section titled “Matcher.replace_in”fn replace_in(m: self, text: String, replacement: String) -> String
interface Matcher
text with every non-overlapping match replaced by replacement,
taken literally.
Matcher.find_all_in
Section titled “Matcher.find_all_in”fn find_all_in(m: self, text: String) -> List<String>
interface Matcher
Every non-overlapping match in text, left to right.
Matcher.find_in
Section titled “Matcher.find_in”fn find_in(m: self, text: String) -> Maybe<String>
interface Matcher
The first match in text, the leftmost: the first element find_all_in
returns, or None when there is no match.