xstrings
A zero-dependency Go package that ports common string functions from Python, Ruby, PHP, and Perl into idiomatic, UTF-8-safe Go.
Repository Health
Technical Analysis
xstrings is a small, dependency-free Go library that implements string functions long available in Python, Ruby, PHP, and Perl but missing from Go’s standard strings package — case conversion, word splitting, UTF-8-safe slicing, and Ruby-style string successor logic. Every function operates directly on UTF-8 encoded strings and is built to drop into existing Go code without pulling in any third-party dependencies.
The README maintains an explicit cross-reference table mapping each xstrings function (and each function already in the standard strings package) to its equivalent in other languages, which makes the library especially useful for developers coming to Go from a dynamic-language background who know the operation they want but not its Go name.
What You Get
- Case conversion between camelCase, PascalCase, snake_case, and kebab-case, correctly handling acronym runs like
HTTPServer - Rune-aware string operations (
Slice,Insert,Reverse,Len,Width) that avoid the byte-offset bugs plain string slicing can cause on multi-byte UTF-8 text - A README cross-reference table mapping every function to its equivalent in Python, Ruby, PHP, and Perl
- Zero runtime dependencies — the entire library is built on the Go standard library alone
- A test file paired with nearly every source file, exercised via a GitHub Actions workflow that reports coverage to Coveralls
Common Use Cases
- Porting string-processing scripts from Python or Ruby to Go and needing the equivalent of
str.partitionorString#succ - Converting between naming conventions (JSON snake_case, Go PascalCase, CLI kebab-case) in code generators or config loaders
- Scrubbing invalid UTF-8 out of untrusted input before storage or transmission
- Rendering fixed-width, rune-aware padded or centered text in CLI output or reports
Under The Hood
Architecture
xstrings is a single flat Go package with no internal subdirectories: functionality is split across a handful of source files by concern (convert.go for case conversion, manipulate.go for slicing/partitioning/scrubbing, translate.go for character translation, count.go and format.go for counting and width-aware formatting), plus common.go holding a shared allocBuffer helper that lazily sizes an internal string-builder to avoid repeated small allocations. A pair of build-tag-gated files (stringbuilder.go and stringbuilder_go110.go) abstract over the standard library’s strings.Builder, letting the package build on Go versions predating its introduction. Because every function is a pure transformation over an input string, there is no dependency injection or shared mutable state; if the shared buffer abstraction changed, nearly every function that builds output incrementally would need to change with it.
Tech Stack
The package targets Go 1.12 (per go.mod) and depends on nothing beyond the standard library — strings, unicode, unicode/utf8, and math/rand cover every runtime need, so consumers add zero transitive dependencies by importing it. There is no separate build tool since the package is consumed via go get/module resolution rather than compiled as a binary. Continuous integration is a single GitHub Actions workflow (.github/workflows/go.yml) that installs Go 1.17, runs go test with coverage instrumentation, and uploads results to Coveralls, giving the project a visible, long-running coverage badge rather than a bespoke test harness.
Code Quality
Almost every source file has a matching _test.go counterpart (convert_test.go, count_test.go, format_test.go, manipulate_test.go, translate_test.go, util_test.go), using table-driven tests built on the standard testing package, and CI enforces these tests plus coverage reporting on every push and pull request. Error handling favors panics over returned errors for invalid input — for example Slice panics with "out of range" rather than returning an error value — which is explicitly documented in the exported functions’ godoc comments but is a less idiomatic-Go pattern than typical error-return APIs. There is no linter configuration or static-analysis step wired into CI, and naming otherwise follows conventional exported Go CamelCase throughout.
API Design
The library’s central idea is a README-level cross-reference table mapping each xstrings function, and each function already present in the standard strings package, to its equivalent in Python, Ruby, PHP, and Perl — turning “what’s the Go name for str.rpartition” into a lookup rather than a guess. Every exported function ships extensive godoc comments with inline before/after examples embedded directly in the comment text, and the package requires no configuration or setup beyond a plain import. The approach is not architecturally novel, but it is executed with unusually thorough documentation and naming discipline for a small utility library.
Used by 2 apps in this directory
Gitea
Devops · Developer Tools · Project Management
Self-hosted DevOps in a single Go binary — Git hosting, GitHub Actions-compatible CI/CD, and 30+ package registries without any SaaS dependency.
Traefik
Devops · Automation · Security
A cloud-native reverse proxy and load balancer that auto-configures itself from Docker, Kubernetes, and other orchestrators — zero manual routing required.