Skip to content

Commit b61478d

Browse files
committed
clean up docs
1 parent 3c72f6d commit b61478d

File tree

1 file changed

+45
-28
lines changed

1 file changed

+45
-28
lines changed

src/lib.rs

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ impl PyRegex {
7272
/// function and returns all matched strings in a list, if no matches it
7373
/// returns a empty list
7474
///
75-
/// # Example (python)
76-
/// ```python
77-
/// >>> a = pyre.findall(r"n[o|0]*b", "Dont say noob say n00b or the bot will ban u")
78-
/// >>> a
79-
/// ["noob", "n00b"]
80-
/// ```
81-
///
8275
/// Args:
8376
/// other:
8477
/// The other string to be matched against the compiled regex.
@@ -97,19 +90,9 @@ impl PyRegex {
9790
}
9891

9992
/// Matches the compiled regex string to another string passed to this
100-
/// function and returns all matched strings that are captured by the notated,
93+
/// function and returns all matched groups that are captured by the notated,
10194
/// regex if non are matched it returns a empty list.
10295
///
103-
/// # Example (python)
104-
/// ```python
105-
/// >>> a = pyre.all_captures(
106-
/// r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)",
107-
/// "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931). "
108-
/// )
109-
/// >>> a
110-
/// [['Citizen Kane', '1941'], ['The Wizard of Oz', '1939'], ['M', '1931']]
111-
/// ```
112-
///
11396
/// Args:
11497
/// other:
11598
/// The other string to be matched against the compiled regex.
@@ -126,6 +109,17 @@ impl PyRegex {
126109
caps
127110
}
128111

112+
/// Matches the compiled regex string to another string passed to this
113+
/// function and returns the first matched group according to the compiled
114+
/// regex pattern.
115+
///
116+
/// Args:
117+
/// other:
118+
/// The other string to be matched against the compiled regex.
119+
///
120+
/// Returns:
121+
/// A list with containing grouped matches relating
122+
/// to the compiled regex.
129123
fn captures(&self, other: &str) -> Option<Vec<Option<String>>> {
130124
let capture = match self.regex.captures(other) {
131125
Some(c) => c,
@@ -135,6 +129,25 @@ impl PyRegex {
135129

136130
Some(new)
137131
}
132+
133+
/// Function that given returns a vector of tuples that contain (start_match, end_match+1)
134+
/// according to the compiled regex.
135+
///
136+
/// Args:
137+
/// other:
138+
/// The other string to be matched against the compiled regex.
139+
///
140+
/// Returns:
141+
/// A list with containing grouped matches relating
142+
/// to the compiled regex.
143+
fn matches(regex_pattern: &str, other: &str) -> Vec<(usize, usize)> {
144+
let re = Regex::new(regex_pattern).unwrap();
145+
let mut matches = Vec::new();
146+
for m in re.find_iter(input_str) {
147+
matches.push((m.start(), m.end()));
148+
}
149+
matches
150+
}
138151
}
139152

140153
fn list_captures(capture: regex::Captures) ->Vec<Option<String>> {
@@ -154,19 +167,23 @@ fn list_captures(capture: regex::Captures) ->Vec<Option<String>> {
154167
new
155168
}
156169

157-
/// Function that given a `regex_pattern` and an input `input_str` returns a
158-
/// vector of tuples that contain (start_match, end_match+1):
159-
/// # Example (python)
160-
/// ```python
161-
/// >>> a = pyre.matches(r"n[o|0]*b", "Dont say noob say n00b or the bot will ban u")
162-
/// >>> a
163-
/// [(9,13),(18,22)]
164-
/// ```
170+
/// Function that given a `regex_pattern` and an input `input_str` will produce
171+
/// the matching points of the start and end of the match.
172+
///
173+
/// Args:
174+
/// regex_pattern:
175+
/// The regex pattern to be matched against a string.
176+
/// other:
177+
/// The other string to be matched against the compiled regex.
178+
///
179+
/// Returns:
180+
/// A vector of tuples that contain (start_match, end_match+1).
181+
///
165182
#[pyfunction]
166-
pub fn matches(regex_pattern: &str, input_str: &str) -> Vec<(usize, usize)> {
183+
pub fn matches(regex_pattern: &str, other: &str) -> Vec<(usize, usize)> {
167184
let re = Regex::new(regex_pattern).unwrap();
168185
let mut matches = Vec::new();
169-
for m in re.find_iter(input_str) {
186+
for m in re.find_iter(other) {
170187
matches.push((m.start(), m.end()));
171188
}
172189
matches

0 commit comments

Comments
 (0)