stringish

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2025 License: MIT Imports: 0 Imported by: 1

README

stringish

A tiny 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.

Install

go get github.com/clipperhouse/stringish/utf8
import (
    "github.com/clipperhouse/stringish/utf8"
)

Examples

String:

s := "Hello, 世界"
r, size := utf8.DecodeRune(s)   // not DecodeRuneInString 🎉

b := []byte("Hello, 世界")
r, size = utf8.DecodeRune(b)    // same API!

Motivation

Sometimes we want APIs to accept string or []byte without having to convert between them. That conversion usually allocates! By implementing with stringish.Interface, we can have a single API for both types, i.e. one Foo func instead of Foo and FooString.

We have converted unicode/utf8 as an example, note the absence of *InString funcs. Others soon, perhaps from x/text.

Packages

  • github.com/clipperhouse/stringish: the Interface type constraint.
  • github.com/clipperhouse/stringish/utf8: UTF-8 helpers parameterized over string or []byte.

Used in

clipperhouse/uax29 clipperhouse/displaywidth

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	~[]byte | ~string
}

Directories

Path Synopsis
Package utf8 implements functions and constants to support text encoded in UTF-8.
Package utf8 implements functions and constants to support text encoded in UTF-8.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL