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

Function strip_trailing_modifiers

src/util.rs:492–527  ·  view source on GitHub ↗

Strip trailing PHP visibility/modifier keywords from a string. Given a string like `" /** ... */\n public static"`, returns `" /** ... */"` (after stripping `static` and `public`). Recognised modifiers: `public`, `protected`, `private`, `static`, `abstract`, `final`, `readonly`.

(s: &str)

Source from the content-addressed store, hash-verified

490/// Recognised modifiers: `public`, `protected`, `private`, `static`,
491/// `abstract`, `final`, `readonly`.
492pub(crate) fn strip_trailing_modifiers(s: &str) -> &str {
493 const MODIFIERS: &[&str] = &[
494 "public",
495 "protected",
496 "private",
497 "static",
498 "abstract",
499 "final",
500 "readonly",
501 ];
502
503 let mut result = s;
504 loop {
505 let trimmed = result.trim_end();
506 let mut found = false;
507 for &kw in MODIFIERS {
508 if let Some(prefix) = trimmed.strip_suffix(kw) {
509 // Make sure the keyword isn't part of a larger identifier.
510 if prefix.is_empty()
511 || prefix
512 .as_bytes()
513 .last()
514 .is_some_and(|&b| !b.is_ascii_alphanumeric() && b != b'_')
515 {
516 result = prefix;
517 found = true;
518 break;
519 }
520 }
521 }
522 if !found {
523 break;
524 }
525 }
526 result.trim_end()
527}
528
529/// Find the first `;` in `s` that is not nested inside `()`, `[]`,
530/// `{}`, or string literals.

Callers 3

enclosing_docblock_textFunction · 0.85
find_enclosing_docblockFunction · 0.85

Calls 2

lastMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected