Skip to content

Commit e3c74f1

Browse files
committed
pyi files, remove unused pyclass
1 parent 0af626e commit e3c74f1

File tree

4 files changed

+55
-43
lines changed

4 files changed

+55
-43
lines changed

regex_rs.pyi

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
class Regex:
2+
def __init__(
3+
self,
4+
pattern: str,
5+
*,
6+
case_insensive: bool | None = None,
7+
dfa_size_limit: int | None = None,
8+
dot_matches_new_line: bool | None = None,
9+
ignore_whitespace: bool | None = None,
10+
multi_line: bool | None = None,
11+
nest_limit: int | None = None,
12+
octal: bool | None = None,
13+
size_limit: int | None = None,
14+
swap_greed: bool | None = None,
15+
unicode: bool | None = None,
16+
) -> None: ...
17+
def is_match(self, text: str, start: int | None = None) -> bool: ...
18+
def find(self, text: str, start: int | None) -> Match | None: ...
19+
def find_iter(self, text: str) -> list[Match]: ...
20+
def captures(self, text: str) -> Captures | None: ...
21+
def split(self, text: str, limit: int | None = None) -> list[str]: ...
22+
def replace(self, text: str, rep: str, limit: int | None = None) -> str: ...
23+
def __repr__(self) -> str: ...
24+
def __str__(self) -> str: ...
25+
26+
27+
class Captures:
28+
def get(self, i: int) -> Match | None: ...
29+
def name(self, name: str) -> Match | None: ...
30+
def expand(self, replacement: str, dst: str) -> str: ...
31+
def __getitem__(self, i: int) -> Match | None: ...
32+
def __len__(self) -> int: ...
33+
def __repr__(self) -> str: ...
34+
35+
36+
class Match:
37+
matched_text: str
38+
start: int
39+
end: int
40+
def __str__(self) -> str: ...
41+
def __repr__(self) -> str: ...

src/capture_locations.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod capture_locations;
21
mod captures;
32
mod error;
43
mod match_struct;
@@ -10,7 +9,6 @@ use pyo3::prelude::*;
109
#[pymodule]
1110
fn regex_rs(_py: Python, m: &PyModule) -> PyResult<()> {
1211
m.add_class::<regex::Regex>()?;
13-
m.add_class::<capture_locations::CaptureLocations>()?;
1412
m.add_class::<match_struct::Match>()?;
1513
m.add_class::<captures::Captures>()?;
1614
Ok(())

src/regex.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,22 @@ impl Regex {
104104
Captures::try_new(Arc::new(text), |text| self.0.captures(text).ok_or(())).ok()
105105
}
106106

107-
pub fn split(&self, text: &str) -> Vec<String> {
108-
self.0.split(text).map(|v| v.to_owned()).collect()
109-
}
110-
111-
pub fn splitn(&self, text: &str, limit: usize) -> Vec<String> {
112-
self.0.splitn(text, limit).map(|v| v.to_owned()).collect()
113-
}
114-
115-
pub fn replace(&self, text: &str, rep: &str) -> String {
116-
self.0.replace(text, rep).into_owned()
117-
}
118-
119-
pub fn replace_all(&self, text: &str, rep: &str) -> String {
120-
self.0.replace_all(text, rep).into_owned()
107+
#[pyo3(signature = (text, limit=None))]
108+
pub fn split(&self, text: &str, limit: Option<usize>) -> Vec<String> {
109+
if let Some(limit) = limit {
110+
self.0.splitn(text, limit).map(|v| v.to_owned()).collect()
111+
} else {
112+
self.0.split(text).map(|v| v.to_owned()).collect()
113+
}
121114
}
122115

123-
pub fn replacen(&self, text: &str, limit: usize, rep: &str) -> String {
124-
self.0.replacen(text, limit, rep).into_owned()
116+
#[pyo3(signature = (text, rep, limit=None))]
117+
pub fn replace(&self, text: &str, rep: &str, limit: Option<usize>) -> String {
118+
if let Some(limit) = limit {
119+
self.0.replacen(text, limit, rep).into_owned()
120+
} else {
121+
self.0.replace_all(text, rep).into_owned()
122+
}
125123
}
126124

127125
// magic

0 commit comments

Comments
 (0)