diff options
| author | Shulhan <m.shulhan@gmail.com> | 2020-07-24 11:31:49 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2020-07-24 11:31:49 +0700 |
| commit | f5ff593ad8d9cecb7dcad13d7c746730c6c535fa (patch) | |
| tree | b4e4639b2a8dfb180879e021f2d9ec1e00227331 /lib/parser/parser.go | |
| parent | 0a092376f929587ed18e205a876e0a3926c2d5f2 (diff) | |
| download | pakakeh.go-f5ff593ad8d9cecb7dcad13d7c746730c6c535fa.tar.xz | |
parser: add method to get single line
Diffstat (limited to 'lib/parser/parser.go')
| -rw-r--r-- | lib/parser/parser.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/parser/parser.go b/lib/parser/parser.go index 5cd08ca4..b9f4622d 100644 --- a/lib/parser/parser.go +++ b/lib/parser/parser.go @@ -159,6 +159,26 @@ func (p *Parser) Load(content, delims string) { } // +// Line read and return a single line. +// On success it will return a string without '\n' and new line character. +// In case of EOF it will return the last line and 0. +// +func (p *Parser) Line() (string, rune) { + p.d = 0 + p.token = p.token[:0] + + for x, r := range p.v[p.x:] { + if r == '\n' { + p.d = r + p.x += x + 1 + return string(p.token), p.d + } + p.token = append(p.token, r) + } + return string(p.token), 0 +} + +// // Token read the next token from content until one of the delimiter found. // if no delimiter found, its mean all of content has been read, the returned // delimiter will be 0. |
