From 2cc46af7c85f68b78f5f047654b0e5edb500a807 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Mon, 23 Oct 2023 20:52:00 +0800 Subject: [PATCH] fix: Skip validation in Is*Symbol methods --- bindings/go/scip/symbol.go | 17 ++++++++--------- bindings/rust/src/symbol.rs | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/bindings/go/scip/symbol.go b/bindings/go/scip/symbol.go index 9cf63ba9..dd345dac 100644 --- a/bindings/go/scip/symbol.go +++ b/bindings/go/scip/symbol.go @@ -12,7 +12,14 @@ import ( // // CAUTION: Does not perform full validation of the symbol string's contents. func IsGlobalSymbol(symbol string) bool { - return !strings.HasPrefix(symbol, "local ") + return !IsLocalSymbol(symbol) +} + +// IsLocalSymbol returns true if the symbol is obviously not a global symbol. +// +// CAUTION: Does not perform full validation of the symbol string's contents. +func IsLocalSymbol(symbol string) bool { + return strings.HasPrefix(symbol, "local ") } func isSimpleIdentifier(s string) bool { @@ -26,14 +33,6 @@ func isSimpleIdentifier(s string) bool { return true } -func IsLocalSymbol(symbol string) bool { - if !strings.HasPrefix(symbol, "local ") { - return false - } - suffix := symbol[6:] - return len(suffix) > 0 && isSimpleIdentifier(suffix) -} - func tryParseLocalSymbol(symbol string) (string, error) { if !strings.HasPrefix(symbol, "local ") { return "", nil diff --git a/bindings/rust/src/symbol.rs b/bindings/rust/src/symbol.rs index 229beb44..1174816d 100644 --- a/bindings/rust/src/symbol.rs +++ b/bindings/rust/src/symbol.rs @@ -19,19 +19,18 @@ pub enum SymbolError { /// /// CAUTION: Does not perform full validation of the symbol string's contents. pub fn is_global_symbol(sym: &str) -> bool { - !sym.starts_with("local ") + !is_local_symbol(sym) } -pub fn is_simple_identifier(sym: &str) -> bool { - sym.chars().all(|c| c.is_alphanumeric() || c == '$' || c == '+' || c == '-' || c == '_') +/// Returns true if the symbol is obviously not a global symbol. +/// +/// CAUTION: Does not perform full validation of the symbol string's contents. +pub fn is_local_symbol(sym: &str) -> bool { + sym.starts_with("local ") } -pub fn is_local_symbol(sym: &str) -> bool { - if !sym.starts_with("local ") { - return false; - } - let suffix = &sym[6..]; - !suffix.is_empty() && is_simple_identifier(suffix) +pub fn is_simple_identifier(sym: &str) -> bool { + sym.chars().all(|c| c.is_alphanumeric() || c == '$' || c == '+' || c == '-' || c == '_') } pub fn try_parse_local_symbol(sym: &str) -> Result, SymbolError> {