Skip to content

Commit

Permalink
Using Char Indices :shipit:
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeadarsh2008 committed Jul 5, 2024
1 parent 3861152 commit 4e880df
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ crate-type = ["cdylib"]
pyo3 = "0.22.0"
regex = "1.10.5"
lazy_static = "1.5.0"
unicode-segmentation = "1.11.0"
# unicode-segmentation = "1.11.0"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "flpc"
version = "0.2.2"
version = "0.2.3"
description = "A Lightning Fast ⚡ Rust-based regex crate wrapper for Python3 to get faster performance. 👾"
maintainers = [{ name = "Adarsh Gourab Mahalik", email = "gourabmahalikadarsh@gmail.com" }]
readme = "README.md"
Expand Down
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use regex::{Captures, Regex, RegexBuilder};
use std::collections::HashMap;
use std::sync::Mutex;
use lazy_static::lazy_static;
use unicode_segmentation::UnicodeSegmentation;

#[pyclass]
struct Pattern {
Expand Down Expand Up @@ -57,21 +56,21 @@ impl Match {

fn start(&self, idx: usize) -> Option<usize> {
self.captures.get(idx).map(|m| {
self.captures.get(0).unwrap().as_str()[..m.start()].graphemes(true).count()
self.captures.get(0).unwrap().as_str()[..m.start()].chars().count()
})
}

fn end(&self, idx: usize) -> Option<usize> {
self.captures.get(idx).map(|m| {
self.captures.get(0).unwrap().as_str()[..m.end()].graphemes(true).count()
self.captures.get(0).unwrap().as_str()[..m.end()].chars().count()
})
}

fn span(&self, idx: usize) -> Option<(usize, usize)> {
self.captures.get(idx).map(|m| {
let full_match = self.captures.get(0).unwrap().as_str();
let start = full_match[..m.start()].graphemes(true).count();
let end = full_match[..m.end()].graphemes(true).count();
let start = full_match[..m.start()].chars().count();
let end = full_match[..m.end()].chars().count();
(start, end)
})
}
Expand Down

0 comments on commit 4e880df

Please sign in to comment.