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

Function skip_balanced_brackets_back

src/subject_extraction.rs:76–96  ·  view source on GitHub ↗

Skip backwards past a balanced bracket group `[…]` in a char slice. `pos` must point one past the closing `]`. Returns the index of the opening `[`, or `None` if brackets are unbalanced.

(chars: &[char], pos: usize)

Source from the content-addressed store, hash-verified

74/// `pos` must point one past the closing `]`. Returns the index of the
75/// opening `[`, or `None` if brackets are unbalanced.
76fn skip_balanced_brackets_back(chars: &[char], pos: usize) -> Option<usize> {
77 if pos == 0 || chars[pos - 1] != ']' {
78 return None;
79 }
80 let mut depth: u32 = 0;
81 let mut j = pos;
82 while j > 0 {
83 j -= 1;
84 match chars[j] {
85 ']' => depth += 1,
86 '[' => {
87 depth -= 1;
88 if depth == 0 {
89 return Some(j);
90 }
91 }
92 _ => {}
93 }
94 }
95 None
96}
97
98/// Check if the `new` keyword (followed by whitespace) appears immediately
99/// before the identifier starting at position `ident_start`.

Callers 1

extract_arrow_subjectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected