String

package module
v0.0.0-...-9ee1e1d Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 7 Imported by: 0

README

Go String Package

The Go String package provides a wrapper around Go's built-in string type, offering a chainable API for string manipulation. This makes your string operations more fluent and intuitive.

Installation

To use the String package, first, ensure you have Go installed on your system. Then, import the package into your project:

import . "github.com/Patrick-ring-motive/String"

Types

String

The String struct is the core type of the String package, wrapping a pointer to a Go string.

Functions

S(s any) String

Initializes a new String instance from any value by converting it to a string using fmt.Sprint(s).

Methods
Contains(substr string) bool

Checks if the String contains the specified substring.

IncludesAny(substrs ...string) bool

Determines if the String includes any of the specified substrings.

Len() int

Returns the length of the String.

Replace(old string, nw string, count ...int) String

Replaces the first n occurrences of old with new. If count is not specified, defaults to 1.

ReplaceAll(oldnew ...string) String

Replaces all occurrences of old with new. Parameters are passed as a variadic list where the first element is old and the second is new.

ToLower() String

Converts all characters in the String to lowercase.

ToUpper() String

Converts all characters in the String to uppercase.

TrimSpace() String

Trims whitespace from both ends of the String.

strings and strconv

All of the methods in the strings and strconv packages from the standard library that take a string as input have been implemented following a similar pattern where the first string input parameter is pulled out given a method that takes in the remaining input parameters eg.

func doAStandardStringOperation(s string,i int)string {}
//becomes
func (s String) doAStandardStringOperation (i int) String {}

For more information on the standard string operations, see the standard documentation

Example Usage

package main

import (
  "fmt"
  . "github.com/Patrick-ring-motive/String" 
)

func main() {
  s := S(" Hello, WORLD!!! ")
  fmt.Println(s.TrimSpace().ToLower().ReplaceAll("world", "gopher").Value) // Output: "hello, gopher!!!"
}

Contributing

Contributions to the String package are welcome. Please feel free to submit issues or pull requests to the project repository.

License

The String package is licensed under the MIT License. See the LICENSE file in the project repository for more details.

Documentation

Index

Constants

View Source
const MaxInt = int(MaxUint >> 1)
View Source
const MaxUint = ^uint(0)
View Source
const MinInt = -MaxInt - 1
View Source
const MinUint = 0

Variables

This section is empty.

Functions

func OldStrings

func OldStrings(strs Strings) []string

func UnwrapStr

func UnwrapStr[STR StringTypes](s STR) string

Types

type String

type String struct {
	Value *string
}

func FormatBool

func FormatBool(b bool) String

func FormatComplex

func FormatComplex(c complex128, fmt byte, prec, bitSize int) String

func FormatFloat

func FormatFloat(f float64, fmt byte, prec, bitSize int) String

func FormatInt

func FormatInt(i int64, base int) String

func FormatUint

func FormatUint(i uint64, base int) String

func Itoa

func Itoa(i int) String

func NewString

func NewString[STR StringTypes](s STR) String

func QuoteRune

func QuoteRune(r rune) String

func QuoteRuneToASCII

func QuoteRuneToASCII(r rune) String

func QuoteRuneToGraphic

func QuoteRuneToGraphic(r rune) String

func S

func S(s any) String

func (String) AppendQuote

func (s String) AppendQuote(dst []byte) []byte

func (String) AppendQuoteToASCII

func (s String) AppendQuoteToASCII(dst []byte) []byte

func (String) AppendQuoteToGraphic

func (s String) AppendQuoteToGraphic(dst []byte) []byte

func (String) Atoi

func (s String) Atoi() (int, error)

func (String) CanBackquote

func (s String) CanBackquote() bool

func (String) Clone

func (s String) Clone() String

func (String) Compare

func (s String) Compare(b string) int

func (String) Compares

func (s String) Compares(b String) int

func (String) Contains

func (s String) Contains(substr string) bool

func (String) ContainsAny

func (s String) ContainsAny(chars string) bool

func (String) ContainsAnyOf

func (s String) ContainsAnyOf(substrs ...string) bool

func (String) ContainsFunc

func (s String) ContainsFunc(f func(rune) bool) bool

func (String) ContainsRune

func (s String) ContainsRune(r rune) bool

func (String) Count

func (s String) Count(substr ...string) int

func (String) Cut

func (s String) Cut(sep string) (before, after String, found bool)

func (String) CutPrefix

func (s String) CutPrefix(prefix string) (after String, found bool)

func (String) CutSuffix

func (s String) CutSuffix(prefix string) (before String, found bool)

func (String) Cuts

func (s String) Cuts(sep string) [3]String

func (String) CutsPrefix

func (s String) CutsPrefix(prefix string) (after String)

func (String) CutsSuffix

func (s String) CutsSuffix(prefix string) (before String)

func (String) EqualFold

func (s String) EqualFold(t string) bool

func (String) Fields

func (s String) Fields() Strings

func (String) FieldsFunc

func (s String) FieldsFunc(f func(rune) bool) Strings

func (String) HasPrefix

func (s String) HasPrefix(prefix string) bool

func (String) HasSuffix

func (s String) HasSuffix(suffix string) bool

func (String) HeaderKey

