Documentation ¶
Overview ¶
Package strutil contain string conversion utility collection.
Index ¶
- Variables
- func B2S(b []byte) string
- func BytesPad(input []byte, padLength int, padData []byte, rightPad bool) (output []byte)
- func BytesPadSingle(input []byte, padLength int, pad byte, rightPad bool) (output []byte)
- func BytesUnPadSingle(input []byte, pad byte, rightPad bool, copyData bool) (output []byte)
- func CamelToUnderscore(s string) string
- func FileSize(s uint64) string
- func FileSizeIEC(s uint64) string
- func FillByte(dst []byte, pattern byte)
- func FillBytes(dst []byte, pattern []byte)
- func FormatIntToBytes(number int) (out []byte)
- func FormatIntToBytesReversed(number int) (out []byte)
- func FormatIntToString(number int) (out string)
- func FormatIntToStringReversed(number int) (out string)
- func FormatUnsignedIntToBytes(sign bool, number uint) (out []byte)
- func FormatUnsignedIntToBytesReversed(sign bool, number uint) (out []byte)
- func FormatUnsignedIntToString(sign bool, number uint) (out string)
- func FormatUnsignedIntToStringReversed(sign bool, number uint) (out string)
- func MaskText(src string) (val string)
- func ParseBytesToInt(in []byte) (number int)
- func ParseStringToInt(in string) (number int)
- func PasswordCheck(source []byte, minLength int, condition ...*regexp.Regexp) (invalid bool)
- func RandomDigits(digitLength, limit int) string
- func Reverse(s string) string
- func StrPad(input string, padLength int, padString string, rightPad bool) (output string)
- func StrPadSingle(input string, padLength int, pad byte, rightPad bool) (output string)
- type LineBreaker
Constants ¶
This section is empty.
Variables ¶
var ( // EmailRegex is the standard email address format. EmailRegex = regexp.MustCompile(`^([^<>()[\]\\.,;:\s@"]+(?:\.[^<>()[\]\\.,;:\s@"]+)*)@(?:(?:[a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,})$`) // DigitRegex represents a digit. DigitRegex = regexp.MustCompile(`\d`) )
Functions ¶
func B2S ¶
B2S converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
Note it may break if string and/or slice header will change in the future go versions.
func BytesPad ¶
BytesPad method pads the input byte array with the padData byte array until the resulting string reaches the given length
func BytesPadSingle ¶
BytesPad method pads the input byte array with a single byte until the resulting string reaches the given length
func BytesUnPadSingle ¶
BytesUnPadSingle method removes a given pad character from both ends.
func CamelToUnderscore ¶
CamelToUnderscore method converts a naming convention from CamelCase to under_score.
func FileSizeIEC ¶
FileSize calculates the file size and generate user-friendly string.
func FormatIntToBytes ¶
FormatIntToBytes is a function that converts number to decimal byte array(ASCII code based,MSB).
func FormatIntToBytesReversed ¶
FormatIntToBytesReversed is a function that converts number to decimal byte array(ASCII code based) reversed order(LSB).
func FormatIntToString ¶
FormatIntToString is a function that converts number to decimal string(MSB).
func FormatIntToStringReversed ¶
FormatIntToStringReversed is a function that converts number to decimal string reversed order(LSB).
func FormatUnsignedIntToBytes ¶
FormatUnsignedIntToBytes is a function that converts number to decimal byte array(ASCII code based, MSB).
func FormatUnsignedIntToBytesReversed ¶
FormatUnsignedIntToBytesReversed is a function that converts number to decimal byte array(ASCII code based) reversed order(LSB).
func FormatUnsignedIntToString ¶
FormatUnsignedIntToString is a function that converts number to decimal string(MSB).
func FormatUnsignedIntToStringReversed ¶
FormatUnsignedIntToStringReversed is a function that converts number to decimal string reversed order(LSB).
func ParseBytesToInt ¶
ParseBytesToInt is a function that converts a decimal byte array(ASCII based) to integer.
func ParseStringToInt ¶
ParseStringToInt is a function that converts a decimal string to integer.
func PasswordCheck ¶
PasswordCheck checks a password candidate with minimum length and regexp conditions.
func RandomDigits ¶
RandomDigits returns authenticate code with given length.
Types ¶
type LineBreaker ¶
LineBreaker is an io.Writer that advances a newline if one line exceeds 64 bytes.
func (*LineBreaker) Close ¶
func (l *LineBreaker) Close() (err error)
Close flushes any pending output from the writer. It is an error to call Write after calling Close.
func (*LineBreaker) Write ¶
func (l *LineBreaker) Write(b []byte) (n int, err error)
Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. Write must return a non-nil error if it returns n < len(p). Write must not modify the slice data, even temporarily.