internal/ucd: added CommentHandler option This is used parsing the idna table, which categorizes tests in the comments. Change-Id: I95ea73a6f9de1e15bf680f4538e03ab3c74954b2 Reviewed-on: https://go-review.googlesource.com/30551 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/internal/ucd/ucd.go b/internal/ucd/ucd.go index 2b0d1a1..60b27d5 100644 --- a/internal/ucd/ucd.go +++ b/internal/ucd/ucd.go
@@ -78,6 +78,14 @@ } } +// The CommentHandler option passes comments that are on a line by itself to +// a given handler. +func CommentHandler(f func(s string)) Option { + return func(p *Parser) { + p.commentHandler = f + } +} + // A Parser parses Unicode Character Database (UCD) files. type Parser struct { scanner *bufio.Scanner @@ -92,7 +100,8 @@ parsedRange bool rangeStart, rangeEnd rune - partHandler func(p *Parser) + partHandler func(p *Parser) + commentHandler func(s string) } func (p *Parser) setError(err error) { @@ -138,7 +147,13 @@ for p.scanner.Scan() { b := p.scanner.Bytes() - if len(b) == 0 || b[0] == '#' { + if len(b) == 0 { + continue + } + if b[0] == '#' { + if p.commentHandler != nil { + p.commentHandler(strings.TrimSpace(string(b[1:]))) + } continue }