MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / isValidDirective

Function isValidDirective

opensca/sca/java/xml/marshal.go:267–303  ·  view source on GitHub ↗

isValidDirective reports whether dir is a valid directive text, meaning angle brackets are matched, ignoring comments and strings.

(dir Directive)

Source from the content-addressed store, hash-verified

265// isValidDirective reports whether dir is a valid directive text,
266// meaning angle brackets are matched, ignoring comments and strings.
267func isValidDirective(dir Directive) bool {
268 var (
269 depth int
270 inquote uint8
271 incomment bool
272 )
273 for i, c := range dir {
274 switch {
275 case incomment:
276 if c == '>' {
277 if n := 1 + i - len(endComment); n >= 0 && bytes.Equal(dir[n:i+1], endComment) {
278 incomment = false
279 }
280 }
281 // Just ignore anything in comment
282 case inquote != 0:
283 if c == inquote {
284 inquote = 0
285 }
286 // Just ignore anything within quotes
287 case c == '\'' || c == '"':
288 inquote = c
289 case c == '<':
290 if i+len(begComment) < len(dir) && bytes.Equal(dir[i:i+len(begComment)], begComment) {
291 incomment = true
292 } else {
293 depth++
294 }
295 case c == '>':
296 if depth == 0 {
297 return false
298 }
299 depth--
300 }
301 }
302 return depth == 0 && inquote == 0 && !incomment
303}
304
305// Flush flushes any buffered XML to the underlying writer.
306// See the EncodeToken documentation for details about when it is necessary.

Callers 1

EncodeTokenMethod · 0.85

Calls 1

EqualMethod · 0.80

Tested by

no test coverage detected