MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / ValidateBytes

Function ValidateBytes

pkg/sql/parser/validate.go:39–66  ·  view source on GitHub ↗

ValidateBytes is like Validate but accepts []byte to avoid a string copy.

(input []byte)

Source from the content-addressed store, hash-verified

37
38// ValidateBytes is like Validate but accepts []byte to avoid a string copy.
39func ValidateBytes(input []byte) error {
40 // Fast path: empty/whitespace-only input is valid
41 if len(trimBytes(input)) == 0 {
42 return nil
43 }
44
45 tkz := tokenizer.GetTokenizer()
46 defer tokenizer.PutTokenizer(tkz)
47
48 tokens, err := tkz.Tokenize(input)
49 if err != nil {
50 return fmt.Errorf("tokenization error: %w", err)
51 }
52
53 if len(tokens) == 0 {
54 return nil
55 }
56
57 p := GetParser()
58 defer PutParser(p)
59
60 astResult, parseErr := p.ParseFromModelTokens(tokens)
61 if parseErr != nil {
62 return parseErr
63 }
64 ast.ReleaseAST(astResult)
65 return nil
66}
67
68// trimBytes returns input with leading/trailing whitespace removed.
69func trimBytes(b []byte) []byte {

Callers 4

TestValidateBytesFunction · 0.92
ValidateFunction · 0.92
validateFileWithTimeoutFunction · 0.92
ValidateFunction · 0.85

Calls 9

GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
ReleaseASTFunction · 0.92
trimBytesFunction · 0.85
GetParserFunction · 0.85
PutParserFunction · 0.85
TokenizeMethod · 0.80
ParseFromModelTokensMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestValidateBytesFunction · 0.74