From 3c849a75ca157d79d90f23e88221c30b09d59a65 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Wed, 5 Apr 2023 00:16:25 +0700 Subject: lib/bytes: add function TrimNull The TrimNull function remove 0 value ("\0" or NULL in C) at leading and trailing of input. --- lib/bytes/bytes_example_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/bytes/bytes_example_test.go') diff --git a/lib/bytes/bytes_example_test.go b/lib/bytes/bytes_example_test.go index 1b68fd42..3d6a11b5 100644 --- a/lib/bytes/bytes_example_test.go +++ b/lib/bytes/bytes_example_test.go @@ -386,6 +386,14 @@ func ExampleTokenFind() { // 64 } +func ExampleTrimNull() { + var in = []byte{0, 'H', 'e', 'l', 'l', 'o', 0, 0} + + in = TrimNull(in) + fmt.Printf(`%s`, in) + // Output: Hello +} + func ExampleWordIndexes() { text := []byte("moo moomoo moo") -- cgit v1.3-6-g1900