aboutsummaryrefslogtreecommitdiff
path: root/lib/bytes/bytes.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-06-04 00:35:27 +0700
committerShulhan <ms@kilabit.info>2023-06-04 01:01:01 +0700
commitf31dc2563c9d264a81ae3dd74f6c6a6a3db629c8 (patch)
tree81bbb86f46ace5dbd371934dbed007dee9b877c9 /lib/bytes/bytes.go
parenta9198587b02ee060d8cacbe9d5ff19c5c1532a89 (diff)
downloadpakakeh.go-f31dc2563c9d264a81ae3dd74f6c6a6a3db629c8.tar.xz
lib/bytes: add function RemoveSpaces
Unlike TrimSpaces, which only remove spaces on beginning and end, RemoveSpaces remove all spaces including in between characters.
Diffstat (limited to 'lib/bytes/bytes.go')
-rw-r--r--lib/bytes/bytes.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/bytes/bytes.go b/lib/bytes/bytes.go
index 28a35fa1..fc000da8 100644
--- a/lib/bytes/bytes.go
+++ b/lib/bytes/bytes.go
@@ -13,6 +13,7 @@ import (
"unicode"
inbytes "github.com/shuLhan/share/internal/bytes"
+ "github.com/shuLhan/share/lib/ascii"
)
// AppendInt16 append an int16 value into slice of byte.
@@ -510,6 +511,19 @@ func ReadUint32(data []byte, x uint) (v uint32) {
return v
}
+// RemoveSpaces remove all spaces from input in.
+func RemoveSpaces(in []byte) (out []byte) {
+ var c byte
+ out = make([]byte, 0, len(in))
+ for _, c = range in {
+ if ascii.IsSpace(c) {
+ continue
+ }
+ out = append(out, c)
+ }
+ return out
+}
+
// SkipAfterToken skip all bytes until matched "token" is found and return the
// index after the token and boolean true.
//