MCPcopy Create free account
hub / github.com/cli/cli / scanBareDest

Function scanBareDest

internal/attachments/references.go:577–598  ·  view source on GitHub ↗

scanBareDest reads an unbracketed destination, which ends at whitespace or at the ")" closing the link. Parentheses inside the path are part of it as long as they balance.

(src []byte, i, hi int)

Source from the content-addressed store, hash-verified

575// at the ")" closing the link. Parentheses inside the path are part of it as
576// long as they balance.
577func scanBareDest(src []byte, i, hi int) int {
578 depth := 0
579 for i < hi {
580 switch c := src[i]; {
581 case c == '\\':
582 if i+1 < hi {
583 i++
584 }
585 case isSpace(c):
586 return i
587 case c == '(':
588 depth++
589 case c == ')':
590 if depth == 0 {
591 return i
592 }
593 depth--
594 }
595 i++
596 }
597 return i
598}
599
600// scanTitle skips the optional title following a destination and returns the
601// index just past it. i may point at anything: a byte that opens no title

Callers 2

inlineDestinationFunction · 0.85
linkReferenceDestinationFunction · 0.85

Calls 1

isSpaceFunction · 0.85

Tested by

no test coverage detected