From d933d6d10e7d8d7f1070b3c613e5bd6682716678 Mon Sep 17 00:00:00 2001 From: Zamicol Date: Thu, 10 Aug 2023 16:02:36 -0600 Subject: [PATCH] remove SB64 from Coze and move it to package Cyphrme/Tree --- base64.go | 24 ------------------------ base64_test.go | 21 --------------------- 2 files changed, 45 deletions(-) diff --git a/base64.go b/base64.go index cfe028e..3167ab1 100644 --- a/base64.go +++ b/base64.go @@ -53,27 +53,3 @@ func MustDecode(b64 string) B64 { } return b } - -// SB64 is useful for B64 map keys. Idiomatically, map key type should be `B64`, -// but currently in Go map keys are only type `string`, not `[]byte`. Since -// B64's underlying type is `[]byte` it cannot be used as a map key. See -// https://github.com/golang/go/issues/283 and -// https://github.com/google/go-cmp/issues/67. SB64 will be deprecated if/when -// Go supports []byte keys. -// -// This is an acceptable hack because (from https://go.dev/blog/strings) -// -// >[A] string holds arbitrary bytes. It is not required to hold Unicode text, -// > UTF-8 text, or any other predefined format. As far as the content of a -// > string is concerned, it is exactly equivalent to a slice of bytes. -type SB64 string - -// String implements fmt.Stringer -func (b SB64) String() string { - return B64(b).String() -} - -// GoString implements fmt.GoString -func (b SB64) GoString() string { - return b.String() -} diff --git a/base64_test.go b/base64_test.go index 0c48a1e..ae0edc7 100644 --- a/base64_test.go +++ b/base64_test.go @@ -131,27 +131,6 @@ func ExampleB64_non_strict_decode() { // invalid character '\r' in string literal } -// ExampleSB64 demonstrates using SB64 as a map key and that fmt prints "RFC -// 4648 base 64 URI canonical with padding truncated" properly. -func ExampleSB64() { - b := MustDecode("zVzgRU3WFpnrlVJAnI4ZU1Od4Agl5Zd4jIP79oubOW0") - b2 := MustDecode("vZIAk8rjcSIKZKokGylCtVoI3DXvFYJn4XNWzf_C_FA") - - lp := make(map[SB64]B64) - lp[SB64(b)] = B64(b2) - - fmt.Printf("%s\n", SB64(b)) - fmt.Printf("%s\n", lp) - fmt.Printf("%+v\n", lp) - fmt.Printf("%#v\n", lp) - - // Output: - // zVzgRU3WFpnrlVJAnI4ZU1Od4Agl5Zd4jIP79oubOW0 - // map[zVzgRU3WFpnrlVJAnI4ZU1Od4Agl5Zd4jIP79oubOW0:vZIAk8rjcSIKZKokGylCtVoI3DXvFYJn4XNWzf_C_FA] - // map[zVzgRU3WFpnrlVJAnI4ZU1Od4Agl5Zd4jIP79oubOW0:vZIAk8rjcSIKZKokGylCtVoI3DXvFYJn4XNWzf_C_FA] - // map[coze.SB64]coze.B64{zVzgRU3WFpnrlVJAnI4ZU1Od4Agl5Zd4jIP79oubOW0:vZIAk8rjcSIKZKokGylCtVoI3DXvFYJn4XNWzf_C_FA} -} - // FuzzCastB64ToString ensures that casting to and from B64 and string does not // cause unexpected issues (issues like replacing bytes with the unicode // replacement character).