strutil

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: BSD-3-Clause Imports: 13 Imported by: 3

Documentation

Overview

Package strutil contain string conversion utility collection.

Index

Constants

This section is empty.

Variables

View Source
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

func B2S(b []byte) string

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

func BytesPad(input []byte, padLength int, padData []byte, rightPad bool) (output []byte)

BytesPad method pads the input byte array with the padData byte array until the resulting string reaches the given length

func BytesPadSingle

func BytesPadSingle(input []byte, padLength int, pad byte, rightPad bool) (output []byte)

BytesPad method pads the input byte array with a single byte until the resulting string reaches the given length

func BytesUnPadSingle

func BytesUnPadSingle(input []byte, pad byte, rightPad bool, copyData bool) (output []byte)

BytesUnPadSingle method removes a given pad character from both ends.

func CamelToUnderscore

func CamelToUnderscore(s string) string

CamelToUnderscore method converts a naming convention from CamelCase to under_score.

func FileSize

func FileSize(s uint64) string

FileSize calculates the file size and generate user-friendly string.

func FileSizeIEC

func FileSizeIEC(s uint64) string

FileSize calculates the file size and generate user-friendly string.

func FillByte

func FillByte(dst []byte, pattern byte)

FillByte fills the destination byte array with a single byte.

func FillBytes

func FillBytes(dst []byte, pattern []byte)

FillBytes fill the destination byte array with the given pattern.

func FormatIntToBytes

func FormatIntToBytes(number int) (out []byte)

FormatIntToBytes is a function that converts number to decimal byte array(ASCII code based,MSB).

func FormatIntToBytesReversed

func FormatIntToBytesReversed(number int) (out []byte)

FormatIntToBytesReversed is a function that converts number to decimal byte array(ASCII code based) reversed order(LSB).

func FormatIntToString

func FormatIntToString(number int) (out string)

FormatIntToString is a function that converts number to decimal string(MSB).

func FormatIntToStringReversed

func FormatIntToStringReversed(number int) (out string)

FormatIntToStringReversed is a function that converts number to decimal string reversed order(LSB).

func FormatUnsignedIntToBytes

func FormatUnsignedIntToBytes(sign bool, number uint) (out []byte)

FormatUnsignedIntToBytes is a function that converts number to decimal byte array(ASCII code based, MSB).

func FormatUnsignedIntToBytesReversed

func FormatUnsignedIntToBytesReversed(sign bool, number uint) (out []byte)

FormatUnsignedIntToBytesReversed is a function that converts number to decimal byte array(ASCII code based) reversed order(LSB).

func FormatUnsignedIntToString

func FormatUnsignedIntToString(sign bool, number uint) (out string)

FormatUnsignedIntToString is a function that converts number to decimal string(MSB).

func FormatUnsignedIntToStringReversed

func FormatUnsignedIntToStringReversed(sign bool, number uint) (out string)

FormatUnsignedIntToStringReversed is a function that converts number to decimal string reversed order(LSB).

func MaskText

func MaskText(src string) (val string)

MaskText is a masking function for hide sensitive data.

func ParseBytesToInt

func ParseBytesToInt(in []byte) (number int)

ParseBytesToInt is a function that converts a decimal byte array(ASCII based) to integer.

func ParseStringToInt

func ParseStringToInt(in string) (number int)

ParseStringToInt is a function that converts a decimal string to integer.

func PasswordCheck

func PasswordCheck(source []byte, minLength int, condition ...*regexp.Regexp) (invalid bool)

PasswordCheck checks a password candidate with minimum length and regexp conditions.

func RandomDigits

func RandomDigits(digitLength, limit int) string

RandomDigits returns authenticate code with given length.

func Reverse

func Reverse(s string) string

Reverse is a function that returns a string in reverse order.

func StrPad

func StrPad(input string, padLength int, padString string, rightPad bool) (output string)

StrPad method pads the input string with the padString until the resulting string reaches the given length

func StrPadSingle

func StrPadSingle(input string, padLength int, pad byte, rightPad bool) (output string)

StrPadSingle method pads the input string with a single character until the resulting string reaches the given length

Types

type LineBreaker

type LineBreaker struct {
	// Out os
	Out io.Writer
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

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