Repository navigation
stringy v1.0.0 - Initial Release
Unicode string encoding handling for Go. Provides helpers for working with UTF-8, UTF-16, and UTF-32 string representations, including code unit and code point counting.
Features
- UTF-16 Support:
Utf16type with proper surrogate pair handling - UTF-32 Support:
Utf32type for Unicode code point manipulation - UTF-8 Support:
Utf8wrapper with enhanced functionality - Unified Interface: All types implement the
Stringinterface withCodeUnits()andCodePoints()methods - io.Writer Support: UTF-16 and UTF-32 types implement
io.Writerandio.StringWriter - Correct Code Point Counting: Handles characters outside the Basic Multilingual Plane (BMP)
Why This Library?
Prior to Go 1.23, there was no built-in way to count UTF-16 code units in a string. This is important for interoperability with systems and protocols (such as JavaScript, Windows APIs, and some network protocols) that use UTF-16 as their string encoding.
Installation
go get github.com/R167/stringy@v1.0.0Quick Example
import "github.com/R167/stringy"
var s stringy.Utf16
s.WriteString("hello 𝄞 world")
fmt.Println(s.String()) // prints: hello 𝄞 world
fmt.Println(s.CodeUnits()) // prints: number of UTF-16 code units
fmt.Println(s.CodePoints()) // prints: number of Unicode code points