| 2 | use fancy_regex::Regex; |
| 3 | |
| 4 | pub fn extract_verification_code(content: &str) -> Option<String> { |
| 5 | let config = Config::load().unwrap_or_default(); |
| 6 | |
| 7 | let keyword_bounds = find_first_keyword_position(content, &config.verification_keywords); |
| 8 | if keyword_bounds.is_none() { |
| 9 | return None; |
| 10 | } |
| 11 | let keyword_bounds = keyword_bounds.unwrap(); |
| 12 | |
| 13 | let candidates = extract_candidate_codes(content, &config.verification_regex); |
| 14 | if candidates.is_empty() { |
| 15 | return None; |
| 16 | } |
| 17 | |
| 18 | let filtered_candidates = filter_candidates_step1(candidates, content); |
| 19 | if filtered_candidates.is_empty() { |
| 20 | return None; |
| 21 | } |
| 22 | |
| 23 | let result = find_closest_candidate(filtered_candidates, keyword_bounds); |
| 24 | |
| 25 | result |
| 26 | } |
| 27 | |
| 28 | fn find_first_keyword_position(text: &str, keywords: &[String]) -> Option<(usize, usize)> { |
| 29 | let text_lower = text.to_lowercase(); |