Shared helpers for PHPDoc context detection and generation. These functions are used by both `context.rs` and `generation.rs` to parse PHP declarations (parameter lists, keyword positions, balanced parentheses). Find the position of a whole-word keyword in a declaration string. Returns the byte offset of the first occurrence of `keyword` that is not part of a larger identifier (i.e. the characte
(decl: &str, keyword: &str)
| 10 | /// not part of a larger identifier (i.e. the characters immediately |
| 11 | /// before and after the match are not ASCII-alphanumeric). |
| 12 | pub(super) fn find_keyword_pos(decl: &str, keyword: &str) -> Option<usize> { |
| 13 | let lower = decl.to_lowercase(); |
| 14 | let mut start = 0; |
| 15 | while let Some(pos) = lower[start..].find(keyword) { |
| 16 | let abs_pos = start + pos; |
| 17 | let before_ok = abs_pos == 0 || !decl.as_bytes()[abs_pos - 1].is_ascii_alphanumeric(); |
| 18 | let after_pos = abs_pos + keyword.len(); |
| 19 | let after_ok = |
| 20 | after_pos >= decl.len() || !decl.as_bytes()[after_pos].is_ascii_alphanumeric(); |
| 21 | if before_ok && after_ok { |
| 22 | return Some(abs_pos); |
| 23 | } |
| 24 | start = abs_pos + keyword.len(); |
| 25 | } |
| 26 | None |
| 27 | } |
| 28 | |
| 29 | /// Find the position of the matching `)` for the first `(`, handling nesting. |
| 30 | /// |
no test coverage detected