mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* fix(deps): update module github.com/olekukonko/tablewriter to v1 | datasource | package | from | to | | ---------- | --------------------------------- | ------ | ------ | | go | github.com/olekukonko/tablewriter | v0.0.5 | v1.1.2 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> * Fixed compilation errors due to breaking changes --------- Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: Oleg Kozliuk <[email protected]>
stringish
A small Go module that provides a generic type constraint for “string-like” data, and a utf8 package that works with both strings and byte slices without conversions.
type Interface interface {
~[]byte | ~string
}
Install
go get github.com/clipperhouse/stringish
Examples
import (
"github.com/clipperhouse/stringish"
"github.com/clipperhouse/stringish/utf8"
)
s := "Hello, 世界"
r, size := utf8.DecodeRune(s) // not DecodeRuneInString 🎉
b := []byte("Hello, 世界")
r, size = utf8.DecodeRune(b) // same API!
func MyFoo[T stringish.Interface](s T) T {
// pass a string or a []byte
// iterate, slice, transform, whatever
}
Motivation
Sometimes we want APIs to accept string or []byte without having to convert
between those types. That conversion usually allocates!
By implementing with stringish.Interface, we can have a single API, and
single implementation for both types: one Foo instead of Foo and
FooString.
We have converted the
unicode/utf8 package
as an example -- note the absence of*InString funcs. We might look at x/text
next.
Used by
-
clipperhouse/uax29: stringish trie, stringish iterator, stringish SplitFunc