(
value: Option<&str>,
pattern: &'strings str,
start: i64,
n: i64,
subexpr: i64,
flags: Option<&'strings str>,
regex_cache: &'cache mut HashMap<(&'strings str, Option<&'str
| 382 | } |
| 383 | } |
| 384 | fn get_index<'strings, 'cache>( |
| 385 | value: Option<&str>, |
| 386 | pattern: &'strings str, |
| 387 | start: i64, |
| 388 | n: i64, |
| 389 | subexpr: i64, |
| 390 | flags: Option<&'strings str>, |
| 391 | regex_cache: &'cache mut HashMap<(&'strings str, Option<&'strings str>), Regex>, |
| 392 | ) -> Result<Option<i64>, ArrowError> |
| 393 | where |
| 394 | 'strings: 'cache, |
| 395 | { |
| 396 | let value = match value { |
| 397 | None => return Ok(None), |
| 398 | Some("") => return Ok(Some(0)), |
| 399 | Some(value) => value, |
| 400 | }; |
| 401 | let pattern: &Regex = compile_and_cache_regex(pattern, flags, regex_cache)?; |
| 402 | // println!("get_index: value = {}, pattern = {}, start = {}, n = {}, subexpr = {}, flags = {:?}", value, pattern, start, n, subexpr, flags); |
| 403 | if start < 1 { |
| 404 | return Err(ArrowError::ComputeError( |
| 405 | "regexp_instr() requires start to be 1-based".to_string(), |
| 406 | )); |
| 407 | } |
| 408 | |
| 409 | if n < 1 { |
| 410 | return Err(ArrowError::ComputeError( |
| 411 | "N must be 1 or greater".to_string(), |
| 412 | )); |
| 413 | } |
| 414 | |
| 415 | // --- Simplified byte_start_offset calculation --- |
| 416 | let total_chars = value.chars().count() as i64; |
| 417 | let byte_start_offset: usize = if start > total_chars { |
| 418 | // If start is beyond the total characters, it means we start searching |
| 419 | // after the string effectively. No matches possible. |
| 420 | return Ok(Some(0)); |
| 421 | } else { |
| 422 | // Get the byte offset for the (start - 1)-th character (0-based) |
| 423 | value |
| 424 | .char_indices() |
| 425 | .nth((start - 1) as usize) |
| 426 | .map(|(idx, _)| idx) |
| 427 | .unwrap_or(0) // Should not happen if start is valid and <= total_chars |
| 428 | }; |
| 429 | // --- End simplified calculation --- |
| 430 | |
| 431 | let search_slice = &value[byte_start_offset..]; |
| 432 | |
| 433 | // Handle subexpression capturing first, as it takes precedence |
| 434 | if subexpr > 0 { |
| 435 | return handle_subexp(pattern, search_slice, subexpr, value, byte_start_offset); |
| 436 | } |
| 437 | |
| 438 | // Use nth to get the N-th match (n is 1-based, nth is 0-based) |
| 439 | get_nth_match(pattern, search_slice, n, byte_start_offset, value) |
| 440 | } |
| 441 |
no test coverage detected
searching dependent graphs…