From 204e51914d65913d2ba97219685268600feaa0cd Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 10 Sep 2020 07:39:44 +0800 Subject: [PATCH] feat: thinking in new api for search --- docs/adr/0005-switch-to-onig-sys-api.md | 2 +- scie-scanner/src/scanner/scanner.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/adr/0005-switch-to-onig-sys-api.md b/docs/adr/0005-switch-to-onig-sys-api.md index d37e8fe..5b1a1f7 100644 --- a/docs/adr/0005-switch-to-onig-sys-api.md +++ b/docs/adr/0005-switch-to-onig-sys-api.md @@ -14,7 +14,7 @@ for examples: - ONIG_REGSET_POSITION_LEAD (returns most left position) - ONIG_OPTION_CAPTURE_GROUP named and no-named group captured. - + ## Decision diff --git a/scie-scanner/src/scanner/scanner.rs b/scie-scanner/src/scanner/scanner.rs index ab2f836..ccea7b7 100644 --- a/scie-scanner/src/scanner/scanner.rs +++ b/scie-scanner/src/scanner/scanner.rs @@ -1,4 +1,4 @@ -use onig::Regex; +use onig::{Regex, SearchOptions}; use unicode_segmentation::UnicodeSegmentation; #[derive(Debug, Clone, Serialize)] @@ -68,6 +68,10 @@ impl Scanner { let regex = _regex.unwrap(); let mut capture_indices = vec![]; let _captures = regex.captures(after_pos_str.as_str()); + let zz = regex.search_with_options(&*origin_str.clone(), start_pos as usize, origin_str.clone().len(), SearchOptions::SEARCH_OPTION_NOTBOL, None); + if let Some(pos) = zz { + println!("pos: {:?}", pos); + } if let Some(captures) = _captures { for (_, pos) in captures.iter_pos().enumerate() { -- GitLab