diff options
| author | Shulhan <ms@kilabit.info> | 2025-01-22 21:33:10 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-01-22 21:34:16 +0700 |
| commit | 360cd7bdc721c2aa968e2f6888db1c7e36538ae2 (patch) | |
| tree | 08c6610214a4da1b54707231c235e81127deeae6 /lib/bytes/parser.go | |
| parent | cdf43c8a97f6fbe7548aa45d3ce2680bdeb70e36 (diff) | |
| download | pakakeh.go-360cd7bdc721c2aa968e2f6888db1c7e36538ae2.tar.xz | |
lib/bytes: replace Copy and Concat with standard library
Since Go 1.20, the standard bytes package have the Copy function.
Since Go 1.22, the standard slices package have the Concat function.
Diffstat (limited to 'lib/bytes/parser.go')
| -rw-r--r-- | lib/bytes/parser.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/bytes/parser.go b/lib/bytes/parser.go index d7a2055c..e5c7addb 100644 --- a/lib/bytes/parser.go +++ b/lib/bytes/parser.go @@ -1,10 +1,14 @@ -// Copyright 2023, Shulhan <ms@kilabit.info>. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2023 M. Shulhan <ms@kilabit.info> +// +// SPDX-License-Identifier: BSD-3-Clause package bytes -import "git.sr.ht/~shulhan/pakakeh.go/lib/ascii" +import ( + "bytes" + + "git.sr.ht/~shulhan/pakakeh.go/lib/ascii" +) // Parser implement tokenize parser for stream of byte using one or more // delimiters as separator between token. @@ -33,7 +37,7 @@ func (bp *Parser) AddDelimiters(delims []byte) { // Delimiters return the copy of current delimiters. func (bp *Parser) Delimiters() []byte { - return Copy(bp.delims) + return bytes.Clone(bp.delims) } // Read read a token until one of the delimiters found. @@ -136,7 +140,7 @@ out: // Remaining return the copy of un-parsed content. func (bp *Parser) Remaining() []byte { - return Copy(bp.content[bp.x:]) + return bytes.Clone(bp.content[bp.x:]) } // RemoveDelimiters remove delimiters delims from current delimiters. @@ -256,7 +260,7 @@ func (bp *Parser) SkipSpaces() (n int, c byte) { // Stop the parser, return the remaining unparsed content and its last // position, and then call Reset to reset the internal state back to zero. func (bp *Parser) Stop() (remain []byte, pos int) { - remain = Copy(bp.content[bp.x:]) + remain = bytes.Clone(bp.content[bp.x:]) pos = bp.x bp.Reset(nil, nil) return remain, pos |
