Skip to content

Commit ba13cfe

Browse files
committed
chore: consolidate function with Regex
1 parent e62338d commit ba13cfe

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

internal/docgen/mintlify.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,13 @@ func backtickFlags(s string) string {
189189
return strings.Join(parts, "```")
190190
}
191191

192+
// nonBoundaryByte matches a single byte that cannot precede a CLI flag:
193+
// a word char (\w), backtick, slash, or dash.
194+
var nonBoundaryByte = regexp.MustCompile("[`/\\w-]")
195+
196+
// isFlagBoundaryChar reports whether c is a valid character before a flag.
192197
func isFlagBoundaryChar(c byte) bool {
193-
// A flag must be preceded by start-of-string or a character that is not
194-
// a word char, slash, dash, or backtick.
195-
if c == '/' || c == '-' || c == '`' {
196-
return false
197-
}
198-
if c == '_' {
199-
return false
200-
}
201-
if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') {
202-
return false
203-
}
204-
return true
198+
return !nonBoundaryByte.Match([]byte{c})
205199
}
206200

207201
func backtickFlagsFragment(s string) string {

0 commit comments

Comments
 (0)