aboutsummaryrefslogtreecommitdiff
path: root/lib/bytes/parser.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-04-09 15:52:30 +0700
committerShulhan <ms@kilabit.info>2023-04-09 19:06:01 +0700
commitaf0eb7e03872e759527e00a004df066a0b03a871 (patch)
tree2d9a5f645a3ff3b5d805498129dda7ed91f244e9 /lib/bytes/parser.go
parentd90ce9219bf3822fa78e713fdd9f6677e08dbc74 (diff)
downloadpakakeh.go-af0eb7e03872e759527e00a004df066a0b03a871.tar.xz
lib/bytes: return the number of skipped chars on Skip(Horizontal)Spaces
Diffstat (limited to 'lib/bytes/parser.go')
-rw-r--r--lib/bytes/parser.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/bytes/parser.go b/lib/bytes/parser.go
index d6c9475d..70230622 100644
--- a/lib/bytes/parser.go
+++ b/lib/bytes/parser.go
@@ -194,17 +194,18 @@ func (bp *Parser) SkipN(n int) (c byte) {
}
// SkipHorizontalSpaces skip space (" "), tab ("\t"), carriage return
-// ("\r"), and form feed ("\f") characters; and return the first non-space
-// character or 0 if it reach end-of-content.
-func (bp *Parser) SkipHorizontalSpaces() (c byte) {
+// ("\r"), and form feed ("\f") characters; and return the number of space
+// skipped and first non-space character or 0 if it reach end-of-content.
+func (bp *Parser) SkipHorizontalSpaces() (n int, c byte) {
for ; bp.x < bp.size; bp.x++ {
c = bp.content[bp.x]
if c == ' ' || c == '\t' || c == '\r' || c == '\f' {
+ n++
continue
}
- return c
+ return n, c
}
- return 0
+ return n, 0
}
// SkipLine skip all characters until new line.
@@ -222,16 +223,18 @@ func (bp *Parser) SkipLine() (c byte) {
}
// SkipSpaces skip all spaces character (' ', '\f', '\n', '\r', '\t') and
-// return the first non-space character or 0 if it reach end-of-content.
-func (bp *Parser) SkipSpaces() (c byte) {
+// return the number of spaces skipped and first non-space character or 0 if
+// it reach end-of-content.
+func (bp *Parser) SkipSpaces() (n int, c byte) {
for ; bp.x < bp.size; bp.x++ {
c = bp.content[bp.x]
if ascii.IsSpace(c) {
+ n++
continue
}
- return c
+ return n, c
}
- return 0
+ return n, 0
}
// Stop the parser, return the remaining unparsed content and its last