From 360cd7bdc721c2aa968e2f6888db1c7e36538ae2 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Wed, 22 Jan 2025 21:33:10 +0700 Subject: 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. --- lib/bytes/parser.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lib/bytes/parser.go') 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 . 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 +// +// 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 -- cgit v1.3-6-g1900