stringutils

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPrecision      = 2
	DefaultBase           = 10
	DefaultFormat         = 'f'
	DefaultNilMapFormat   = "{}"
	DefaultNilSliceFormat = "[]"
	DefaultNilFormat      = "<nil>"
)

Default options.

Variables

This section is empty.

Functions

func Capitalize added in v1.8.0

func Capitalize(str string) string

func PadLeft added in v1.3.1

func PadLeft(str string, padWith string, padTo int) string

PadLeft - Pad a string to a certain length (in bytes) with another string on the left side.

func PadRight added in v1.3.1

func PadRight(str string, padWith string, padTo int) string

PadRight - Pad a string to a certain length (in bytes) with another string on the right side.

func Stringify

func Stringify(value any, opts ...Options) string

Stringify receives an arbitrary value and converts it into a string. Stringify also accepts an options object with the following properties:

Options.NilFormat: the string format for nil values, defaults to "<nil>".
Options.NilMapFormat: the string format for nil map objects, defaults to "{}".
Options.NilSliceFormat: the string format for nil slice objects, defaults to "[]".
Options.Base: a number between 2-36 as the base when converting ints and uints to strings, defaults to Base 10.
Options.Precision: number of digits to include when converting floats and complex numbers to strings, defaults to 2.
Options.Format: the number notation format, using the stdlib ftoa functionalities, defaults to 'f':
	'b' (-ddddp±ddd, a binary exponent),
	'e' (-d.dddde±dd, a decimal exponent),
	'E' (-d.ddddE±dd, a decimal exponent),
	'f' (-ddd.dddd, no exponent),
	'g' ('e' for large exponents, 'f' otherwise),
	'G' ('E' for large exponents, 'f' otherwise),
	'x' (-0xd.ddddp±ddd, a hexadecimal fraction and binary exponent), or
	'X' (-0Xd.ddddP±ddd, a hexadecimal fraction and binary exponent).

Types

type Options

type Options struct {
	Base           int
	Format         byte
	Precision      int
	NilFormat      string
	NilMapFormat   string
	NilSliceFormat string
}

Options - stringification options.

Jump to

Keyboard shortcuts

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