MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / find_matching_paren

Function find_matching_paren

src/completion/phpdoc/helpers.rs:33–48  ·  view source on GitHub ↗

Find the position of the matching `)` for the first `(`, handling nesting. The input `s` is expected to start *after* the opening `(`. Returns the byte offset of the closing `)` within `s`.

(s: &str)

Source from the content-addressed store, hash-verified

31/// The input `s` is expected to start *after* the opening `(`. Returns
32/// the byte offset of the closing `)` within `s`.
33pub(super) fn find_matching_paren(s: &str) -> Option<usize> {
34 let mut depth = 0i32;
35 for (i, c) in s.char_indices() {
36 match c {
37 '(' => depth += 1,
38 ')' => {
39 if depth == 0 {
40 return Some(i);
41 }
42 depth -= 1;
43 }
44 _ => {}
45 }
46 }
47 None
48}
49
50/// Split a parameter string on commas, respecting nested `()`, `<>`,
51/// `[]`, and `{}` delimiters.

Callers 2

parse_declaration_infoFunction · 0.70
parse_symbol_infoFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected