stringhelper

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: Apache-2.0 Imports: 5 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPrefix added in v0.12.0

func AddPrefix(text, prefix, sep string) string

AddPrefix adds the prefix to each section of the text.

func AddPrefixW added in v0.12.0

func AddPrefixW(w io.StringWriter, text, prefix, sep string) (n int, err error)

AddPrefixW is like AddPrefix, except it writes the string into the w.

func AddSuffix added in v0.12.0

func AddSuffix(text, suffix, sep string) string

AddSuffixW adds the suffix to each section of the text.

func AddSuffixW added in v0.12.0

func AddSuffixW(w io.StringWriter, text, suffix, sep string) (n int, err error)

AddSuffixW is like AddSuffix, except it writes the string into the w.

func Append

func Append[B ~byte, S1 ~string, S2 String[B]](s S1, more ...S2) S1

Append string data to typed string

func Convert

func Convert[R ~string, B ~byte, S String[B]](s S) R

Convert String to typed string by sharing underlaying data

func ForEachSection added in v0.12.0

func ForEachSection(text, sep string, fn func(section string, hasSep bool) error) (err error)

ForEachSection runs fn on each section of the text, using sep as the section separator.

func HasPrefix

func HasPrefix[B1, B2 ~byte, S1 String[B1], S2 String[B2]](s S1, prefix S2) bool

func HasSuffix

func HasSuffix[B1, B2 ~byte, S1 String[B1], S2 String[B2]](s S1, suffix S2) bool

func NoSpace added in v0.12.0

func NoSpace(text string) string

NoSpace returns a copy of text with all whitespaces removed.

func NoSpaceW added in v0.12.0

func NoSpaceW(w io.StringWriter, text string) (n int, err error)

NoSpaceW is like NoSpace, but writes the string to w.

func RemoveFunc added in v0.12.0

func RemoveFunc(text string, match func(r rune) bool) string

RemoveFunc returns a copy of text with all matched runes removed.

func RemoveFuncW added in v0.12.0

func RemoveFuncW(w io.StringWriter, text string, match func(r rune) bool) (n int, err error)

RemoveFuncW is like RemoveFunc, but writes the string to w.

NOTE: To do in-place remove, use byteshelper.RemoveFunc.

func RemoveIndent added in v0.12.0

func RemoveIndent(text, sep string) string

RemoveIndent drops all leading empty sections, and detects the indentation level from the first non-empty section.

func RemoveIndentW added in v0.12.0

func RemoveIndentW(w io.StringWriter, text, sep string) (n int, err error)

func RemovePrefix added in v0.12.0

func RemovePrefix(text, prefix, sep string) string

RemovePrefix removes the prefix from each section of the text.

func RemovePrefixW added in v0.12.0

func RemovePrefixW(w io.StringWriter, text, prefix, sep string) (n int, err error)

RemovePrefixW is like RemovePrefix, except it writes the string into the w.

func RemoveSpace added in v0.12.0

func RemoveSpace(text, sep string) string

RemoveSpace calls strings.TrimSpace on each section of the text.

func RemoveSpaceW added in v0.12.0

func RemoveSpaceW(w io.StringWriter, text, sep string) (n int, err error)

RemoveSpaceW is like RemoveSpace, except it writes the string into the w.

func RemoveSuffix added in v0.12.0

func RemoveSuffix(text, prefix, sep string) string

RemoveSuffix removes the suffix from each section of the text.

func RemoveSuffixW added in v0.12.0

func RemoveSuffixW(w io.StringWriter, text, suffix, sep string) (n int, err error)

RemoveSuffixW is like RemoveSuffix, except it writes the string into the w.

func ReplaceFunc added in v0.12.0

func ReplaceFunc(text string, match func(r rune) bool, replace func(matched string) string) string

ReplaceFunc returns a copy of the text with all matched strings replaced.

func ReplaceFuncW added in v0.12.0

func ReplaceFuncW(
	w io.StringWriter,
	text string,
	match func(r rune) bool,
	replace func(matched string) string,
) (n int, err error)

ReplaceFuncW is like ReplaceFunc, but writes the string to w.

func Reverse

func Reverse[B ~byte, S String[B]](s S) S

Reverse string s in runes

func SliceEnd

func SliceEnd[B ~byte, S String[B]](s S, i int) S

SliceEnd returns s[:i], cap = len

func SliceStart

func SliceStart[B ~byte, S String[B]](s S, i int) S

SliceStart returns s[i:], cap = len

func SliceStartEnd

func SliceStartEnd[B ~byte, S String[B]](s S, i, j int) S

SliceStartEnd returns s[i:j], cap = len

func ToBytes

func ToBytes[R, B ~byte, S String[B]](s S) []R

ToBytes converts String to typed/untyped byte slice by sharing underlaying data

func TrimPrefix

func TrimPrefix[B1, B2 ~byte, S1 String[B1], S2 String[B2]](s S1, prefix S2) S1

func TrimSuffix

func TrimSuffix[B1, B2 ~byte, S1 String[B1], S2 String[B2]](s S1, suffix S2) S1

Types

type ByteString

type ByteString String[byte]

type String

type String[T ~byte] interface {
	~string | ~[]T
}

Jump to

Keyboard shortcuts

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