Skip to content

v1.3.0

Choose a tag to compare

@cmilesio cmilesio released this 10 Mar 23:59
· 14 commits to main since this release

This release expands str with a small set of high-leverage additions:

  • Case-insensitive search helpers now include positional and counting APIs.
  • New character-class predicates cover common validation checks.
  • Word and affix helpers fill a few practical gaps without expanding the surface area.
  • Native-type conversions were added in a deliberately minimal form: Int, Float64, and Bool.

str aims to be intentionally simple by providing sane defaults, no aliased helpers and high-value primitives.

Search

IndexFold()

Returns the rune index of the first case-insensitive match.

v := str.Of("Go gopher GO").IndexFold("go")
println(v)
// 0

LastIndexFold()

Returns the rune index of the last case-insensitive match.

v := str.Of("Go gopher GO").LastIndexFold("go")
println(v)
// 10

CountFold()

Counts non-overlapping case-insensitive matches.

v := str.Of("GoGOgophergo").CountFold("go")
println(v)
// 4

Checks

IsAlpha()

Reports whether a string consists only of Unicode letters.

v := str.Of("Gopher").IsAlpha()
println(v)
// true

IsAlnum()

Reports whether a string consists only of Unicode letters or numbers.

v := str.Of("Gopher2025").IsAlnum()
println(v)
// true

IsNumeric()

Reports whether a string consists only of Unicode numbers.

v := str.Of("12345").IsNumeric()
println(v)
// true

Words

Initials()

Extracts the uppercase first rune of each detected word.

v := str.Of("portableNetwork graphics").Initials().String()
println(v)
// PNG

Substrings

BeforeFold()

Returns the substring before the first case-insensitive separator match.

v := str.Of("GoPHER::go").BeforeFold("::GO").String()
println(v)
// GoPHER

AfterFold()

Returns the substring after the first case-insensitive separator match.

v := str.Of("gopher::GO-team").AfterFold("::go").String()
println(v)
// -team

BeforeLastFold()

Returns the substring before the last case-insensitive separator match.

v := str.Of("pkg/Path/FILE.txt").BeforeLastFold("/path/").String()
println(v)
// pkg

AfterLastFold()

Returns the substring after the last case-insensitive separator match.

v := str.Of("pkg/Path/FILE.txt").AfterLastFold("/path/").String()
println(v)
// FILE.txt

CommonPrefix()

Returns the longest shared prefix across the receiver and the provided strings.

v := str.Of("gopher").CommonPrefix("go", "gold").String()
println(v)
// go

CommonSuffix()

Returns the longest shared suffix across the receiver and the provided strings.

v := str.Of("main_test.go").CommonSuffix("user_test.go", "api_test.go").String()
println(v)
// _test.go

Affixes

HasSurrounding()

Reports whether a string starts and ends with the expected delimiters.

v := str.Of(`"GoForj"`).HasSurrounding(`"`, "")
println(v)
// true

Conversion

Int()

Parses the string as a base-10 int using strict strconv.Atoi semantics.

v, err := str.Of("42").Int()
println(v, err == nil)
// 42 true

Float64()

Parses the string as a float64 using strict strconv.ParseFloat semantics.

v, err := str.Of("3.14").Float64()
println(v, err == nil)
// 3.14 true

Bool()

Parses the string as a bool using strict strconv.ParseBool semantics.

v, err := str.Of("true").Bool()
println(v, err == nil)
// true true

Full Changelog: v1.2.0...v1.3.0