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

Function scanBareDest

internal/attachments/references.go:614–635  ·  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

612// at the ")" closing the link. Parentheses inside the path are part of it as
613// long as they balance.
614func scanBareDest(src []byte, i, hi int) int {
615 depth := 0
616 for i < hi {
617 switch c := src[i]; {
618 case c == '\\':
619 if i+1 < hi {
620 i++
621 }
622 case isSpace(c):
623 return i
624 case c == '(':
625 depth++
626 case c == ')':
627 if depth == 0 {
628 return i
629 }
630 depth--
631 }
632 i++
633 }
634 return i
635}
636
637// scanTitle skips the optional title following a destination and returns the
638// 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