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

Function extract_string_literal_value

src/parser/mod.rs:596–613  ·  view source on GitHub ↗

Extract the string value from a literal string expression by reading the source text between the expression's span and stripping quotes.

(
    expr: &expression::Expression<'_>,
    content: &str,
)

Source from the content-addressed store, hash-verified

594/// Extract the string value from a literal string expression by reading
595/// the source text between the expression's span and stripping quotes.
596fn extract_string_literal_value(
597 expr: &expression::Expression<'_>,
598 content: &str,
599) -> Option<String> {
600 let span = expr.span();
601 let start = span.start.offset as usize;
602 let end = span.end.offset as usize;
603 let raw = content.get(start..end)?;
604 // Strip surrounding quotes (single or double).
605 let trimmed = raw.trim();
606 if (trimmed.starts_with('\'') && trimmed.ends_with('\''))
607 || (trimmed.starts_with('"') && trimmed.ends_with('"'))
608 {
609 Some(trimmed[1..trimmed.len() - 1].to_string())
610 } else {
611 Some(trimmed.to_string())
612 }
613}
614
615// ─── Thread-local parse cache ───────────────────────────────────────────────
616//

Callers 4

Calls 1

getMethod · 0.45

Tested by

no test coverage detected