stringutil

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountBytes

func CountBytes(s string, b byte) (count int)

CountBytes returns the number of copies of b in s.

CountBytes("aabcc", 'b')
>> 2

func CountRunes

func CountRunes(s string, r rune) (count int)

CountRunes returns the number of copies of r in s. Be warned that unicode-equivalent code points do not always compare equally.

CountRunes(`🔥aaab🔥c🔥`, '🔥')
>> 2

func Cut

func Cut(text, sep string) (left, right string, ok bool)
// alias for strings.Cut

Cut slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, "", false.

if left, right, _ := Cut("my name is", " ")); left != "my", right != "name is" {
  panic("bad cut!")
}

func Cut2

func Cut2(text, sub string) (s0, s1, s2 string, ok bool)

Cut slices s around the first two appearances of sep. The found result reports whether sep appears at least twice in s. If sep does not appear in s, cut returns "", "", false.

s0, s1, s2, _ := fmt.Println(Cut2("a__b__c__d", "__")
fmt.Printf("%s %s %s\n", s0, s1, s2)
>>  a b c__d

func Cut2Byte

func Cut2Byte(text string, sep byte) (s0, s1, s2 string, ok bool)

Cut2Byte is as Cut2, but sep is a byte, not string

func Cut2Rune

func Cut2Rune(text string, sep rune) (s0, s1, s2 string, ok bool)

Cut2Rune is as Cut2, but sep is a rune, not a string.

func CutAfter

func CutAfter(s, sub string) (left, right string, ok bool)

CutAfter splits s immediately after the first occurence of sub ok is false if sub is not present. If sep does not appear in s, CutAfter returns s, "", false.

func CutByte

func CutByte(s string, sep byte) (string, string, bool)

CutByte is as cut, but sep is a byte, not string.

func CutByteAfter

func CutByteAfter(s string, delim byte) (string, string, bool)

CutByteOnce is as CutAfter, but delim is a byte, not a string.

func CutRune

func CutRune(s string, r rune) (string, string, bool)

CutRune is as Cut, but separates on a rune, not a string.

func CutRuneAfter

func CutRuneAfter(s string, r rune) (string, string, bool)

func RunesIn

func RunesIn(s string) (runes int)

RunesIn is the total number of runes in a string.

fmt.Println(RunesIn(`🔥💧`))
>> 2

func SortedBytes

func SortedBytes(s string) []byte

SortedBytes returns the bytes of the string, sorted as u8s.

func SortedRunes

func SortedRunes(s string) []rune

SortedRunes returns the runes of the string, sorted as i32s. be warned that unicode-equivalent strings do not necessarially sort identically, due to composed & decomposed forms, unicode equivalence, etc.

Types

This section is empty.

Jump to

Keyboard shortcuts

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