stringutils

package
v0.0.0-...-d637b58 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidInt = errors.New("invalid integer syntax")

Functions

func Atoi

func Atoi(s string) int

Atoi is an alias for String2Int, mimicking standard library naming. Optimization: Same as String2Int.

func ConvertSummarizedString2Int

func ConvertSummarizedString2Int(s string) int

ConvertSummarizedString2Int converts a summarized string (e.g., "1k") to an integer. Optimization: Manual parsing with minimal allocations.

func IsLetter

func IsLetter[T rune | byte](r T) bool

IsLetter checks if a rune or byte is a letter. Optimization: Simple range check with no allocations.

func Partition

func Partition(s string, sep rune) (string, string)

Partition splits a string around the first occurrence of a separator rune. Optimization: Uses strings.IndexRune for efficient search.

func RandomString

func RandomString(n int) string

RandomString generates a random string of length n. Optimization: Efficient bit manipulation for random generation.

func Reverse

func Reverse(input string) string

Reverse reverses a string in-place using unsafe operations. Optimization: Zero-copy reversal with unsafe pointer manipulation.

func S2b

func S2b(s string) []byte

S2b converts a string to a byte slice without copying. Optimization: Zero-copy using unsafe operations.

func String2Int

func String2Int(s string) int

String2Int converts a string to an integer without error checking. Optimization: Manual conversion for speed over strconv.

func String2Int64

func String2Int64(s string) int64

String2Int64 converts a string to an int64 using String2Int. Optimization: Leverages optimized String2Int.

func String2IntWithChecking

func String2IntWithChecking(s string) (int, error)

String2IntWithChecking converts a string to an integer with error checking. Optimization: Adds validation with minimal overhead.

func ToLower

func ToLower(o string) string

ToLower converts a string to lowercase. Optimization: Uses UnsafeToLower with single allocation.

func ToTitleCase

func ToTitleCase(s string) string

ToTitleCase converts a string to title case. Optimization: Single pass with minimal allocations.

func ToUpper

func ToUpper(o string) string

ToUpper converts a string to uppercase. Optimization: Uses UnsafeToUpper with single allocation.

func TrimLeft

func TrimLeft(s, cutset string) string

TrimLeft trims the left side of a string by removing repeated cutset. Optimization: Single pass with minimal slicing.

func UnsafeToLower

func UnsafeToLower(o byte) byte

UnsafeToLower converts a byte to lowercase if it’s an uppercase letter. Optimization: Inline operation with minimal branching.

func UnsafeToUpper

func UnsafeToUpper(o byte) byte

UnsafeToUpper converts a byte to uppercase if it’s a lowercase letter. Optimization: Inline operation with minimal branching.

Types

This section is empty.

Jump to

Keyboard shortcuts

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