func (s String) HeaderKey() String

func (String) IncludesAny

func (s String) IncludesAny(substrs ...string) bool

func (String) Index

func (s String) Index(substr string) int

func (String) IndexAny

func (s String) IndexAny(chars string) int

func (String) IndexAnyOf

func (s String) IndexAnyOf(substrs ...string) int

func (String) IndexByte

func (s String) IndexByte(c byte) int

func (String) IndexFunc

func (s String) IndexFunc(f func(rune) bool) int

func (String) IndexRune

func (s String) IndexRune(r rune) int

func (String) LastIndex

func (s String) LastIndex(substr string) int

func (String) LastIndexAny

func (s String) LastIndexAny(chars string) int

func (String) LastIndexAnyOf

func (s String) LastIndexAnyOf(substrs ...string) int

func (String) LastIndexByte

func (s String) LastIndexByte(c byte) int

func (String) LastIndexFunc

func (s String) LastIndexFunc(f func(rune) bool) int

func (String) Len

func (s String) Len() int

func (String) Map

func (s String) Map(mapping func(rune) rune) String

func (String) NewReader

func (s String) NewReader() *strings.Reader

func (String) ParseComplex

func (s String) ParseComplex(bitSize int) (complex128, error)

func (String) ParseComplexes

func (s String) ParseComplexes(bitSize int) complex128

func (String) ParseFloat

func (s String) ParseFloat(bitSize int) (float64, error)

func (String) ParseFloats

func (s String) ParseFloats(bitSize int) float64

func (String) ParseInt

func (s String) ParseInt(base int, bitSize int) (int64, error)

func (String) ParseInts

func (s String) ParseInts(base int, bitSize int) int64

func (String) ParseUint

func (s String) ParseUint(base int, bitSize int) (uint64, error)

func (String) ParseUints

func (s String) ParseUints(base int, bitSize int) uint64

func (String) Quote

func (s String) Quote() String

func (String) QuoteToASCII

func (s String) QuoteToASCII() String

func (String) QuoteToGraphic

func (s String) QuoteToGraphic() String

func (String) QuotedPrefix

func (s String) QuotedPrefix() (String, error)

func (String) QuotedPrefixes

func (s String) QuotedPrefixes() String

func (String) Repeat

func (s String) Repeat(count int) String

func (String) Replace

func (s String) Replace(old string, nw string, count ...int) String

func (String) ReplaceAll

func (s String) ReplaceAll(oldnew ...string) String

func (String) Replacer

func (s String) Replacer(r *strings.Replacer) String

func (String) Reset

func (s String) Reset(r *strings.Reader)

func (String) Split

func (s String) Split(seps ...string) Strings

func (String) SplitAfter

func (s String) SplitAfter(sep string) Strings

func (String) SplitAfterN

func (s String) SplitAfterN(sep string, n ...int) Strings

func (String) SplitN

func (s String) SplitN(sep string, n ...int) Strings

func (String) String

func (s String) String() string

func (String) Title

func (s String) Title() String

func (String) ToLower

func (s String) ToLower() String

func (String) ToLowerSpecial

func (s String) ToLowerSpecial(c unicode.SpecialCase) String

func (String) ToTitle

func (s String) ToTitle() String

func (String) ToTitleSpecial

func (s String) ToTitleSpecial(c unicode.SpecialCase) String

func (String) ToUpper

func (s String) ToUpper() String

func (String) ToUpperSpecial

func (s String) ToUpperSpecial(c unicode.SpecialCase) String

func (String) ToValidUTF8

func (s String) ToValidUTF8(replacement string) String

func (String) Trim

func (s String) Trim(cutset string) String

func (String) TrimFunc

func (s String) TrimFunc(f func(rune) bool) String

func (String) TrimLeft

func (s String) TrimLeft(cutset string) String

func (String) TrimLeftFunc

func (s String) TrimLeftFunc(f func(rune) bool) String

func (String) TrimPrefix

func (s String) TrimPrefix(prefix string) String

func (String) TrimRight

func (s String) TrimRight(cutset string) String

func (String) TrimRightFunc

func (s String) TrimRightFunc(f func(rune) bool) String

func (String) TrimSpace

func (s String) TrimSpace() String

func (String) TrimSuffix

func (s String) TrimSuffix(suffix string) String

func (String) Unquote

func (s String) Unquote() (String, error)

func (String) UnquoteChar

func (s String) UnquoteChar(quote byte) (value rune, multibyte bool, tail String, err error)

func (String) UnquoteChars

func (s String) UnquoteChars(quote byte) String

func (String) Unquotes

func (s String) Unquotes() String

func (String) WriteBuilder

func (s String) WriteBuilder(b *strings.Builder) (int, error)

func (String) WriteReplacer

func (s String) WriteReplacer(w io.Writer, r *strings.Replacer) (n int, err error)

type StringTypes

type StringTypes interface {
	string | *string | String | *String
}

type Strings

type Strings struct {
	Value []String
}

func NewStrings

func NewStrings(ss []string) Strings

func (Strings) Join

func (strs Strings) Join(sep string) String

func (Strings) NewReplacer

func (ss Strings) NewReplacer() *strings.Replacer

Jump to

Keyboard shortcuts

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