paw

package module
v0.0.7-2021.1.21 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: MIT Imports: 27 Imported by: 1

README

paw

Functions

io

LineCount

LineCount counts the number of \n for reader r

func LineCount(r io.Reader) (int, error)

modify from "github.com/liuzl/goutil"

FileLineCount

FileLineCount counts the number of \n for file f

f : could be gzip file or plain text file

func FileLineCount(f string) (int, error)

modify from "github.com/liuzl/goutil"

ForEachLine

ForEachLine higher order function that processes each line of text by callback function.

The last non-empty line of input will be processed even if it has no newline.

br : read from br reader

callback : the function used to treatment the every line from br

func ForEachLine(br *bufio.Reader, callback func(string) error) error

modify from "github.com/liuzl/goutil"

path

IsFileExist

IsFileExist return true that fileName exist or false for not exist

func IsFileExist(fileName string) bool
IsDirExists

IsDirExists return true that dir is directory or false for not

func IsDirExists(dir string) bool

web

GetTitleAndURL

GetTitleAndURL get the title and URL of active tab of the current window of browser

browser : - "edge" for "Microsoft Edge" (default) : - "chrome" for "Google Chrome"

func GetTitleAndURL(browser string) (t, u string, err error)
GetTitle

GetTitle get the title of active tab of the current window of browser

func GetTitle(browser string) (string, error)
GetURL

GetURL get the URL of active tab of the current window of browser

func GetURL(browser string) (string, error)

text or string

GetAbbrString

GetAbbrString return a abbreviation string 'xxx...' of str with maximum length maxlen.

func GetAbbrString(str string, maxlen int) string
CountPlaceHolder

CountPlaceHolder return nHan and nASCII

nHan : number of occupied space in terminal for han-character

nASCII : number of occupied space in terminal for ASCII-character

func CountPlaceHolder(str string) (nHan int, nASCII int)
HasChineseChar

HasChineseChar return true for that str include chinese character

func HasChineseChar(str string) bool

Table

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Info    *log.Logger
	Warning *log.Logger
	Error   *log.Logger
)
View Source
var (
	// Log is a logger use logrus
	Log = logrus.New()
)
View Source
var (

	// Logger is logrus.Logger
	// Logger = logrus.New()
	Logger = &logrus.Logger{
		Out:          os.Stderr,
		ReportCaller: true,
		Formatter:    nestedFormatter,
		Level:        logrus.InfoLevel,
	}
)

Functions

func AppendToFile

func AppendToFile(fileName string, s string) error

AppendToFile append string `s` to file `fileName`

func Big5ToUtf8

func Big5ToUtf8(s []byte) ([]byte, error)

Big5ToUtf8 decodes Big5 to UTF8

func Big5ToUtf8String

func Big5ToUtf8String(s string) (string, error)

Big5ToUtf8String decodes Big5 to UTF8

func Contains

func Contains(str string, substr string) bool

Contains return `strings.Contains(str, substr)`

func ContainsAny

func ContainsAny(s, chars string) bool

ContainsAny reports whether any Unicode code points in `chars` are within `s`.

Encapsulates ContainsAny(s, chars string) bool

func ContainsFloat32

func ContainsFloat32(s []float32, v float32) bool

ContainsFloat32 returns true if a float32 is present in a iteratee.

func ContainsFloat64

func ContainsFloat64(s []float64, v float64) bool

ContainsFloat64 returns true if a float64 is present in a iteratee.

func ContainsInt

func ContainsInt(s []int, v int) bool

ContainsInt returns true if an int is present in a iteratee.

func ContainsInt32

func ContainsInt32(s []int32, v int32) bool

ContainsInt32 returns true if an int32 is present in a iteratee.

func ContainsInt64

func ContainsInt64(s []int64, v int64) bool

ContainsInt64 returns true if an int64 is present in a iteratee.

func ContainsRune

func ContainsRune(s string, r rune) bool

ContainsRune reports whether the Unicode code point `r` is within `s`.

Encapsulates strings.ContainsRune(s string, r rune) bool

func ContainsString

func ContainsString(s []string, v string) bool

ContainsString returns true if a string is present in a iteratee.

func ContainsUInt

func ContainsUInt(s []uint, v uint) bool

ContainsUInt returns true if an uint is present in a iteratee.

func ContainsUInt32

func ContainsUInt32(s []uint32, v uint32) bool

ContainsUInt32 returns true if an uint32 is present in a iteratee.

func ContainsUInt64

func ContainsUInt64(s []uint64, v uint64) bool

ContainsUInt64 returns true if an uint64 is present in a iteratee.

func CountPlaceHolder

func CountPlaceHolder(str string) (nHan int, nASCII int)

CountPlaceHolder return `nHan` and `nASCII`

`nHan`: number of occupied space in screen for han-character
`nASCII`: number of occupied space in screen for ASCII-character

func EqualFold

func EqualFold(s, t string) bool

EqualFold reports whether `s` and `t`, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-insensitivity.

Encapsulates strings.EqualFold(s, t string) bool

func Fields

func Fields(s string) []string

Fields splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space.

Encapsulates strings.Fields(s string) []string

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Printf("Fields are: %q", strings.Fields("  foo bar  baz   "))
}
result: Fields are: ["foo" "bar" "baz"]

func FieldsFunc

func FieldsFunc(s string, f func(rune) bool) []string

FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s. If all code points in s satisfy f(c) or the string is empty, an empty slice is returned.

FieldsFunc makes no guarantees about the order in which it calls f(c) and assumes that f always returns the same value for a given c.

Example

package main

import (
	"fmt"
	"strings"
	"unicode"
)

func main() {
	f := func(c rune) bool {
		return !unicode.IsLetter(c) && !unicode.IsNumber(c)
	}
	fmt.Printf("Fields are: %q", strings.FieldsFunc("  foo1;bar2,baz3...", f))
}
result: Fields are: ["foo1" "bar2" "baz3"]

func FileLineCount

func FileLineCount(f string) (int, error)

FileLineCount counts the number of '\n' for file f

`f` could be `gzip` file or plain text file

modify from "github.com/liuzl/goutil"

func FillLeft

func FillLeft(s string, w int) string

FillLeft return string filled in left by spaces in w cells

func FillRight

func FillRight(s string, w int) string

FillRight return string filled in left by spaces in w cells

func ForEachLine

func ForEachLine(br *bufio.Reader, callback func(string) error) error

ForEachLine higher order function that processes each line of text by callback function. The last non-empty line of input will be processed even if it has no newline.

`br` : read from `br` reader
`callback` : the function used to treatment the each line from `br`

modify from "github.com/liuzl/goutil"

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

GbkToUtf8 decodes GBK to UTF8

func GbkToUtf8String

func GbkToUtf8String(s string) (string, error)

GbkToUtf8String decodes GBK to UTF8

func GetAbbrString

func GetAbbrString(str string, maxlen int, conSymbole string) string

GetAbbrString return the abbreviation string 'xxx...' of `str`

`maxlen`: maimium length of the abbreviation
`conSymbole`: tailing symbol of the abbreviation

func GetAppDir

func GetAppDir() string

GetAppDir get the current app directory

func GetCurrPath

func GetCurrPath() string

GetCurrPath get the current path

func GetDate

func GetDate() string

GetDate get the current date and return string. For example,

if time.Now().Date() is `2020 November 27`
then GetDate() return `Nov 27, 2020`

func GetDotDir

func GetDotDir() string

GetDotDir return the absolute path of "."

func GetFuncName

func GetFuncName(level interface{}) string

GetFuncName get the func name

func GetHomeDir

func GetHomeDir() string

GetHomeDir get the home directory of user

func GetTerminalSize

func GetTerminalSize() (height, width int)

GetTerminalSize get size of console using `stty size`

func GetTitle

func GetTitle(browser string) (string, error)

GetTitle get the `title` of active tab of the current window of `browser`

func GetTitleAndURL

func GetTitleAndURL(browser string) (t, u string, err error)

GetTitleAndURL get the `title` and `UTL` of active tab of the current window of `browser`

`browser`:
   "edge" for "Microsoft Edge" (default)
   "chrome" for "Google Chrome"

func GetURL

func GetURL(browser string) (string, error)

GetURL get the `URL` of active tab of the current window of `browser`

func GologInit

func GologInit(
	infoHandle io.Writer,
	warnHandle io.Writer,
	errorHandle io.Writer,
	isVerbose bool)

GologInit initializes logger

func HasChineseChar

func HasChineseChar(str string) bool

HasChineseChar return true for that `str` include chinese character

Example:

HasChineseChar("abc 中文") return true
HasChineseChar("abccefgh") return false

func HasFile

func HasFile(filename string) bool

HasFile : Check if file exists in the current directory

func HasPrefix

func HasPrefix(str string, prefix string) bool

HasPrefix return `strings.HasPrefix(str, prefix)`

func HasSuffix

func HasSuffix(str string, suffix string) bool

HasSuffix return `strings.HasSuffix(str, Suffix)`

func Index

func Index(s, substr string) int

Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.Index("chicken", "ken")) // 4
	fmt.Println(strings.Index("chicken", "dmr")) // -1
}

func IndexAny

func IndexAny(s, chars string) int

IndexAny returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.IndexAny("chicken", "aeiouy")) 	// 2
	fmt.Println(strings.IndexAny("crwth", "aeiouy"))	// -1
}

func IndexByte

func IndexByte(s string, c byte) int

IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.IndexByte("golang", 'g'))	// 0
	fmt.Println(strings.IndexByte("gophers", 'h'))	// 3
	fmt.Println(strings.IndexByte("golang", 'x'))	// -1
}
result:

func IndexFunc

func IndexFunc(s string, f func(rune) bool) int

IndexFunc returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do.

Example

package main

import (
	"fmt"
	"strings"
	"unicode"
)

func main() {
	f := func(c rune) bool {
		return unicode.Is(unicode.Han, c)
	}
	fmt.Println(strings.IndexFunc("Hello, 世界", f))	// 7
	fmt.Println(strings.IndexFunc("Hello, world", f))	// -1
}

func IndexOf

func IndexOf(n int, f func(int) bool) int

IndexOf gets the index at which the first occurrence of an value is found in array or return -1. if the value cannot be found

func IndexOfFloat64

func IndexOfFloat64(a []float64, x float64) int

IndexOfFloat64 gets the index at which the first occurrence of an float64 value is found in array or return -1 if the value cannot be found

func IndexOfInt

func IndexOfInt(a []int, x int) int

IndexOfInt gets the index at which the first occurrence of an int value is found in array or return -1 if the value cannot be found

func IndexOfInt32

func IndexOfInt32(a []int32, x int32) int

IndexOfInt32 gets the index at which the first occurrence of an int32 value is found in array or return -1 if the value cannot be found

func IndexOfInt64

func IndexOfInt64(a []int64, x int64) int

IndexOfInt64 gets the index at which the first occurrence of an int64 value is found in array or return -1 if the value cannot be found

func IndexOfString

func IndexOfString(a []string, x string) int

IndexOfString gets the index at which the first occurrence of a string value is found in array or return -1 if the value cannot be found

func IndexOfUInt

func IndexOfUInt(a []uint, x uint) int

IndexOfUInt gets the index at which the first occurrence of an uint value is found in array or return -1 if the value cannot be found

func IndexOfUInt32

func IndexOfUInt32(a []uint32, x uint32) int

IndexOfUInt32 gets the index at which the first occurrence of an uint32 value is found in array or return -1 if the value cannot be found

func IndexOfUInt64

func IndexOfUInt64(a []uint64, x uint64) int

IndexOfUInt64 gets the index at which the first occurrence of an uint64 value is found in array or return -1 if the value cannot be found

func IndexRune

func IndexRune(s string, r rune) int

IndexRune returns the index of the first instance of the Unicode code point r, or -1 if rune is not present in s. If r is utf8.RuneError, it returns the first instance of any invalid UTF-8 byte sequence.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.IndexRune("chicken", 'k'))	// 4
	fmt.Println(strings.IndexRune("chicken", 'd'))	// -1
}

func IsDirExist

func IsDirExist(name string) bool

IsDirExist reports whether the dir exists as a boolean

func IsEqualString

func IsEqualString(a, b string, ignoreCase bool) bool

IsEqualString compares string `a` and `b`

func IsExist

func IsExist(name string) bool

IsExists reports whether the file or dir exists as a boolean

func IsFileExist

func IsFileExist(name string) bool

IsFileExist reports whether the named file exists as a boolean

func IsPathExist

func IsPathExist(path string) bool

IsPathExist return whether the path exists.

func Join

func Join(elems []string, sep string) string

Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	s := []string{"foo", "bar", "baz"}
	fmt.Println(strings.Join(s, ", ")) // foo, bar, baz
}

func LastIndex

func LastIndex(s, substr string) int

LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.Index("go gopher", "go"))			// 0
	fmt.Println(strings.LastIndex("go gopher", "go"))		// 3
	fmt.Println(strings.LastIndex("go gopher", "rodent"))	// -1
}

func LastIndexAny

func LastIndexAny(s, chars string) int

LastIndexAny returns the index of the last instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.LastIndexAny("go gopher", "go"))		// 4
	fmt.Println(strings.LastIndexAny("go gopher", "rodent"))	// 8
	fmt.Println(strings.LastIndexAny("go gopher", "fail"))		// -1
}

func LastIndexByte

func LastIndexByte(s string, c byte) int

LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.LastIndexByte("Hello, world", 'l')) // 10
	fmt.Println(strings.LastIndexByte("Hello, world", 'o')) // 8
	fmt.Println(strings.LastIndexByte("Hello, world", 'x')) // -1
}

func LastIndexFunc

func LastIndexFunc(s string, f func(rune) bool) int

LastIndexFunc returns the index into s of the last Unicode code point satisfying f(c), or -1 if none do.

Example

package main

import (
	"fmt"
	"strings"
	"unicode"
)

func main() {
	fmt.Println(strings.LastIndexFunc("go 123", unicode.IsNumber))	// 5
	fmt.Println(strings.LastIndexFunc("123 go", unicode.IsNumber))	// 2
	fmt.Println(strings.LastIndexFunc("go", unicode.IsNumber))		// -1
}

func LastIndexOf

func LastIndexOf(n int, f func(int) bool) int

LastIndexOf gets the index at which the first occurrence of an value is found in array or return -1. if the value cannot be found

func LastIndexOfFloat32

func LastIndexOfFloat32(a []float32, x float32) int

LastIndexOfFloat32 gets the index at which the first occurrence of an float32 value is found in array or return -1 if the value cannot be found

func LastIndexOfFloat64

func LastIndexOfFloat64(a []float64, x float64) int

LastIndexOfFloat64 gets the index at which the first occurrence of an float64 value is found in array or return -1 if the value cannot be found

func LastIndexOfInt

func LastIndexOfInt(a []int, x int) int

LastIndexOfInt gets the index at which the first occurrence of an int value is found in array or return -1 if the value cannot be found

func LastIndexOfInt32

func LastIndexOfInt32(a []int32, x int32) int

LastIndexOfInt32 gets the index at which the first occurrence of an int32 value is found in array or return -1 if the value cannot be found

func LastIndexOfInt64

func LastIndexOfInt64(a []int64, x int64) int

LastIndexOfInt64 gets the index at which the first occurrence of an int64 value is found in array or return -1 if the value cannot be found

func LastIndexOfString

func LastIndexOfString(a []string, x string) int

LastIndexOfString gets the index at which the first occurrence of a string value is found in array or return -1 if the value cannot be found

func LastIndexOfUInt

func LastIndexOfUInt(a []uint, x uint) int

LastIndexOfUInt gets the index at which the first occurrence of an uint value is found in array or return -1 if the value cannot be found

func LastIndexOfUInt32

func LastIndexOfUInt32(a []uint32, x uint32) int

LastIndexOfUInt32 gets the index at which the first occurrence of an uint32 value is found in array or return -1 if the value cannot be found

func LastIndexOfUInt64

func LastIndexOfUInt64(a []uint64, x uint64) int

LastIndexOfUInt64 gets the index at which the first occurrence of an uint64 value is found in array or return -1 if the value cannot be found

func LineCount

func LineCount(r io.Reader) (int, error)

LineCount counts the number of '\n' for reader `r`

func MakeAll

func MakeAll(path string) error

MakeAll check path and create like as `make -p path`

func Map

func Map(mapping func(rune) rune, s string) string

Map returns a copy of the string `s` with all its characters modified according to the `mapping` function. If `mapping` returns a negative value, the character is dropped from the string with no replacement.

Example:

rot13 := func(r rune) rune {
	switch {
	case r >= 'A' && r <= 'Z':
		return 'A' + (r-'A'+13)%26
	case r >= 'a' && r <= 'z':
		return 'a' + (r-'a'+13)%26
	}
	return r
}
fmt.Println(strings.Map(rot13, "'Twas brillig and the slithy gopher..."))
out:
'Gjnf oevyyvt naq gur fyvgul tbcure...

func Max

func Max(x interface{}) interface{}

Max return the maximum value of `x`, the type of x is one of []int, []float32, []float64, []string. If x is empty, and type is one of []int, []float32 and []float64, will return 0. If x is empty, and type is one of []string, will return "".

func MaxFloat32s

func MaxFloat32s(x ...float32) float32

MaxFloat32s will return maximum value of `x...`. If x is empty, and return 0.

func MaxFloat64s

func MaxFloat64s(x ...float64) float64

MaxFloat64s will return maximum value of `x...`. If x is empty, and return 0.

func MaxInt

func MaxInt(i, j int) int

MaxInt will return maximum value of `i` and `j`

func MaxInts

func MaxInts(x ...int) int

MaxInts will return maximum value of `x...`. If x is empty, and return 0.

func MaxStrings

func MaxStrings(x ...string) string

MaxStrings will return maximum value of `x...`. Compares iterms using code point.

func Min

func Min(x interface{}) interface{}

Min return the minimum value of `x`, the type of x is one of []int, []float32, []float64, []string. If x is empty, and type is one of []int, []float32 and []float64, will return 0. If x is empty, and type is one of []string, will return "".

func MinFloat32s

func MinFloat32s(x ...float32) float32

MinFloat32s will return minimum value of `x...`. If x is empty, and return 0.

func MinFloat64s

func MinFloat64s(x ...float64) float64

MinFloat64s will return minimum value of `x...`. If x is empty, and return 0.

func MinInt

func MinInt(i, j int) int

MinInt will return minimum value of `i` and `j`

func MinInts

func MinInts(x ...int) int

MinInts will return minimum value of `x...`. If x is empty, and return 0.

func MinStrings

func MinStrings(x ...string) string

MinStrings will return minimum value of `x...`. Compares iterms using code point If x is empty, and return "".

func NewBuffer

func NewBuffer(buf []byte) *bytes.Buffer

NewBuffer creates and initializes a new Buffer using buf as its initial contents. The new Buffer takes ownership of buf, and the caller should not use buf after this call. NewBuffer is intended to prepare a Buffer to read existing data. It can also be used to set the initial size of the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.

In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.

func NewBufioReader

func NewBufioReader(s string) *bufio.Reader

NewReader returns a new Reader whose buffer has the default size.

func NewRand

func NewRand() *rand.Rand

NewRand return a instance of

func NewStringBuilder

func NewStringBuilder() *strings.Builder

NewStringBuilder will return `*strings.Builder`

A Builder is used to efficiently build a string using Write methods. It minimizes memory copying. The zero value is ready to use. Do not copy a non-zero Builder.

func NewStringReader

func NewStringReader(s string) *strings.Reader

NewStringReader returns a new Reader reading from s. It is similar to bytes.NewBufferString but more efficient and read-only.

func NumberBanner

func NumberBanner(width int) string

NumberBanner return numbers' string with length `width`

Example:

NumberBanner(11) return "01234567890"

func PaddingBytes

func PaddingBytes(bytes []byte, pad string) []byte

PaddingBytes add pad-prefix in every line('\n') of []byte

func PaddingString

func PaddingString(s string, pad string) string

PaddingString add pad-prefix in every line of string

func RandomInt

func RandomInt(min, max int) int

RandomInt generates a random int, based on a min and max values

func RandomString

func RandomString(n int, allowedChars ...[]rune) string

RandomString returns a random string with a fixed length

func Repeat

func Repeat(s string, count int) string

Repeat returns a new string consisting of count copies of the string `s`.

It panics if `count` is negative or if the result of (`len(s) * count`) overflows.

Example:

fmt.Println("ba" + strings.Repeat("na", 2))
out: banana

func Replace

func Replace(s, old, new string, n int) string

Replace returns a copy of the string `s` with the first `n` non-overlapping instances of `old` replaced by `new`. If `old` is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to `k+1` replacements for a `k-rune string. If `n < 0`, there is no limit on the number of replacements.

Example:

fmt.Println(strings.Replace("oink oink oink", "k", "ky", 2))
fmt.Println(strings.Replace("oink oink oink", "oink", "moo", -1))
out:
oinky oinky oink
moo moo moo

func ReplaceAll

func ReplaceAll(s, old, new string) string

ReplaceAll returns a copy of the string `s` with all non-overlapping instances of `old` replaced by `new`. If `old` is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to `k+1` replacements for a `k`-rune string.

Example:

fmt.Println(strings.ReplaceAll("oink oink oink", "oink", "moo"))
out: moo moo moo

func Reverse

func Reverse(s string) string

Reverse reverse the string `s` based on `rune`

func ReverseByte

func ReverseByte(s string) string

ReverseByte reverse the string `s` based on `byte`

func ReverseFloat32

func ReverseFloat32(s []float32) []float32

ReverseFloat32 reverses an array of float32

func ReverseFloat64

func ReverseFloat64(s []float64) []float64

ReverseFloat64 reverses an array of float64

func ReverseInt

func ReverseInt(s []int) []int

ReverseInt reverses an array of int

func ReverseInt32

func ReverseInt32(s []int32) []int32

ReverseInt32 reverses an array of int32

func ReverseInt64

func ReverseInt64(s []int64) []int64

ReverseInt64 reverses an array of int64

func ReverseString

func ReverseString(s string) string

ReverseString reverses a string

func ReverseStrings

func ReverseStrings(s []string) []string

ReverseStrings reverses an array of string

func ReverseUInt

func ReverseUInt(s []uint) []uint

ReverseUInt reverses an array of int

func ReverseUInt32

func ReverseUInt32(s []uint32) []uint32

ReverseUInt32 reverses an array of uint32

func ReverseUInt64

func ReverseUInt64(s []uint64) []uint64

ReverseUInt64 reverses an array of uint64

func RuneWidth

func RuneWidth(r rune) int

RuneWidth returns the number of cells in r. See http://www.unicode.org/reports/tr11/

func SetLoggerFieldsOrder

func SetLoggerFieldsOrder(fields []string)

SetLoggerFieldsOrder set `nestedFormatter.FieldsOrder`

func Shuffle

func Shuffle(slice []interface{})

Shuffle randomly shuffle the order of `slice`

func ShuffleFloat32

func ShuffleFloat32(a []float32) []float32

ShuffleFloat32 creates an array of float32 shuffled values using Fisher–Yates algorithm

func ShuffleFloat64

func ShuffleFloat64(a []float64) []float64

ShuffleFloat64 creates an array of float64 shuffled values using Fisher–Yates algorithm

func ShuffleInt

func ShuffleInt(a []int) []int

ShuffleInt creates an array of int shuffled values using Fisher–Yates algorithm

func ShuffleInt32

func ShuffleInt32(a []int32) []int32

ShuffleInt32 creates an array of int32 shuffled values using Fisher–Yates algorithm

func ShuffleInt64

func ShuffleInt64(a []int64) []int64

ShuffleInt64 creates an array of int64 shuffled values using Fisher–Yates algorithm

func ShuffleString

func ShuffleString(a []string) []string

ShuffleString creates an array of string shuffled values using Fisher–Yates algorithm

func ShuffleUInt

func ShuffleUInt(a []uint) []uint

ShuffleUInt creates an array of int shuffled values using Fisher–Yates algorithm

func ShuffleUInt32

func ShuffleUInt32(a []uint32) []uint32

ShuffleUInt32 creates an array of uint32 shuffled values using Fisher–Yates algorithm

func ShuffleUInt64

func ShuffleUInt64(a []uint64) []uint64

ShuffleUInt64 creates an array of uint64 shuffled values using Fisher–Yates algorithm

func Spaces

func Spaces(w int) string

Spaces return a string with lenth w of spaces

func Split

func Split(s, sep string) []string

Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators.

If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s.

If sep is empty, Split splits after each UTF-8 sequence. If both s and sep are empty, Split returns an empty slice.

It is equivalent to SplitN with a count of -1.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Printf("%q\n", strings.Split("a,b,c", ","))
	// ["a" "b" "c"]
	fmt.Printf("%q\n", strings.Split("a man a plan a canal panama", "a "))
	// ["" "man " "plan " "canal panama"]
	fmt.Printf("%q\n", strings.Split(" xyz ", ""))
	// [" " "x" "y" "z" " "]
	fmt.Printf("%q\n", strings.Split("", "Bernardo O'Higgins"))
	// [""]
}

func SplitAfter

func SplitAfter(s, sep string) []string

SplitAfter slices s into all substrings after each instance of sep and returns a slice of those substrings.

If s does not contain sep and sep is not empty, SplitAfter returns a slice of length 1 whose only element is s.

If sep is empty, SplitAfter splits after each UTF-8 sequence. If both s and // sep are empty, SplitAfter returns an empty slice.

It is equivalent to SplitAfterN with a count of -1.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Printf("%q\n", strings.SplitAfter("a,b,c", ",")) // ["a," "b," "c"]
}

func SplitAfterN

func SplitAfterN(s, sep string, n int) []string

SplitAfterN slices s into substrings after each instance of sep and returns a slice of those substrings.

The count determines the number of substrings to return:

n > 0: at most n substrings; the last substring will be the unsplit remainder.
n == 0: the result is nil (zero substrings)
n < 0: all substrings

Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for SplitAfter.

Example

package main

import (

"fmt"
"strings"

)

func main() {
	fmt.Printf("%q\n", strings.SplitAfterN("a,b,c", ",", 2)) // ["a," "b,c"]
}

func SplitN

func SplitN(s, sep string, n int) []string

SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators.

The count determines the number of substrings to return:

n > 0: at most n substrings; the last substring will be the unsplit remainder.
n == 0: the result is nil (zero substrings)
n < 0: all substrings

Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for Split.

Example

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Printf("%q\n", strings.SplitN("a,b,c", ",", 2)) // ["a" "b,c"]
	z := strings.SplitN("a,b,c", ",", 0)
	fmt.Printf("%q (nil = %v)\n", z, z == nil) //[] (nil = true)
}

func StringWidth

func StringWidth(s string) int

StringWidth will return width as you can see (the numbers of placeholders on terminal)

func Sum

func Sum(x interface{}) interface{}

Sum will return summation of []int, []float32, []flot64, []string. If the type of `x` is not one of []int, []float32, []flot64 and []string, then return `nil` If `x` is []string, will return concatenation using `strings.Join(a,"")`.

func SumFloat32s

func SumFloat32s(a ...float32) float32

SumFloat32s will return summation of []float32

func SumFloat64s

func SumFloat64s(a ...float64) float64

SumFloat64s will return summation of []float64

func SumInts

func SumInts(a ...int) int

SumInts will return summation of []int

func SumStrings

func SumStrings(a ...string) string

SumStrings will return concatenation of []string using strings.Join(a, "")

func Title

func Title(s string) string

Title returns a copy of the string `s` with all Unicode letters that begin words mapped to their Unicode title case.

BUG(rsc): The rule Title uses for word boundaries does not handle Unicode punctuation properly.

Example:

Compare this example to the ToTitle example.
fmt.Println(strings.Title("her royal highness"))
fmt.Println(strings.Title("loud noises"))
fmt.Println(strings.Title("хлеб"))
out:
Her Royal Highness
Loud Noises
Хлеб

func ToLower

func ToLower(s string) string

ToLower returns s with all Unicode letters mapped to their lower case.

Example:

fmt.Println(strings.ToLower("Gopher"))
out: gopher

func ToTitle

func ToTitle(s string) string

ToTitle returns a copy of the string `s` with all Unicode letters mapped to their Unicode title case.

Example:

Compare this example to the Title example.
fmt.Println(strings.ToTitle("her royal highness"))
fmt.Println(strings.ToTitle("loud noises"))
fmt.Println(strings.ToTitle("хлеб"))
out:
HER ROYAL HIGHNESS
LOUD NOISES
ХЛЕБ

func ToUpper

func ToUpper(s string) string

ToUpper returns `s` with all Unicode letters mapped to their upper case.

Example:

fmt.Println(strings.ToUpper("Gopher"))
out: GOPHER

func Trim

func Trim(s, cutset string) string

Trim returns a slice of the string `s` with all leading and trailing Unicode code points contained in `cutset` removed.

func TrimBOM

func TrimBOM(line string) string

TrimBOM trim the leading BOM character of a string

func TrimFrontEndSpaceLine

func TrimFrontEndSpaceLine(content string) string

TrimFrontEndSpaceLine trim the front and end empty line of `content` and return

func TrimFunc

func TrimFunc(s string, f func(rune) bool) string

TrimFunc returns a slice of the string `s` with all leading and trailing Unicode code points `c` satisfying `f(c)` removed.

Example:

fmt.Print(strings.TrimFunc("¡¡¡Hello, Gophers!!!", func(r rune) bool { return !unicode.IsLetter(r) && !unicode.IsNumber(r)}))
out: Hello, Gophers

func TrimLeft

func TrimLeft(s, cutset string) string

TrimLeft returns a slice of the string `s` with all leading Unicode code points contained in `cutset` removed.

To remove a `prefix`, use `TrimPrefix` instead.

Example:

fmt.Print(strings.TrimLeft("¡¡¡Hello, Gophers!!!", "!¡"))
out: Hello, Gophers!!!

func TrimLeftFunc

func TrimLeftFunc(s string, f func(rune) bool) string

TrimLeftFunc returns a slice of the string `s` with all leading Unicode code points `c` satisfying `f(c)` removed.

Example:

fmt.Print(strings.TrimLeftFunc("¡¡¡Hello, Gophers!!!", func(r rune) bool {return !unicode.IsLetter(r) && !unicode.IsNumber(r)}))
out: Hello, Gophers!!!

func TrimPrefix

func TrimPrefix(s, prefix string) string

TrimPrefix returns `s` without the provided leading prefix string. If `s` doesn't start with `prefix`, `s` is returned unchanged.

Example:

var s = "¡¡¡Hello, Gophers!!!"
s = strings.TrimPrefix(s, "¡¡¡Hello, ")
s = strings.TrimPrefix(s, "¡¡¡Howdy, ")
fmt.Print(s)
out: Gophers!!!

func TrimRight

func TrimRight(s, cutset string) string

TrimRight returns a slice of the string `s`, with all trailing Unicode code points contained in cutset removed.

To remove a `suffix`, use `TrimSuffix` instead.

Example:

fmt.Print(strings.TrimRight("¡¡¡Hello, Gophers!!!", "!¡"))

out: ¡¡¡Hello, Gophers

func TrimRightFunc

func TrimRightFunc(s string, f func(rune) bool) string

TrimRightFunc returns a slice of the string `s` with all trailing Unicode code points `c` satisfying `f(c)` removed.

Example:

fmt.Print(strings.TrimRightFunc("¡¡¡Hello, Gophers!!!", func(r rune) bool {return !unicode.IsLetter(r) && !unicode.IsNumber(r)}))

out: ¡¡¡Hello, Gophers

func TrimSpace

func TrimSpace(s string) string

TrimSpace returns a slice of the string `s`, with all leading and trailing white space removed, as defined by Unicode.

Example:

fmt.Println(strings.TrimSpace(" \t\n Hello, Gophers \n\t\r\n"))
out: Hello, Gophers

func TrimSuffix

func TrimSuffix(s, suffix string) string

TrimSuffix returns `s` without the provided trailing `suffix` string. If `s` doesn't end with suffix, `s` is returned unchanged.

Example:

var s = "¡¡¡Hello, Gophers!!!"
s = strings.TrimSuffix(s, ", Gophers!!!")
s = strings.TrimSuffix(s, ", Marmots!!!")
out: ¡¡¡Hello

func Truncate

func Truncate(s string, w int, tail string) string

Truncate return string truncated with w cells

func Utf8ToBig5

func Utf8ToBig5(s []byte) ([]byte, error)

Utf8ToBig5 encodes UTF8 to Big5

func Utf8ToBig5String

func Utf8ToBig5String(s string) (string, error)

Utf8ToBig5String encodes UTF8 to Big5

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

Utf8ToGbk encodes UTF8 to GBK

func Utf8ToGbkString

func Utf8ToGbkString(s string) (string, error)

Utf8ToGbkString encodes UTF8 to GBK

func Wrap

func Wrap(s string, w int) string

Wrap return string wrapped with w cells

func WrapToSlice

func WrapToSlice(s string, w int) []string

WrapToSlice return string slice wrapped with w cells

Types

type Align

type Align int

Align is id that indicate alignment of head-column

const (

	// AlignLeft align left
	AlignLeft Align = iota
	// AlignCenter align center
	AlignCenter
	// AlignRight align right
	AlignRight
)

type LogFormatter

type LogFormatter struct{}

LogFormatter 日誌自定義格式

func (*LogFormatter) Format

func (s *LogFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format 格式詳情

type StrChain

type StrChain struct {
	// contains filtered or unexported fields
}

StrChain contains all tools which can be chained.

func (*StrChain) Big5ToUtf8String

func (t *StrChain) Big5ToUtf8String() (*StrChain, error)

Big5ToUtf8String packs `Big5ToUtf8String(s string)`

func (*StrChain) Bytes

func (t *StrChain) Bytes() []byte

Bytes will convert the string t.v to []byte

Example:

b := StrChain{"ABC€"}
fmt.Println(b.Bytes()) // [65 66 67 226 130 172]

func (*StrChain) Contains

func (t *StrChain) Contains(substr string) bool

Contains return `Contains(t.v, substr)`

func (*StrChain) ContainsAny

func (t *StrChain) ContainsAny(chars string) bool

ContainsAny return `ContainsAny(t.v, chars)`

func (*StrChain) ContainsRune

func (t *StrChain) ContainsRune(r rune) bool

ContainsAny return ContainsRune(t.v, r) bool

func (*StrChain) CountPlaceHolder

func (t *StrChain) CountPlaceHolder() (nHan int, nASCII int)

CountPlaceHolder return `nHan` and `nASCII`

`nHan`: number of occupied space in screen for han-character
`nASCII`: number of occupied space in screen for ASCII-character

func (*StrChain) EqualFold

func (t *StrChain) EqualFold(s string) bool

EqualFold return EqualFold(t.v,, t) bool

func (*StrChain) Fields

func (t *StrChain) Fields() []string

Fields return Fields(t.v)

func (*StrChain) FieldsFunc

func (t *StrChain) FieldsFunc(f func(rune) bool) []string

FieldsFunc return FieldsFunc(t.v, f)

func (*StrChain) FillLeft

func (t *StrChain) FillLeft(w int) *StrChain

FillLeft return string filled in left by spaces in w cells

func (*StrChain) FillRight

func (t *StrChain) FillRight(w int) *StrChain

FillRight return string filled in left by spaces in w cells

func (*StrChain) GbkToUtf8String

func (t *StrChain) GbkToUtf8String() (*StrChain, error)

GbkToUtf8String packs `GbkToUtf8String(s string)`

func (*StrChain) GetAbbrString

func (t *StrChain) GetAbbrString(maxlen int, contSymbol string) *StrChain

GetAbbrString get a abbreviation of `StrChain.sCollection.s` and save to `StrChain.sCollection.s`

`maxlen`: maimium length of the abbreviation
`conSymbole`: tailing symbol of the abbreviation

func (*StrChain) GetText

func (t *StrChain) GetText() string

GetText return `StrChain.sCollection.s`

func (*StrChain) HasChineseChar

func (t *StrChain) HasChineseChar() bool

HasChineseChar return true for that `str` include chinese character

Example:

HasChineseChar("abc 中文") return true
HasChineseChar("abccefgh") return false

func (*StrChain) HasPrefix

func (t *StrChain) HasPrefix(prefix string) bool

HasPrefix return `HasPrefix(t.v, prefix)`

func (*StrChain) HasSuffix

func (t *StrChain) HasSuffix(suffix string) bool

HasSuffix return `HasSuffix(t.v, Suffix)`

func (*StrChain) Index

func (t *StrChain) Index(substr string) int

Index return Index(t.v, substr) int

func (*StrChain) IndexAny

func (t *StrChain) IndexAny(chars string) int

IndexAny return IndexAny(t.v, chars) int

func (*StrChain) IndexByte

func (t *StrChain) IndexByte(c byte) int

IndexByte return IndexByte(t.v, c) int

func (*StrChain) IndexFunc

func (t *StrChain) IndexFunc(f func(rune) bool) int

IndexFunc return IndexFunc(t.v, f) int

func (*StrChain) IndexRune

func (t *StrChain) IndexRune(r rune) int

IndexRune return IndexRune(t.v, r) int

func (*StrChain) IsEqualString

func (t *StrChain) IsEqualString(b string, ignoreCase bool) bool

IsEqualString packs `IsEqualString(a, b string, ignoreCase bool) bool`

func (*StrChain) LastIndex

func (t *StrChain) LastIndex(substr string) int

LastIndex return LastIndex(t.v, substr) int

func (*StrChain) LastIndexAny

func (t *StrChain) LastIndexAny(chars string) int

LastIndexAny return LastIndexAny(t.v, chars) int

func (*StrChain) LastIndexByte

func (t *StrChain) LastIndexByte(c byte) int

LastIndexByte return LastIndexByte(t.v, c) int

func (*StrChain) LastIndexFunc

func (t *StrChain) LastIndexFunc(f func(rune) bool) int

LastIndexFunc return LastIndexFunc(t.v, f) int

func (*StrChain) Len

func (t *StrChain) Len() int

Len will return the lenth of t.v (would be the sizes of []bytes)

func (*StrChain) Map

func (t *StrChain) Map(mapping func(rune) rune) *StrChain

Map packs `Map(mapping func(rune) rune, s string)`

set `StrChain.S` to the result

func (*StrChain) NewStrChain

func (t *StrChain) NewStrChain(s string) *StrChain

NewStrChain return a instance of `StrChain` and return `*StrChain`

func (*StrChain) NumberBanner

func (t *StrChain) NumberBanner() *StrChain

NumberBanner return numbers' string with length of `StrChain.sCollection.s`

Example:

StrChain.sCollection.s = "Text中文 Collection"
nh, na := CountPlaceHolder("Text中文 Collection")
--> nh=4, na=15 --> length = nh + na = 19
NumberBanner() return "12345678901"

func (*StrChain) Repeat

func (t *StrChain) Repeat(count int) *StrChain

Repeat packs `Repeat(s string, count int)`

set `StrChain.S` to the result

func (*StrChain) Replace

func (t *StrChain) Replace(old, new string, n int) *StrChain

Replace packs `Replace(s, old, new string, n int)`

set `StrChain.S` to the result

func (*StrChain) ReplaceAll

func (t *StrChain) ReplaceAll(old, new string) *StrChain

ReplaceAll packs `ReplaceAll(s, old, new string)`

set `StrChain.S` to the result

func (*StrChain) Reverse

func (t *StrChain) Reverse() *StrChain

Reverse packs `Reverse(s string)` based on `rune`

set `StrChain.S` to the result

func (*StrChain) ReverseByte

func (t *StrChain) ReverseByte() *StrChain

ReverseByte packs `ReverseByte(s string)` based on `byte`

set `StrChain.S` to the result

func (*StrChain) Runes

func (t *StrChain) Runes() []rune

Runes will convert the string t.v to []rune

Example:

r := StrChain{"ABC€"}
fmt.Println(r.Runes())        	// [65 66 67 8364]
fmt.Printf("%U\n", r.Rune()) 	// [U+0041 U+0042 U+0043 U+20AC]

func (*StrChain) SetText

func (t *StrChain) SetText(txt string) *StrChain

SetText set `StrChain.s` to `txt`

func (*StrChain) Split

func (t *StrChain) Split(sep string) []string

Split return Split(t.v, sep) []string

func (*StrChain) SplitAfter

func (t *StrChain) SplitAfter(sep string) []string

Split return Split(t.v, sep) []string

func (*StrChain) SplitAfterN

func (t *StrChain) SplitAfterN(sep string, n int) []string

Split return Split(t.v, sep) []string

func (*StrChain) SplitN

func (t *StrChain) SplitN(sep string, n int) []string

Split return Split(t.v, sep) []string

func (*StrChain) String

func (t *StrChain) String() string

String return `StrChain.sCollection.s`

func (*StrChain) StringWidth

func (t *StrChain) StringWidth() int

StringWidth will return width as you can see (the numbers of placeholders on terminal)

func (*StrChain) Title

func (t *StrChain) Title() *StrChain

Title returns packs `Title(s string)`

set `StrChain.S` to the result

func (*StrChain) ToLower

func (t *StrChain) ToLower() *StrChain

ToLower packs ` ToLower(s string)`

set `StrChain.S` to the result

func (*StrChain) ToTitle

func (t *StrChain) ToTitle() *StrChain

ToTitle packs `ToTitle(s string)`

set `StrChain.S` to the result

func (*StrChain) ToUpper

func (t *StrChain) ToUpper() *StrChain

ToUpper packs `ToUpper(s string)`

set `StrChain.S` to the result

func (*StrChain) Trim

func (t *StrChain) Trim(cutset string) *StrChain

Trim packs `Trim(s, cutset)`

set `StrChain.S` to the result

func (*StrChain) TrimBOM

func (t *StrChain) TrimBOM() *StrChain

TrimBOM packs `TrimBOM(line string) string`

func (*StrChain) TrimFrontEndSpaceLine

func (t *StrChain) TrimFrontEndSpaceLine() *StrChain

TrimFrontEndSpaceLine packs `TrimFrontEndSpaceLine(content string) string`

func (*StrChain) TrimFunc

func (t *StrChain) TrimFunc(f func(rune) bool) *StrChain

TrimFunc packs `TrimFunc(s string, f func(rune) bool)`

set `StrChain.S` to the result

func (*StrChain) TrimLeft

func (t *StrChain) TrimLeft(cutset string) *StrChain

TrimLeft packs `TrimLeft(s, cutset string)`

set `StrChain.S` to the result

func (*StrChain) TrimLeftFunc

func (t *StrChain) TrimLeftFunc(f func(rune) bool) *StrChain

TrimLeftFunc packs `TrimLeftFunc(s string, f func(rune) bool)`

set `StrChain.S` to the result

func (*StrChain) TrimPrefix

func (t *StrChain) TrimPrefix(prefix string) *StrChain

TrimPrefix packs `TrimPrefix(s, prefix string)`

set `StrChain.S` to the result

func (*StrChain) TrimRight

func (t *StrChain) TrimRight(cutset string) *StrChain

TrimRight packs `TrimRight(s, cutset string)`

set `StrChain.S` to the result

func (*StrChain) TrimRightFunc

func (t *StrChain) TrimRightFunc(f func(rune) bool) *StrChain

TrimRightFunc packs `TrimRightFunc(s string, f func(rune) bool)`

set `StrChain.S` to the result

func (*StrChain) TrimSpace

func (t *StrChain) TrimSpace() *StrChain

TrimSpace packs `TrimSpace(s string)`

set `StrChain.S` to the result

func (*StrChain) TrimSuffix

func (t *StrChain) TrimSuffix(suffix string) *StrChain

TrimSuffix packs `TrimSuffix(s, suffix string)`

set `StrChain.S` to the result

func (*StrChain) Truncate

func (t *StrChain) Truncate(w int, tail string) *StrChain

Truncate return string truncated with w cells

func (*StrChain) Utf8ToBig5String

func (t *StrChain) Utf8ToBig5String() (*StrChain, error)

Utf8ToBig5String packs `Utf8ToBig5String(s string)`

func (*StrChain) Utf8ToGbkString

func (t *StrChain) Utf8ToGbkString() (*StrChain, error)

Utf8ToGbkString packs `Utf8ToGbkString(s string)`

func (*StrChain) Wrap

func (t *StrChain) Wrap(w int) *StrChain

Wrap return string wrapped with w cells

type TableFormat

type TableFormat struct {
	Fields            []string
	LenFields         []int
	Aligns            []Align
	Colors            []*color.Color
	FieldsColorString []string
	Padding           string
	Sep               string
	TopChar           string

	MiddleChar string

	BottomChar string

	IsWrapped  bool
	IsColorful bool
	// chdEven         *color.Color
	// chdOdd          *color.Color
	XAttributeSymbol  string
	XAttributeSymbol2 string
	// contains filtered or unexported fields
}

TableFormat define the format used to print out

Elements:

`Fields []string{}`, string list of heading row `LenFields []int{}`, length of every field of heading row `Aligns []Align{}` : , `Padding string`: paddign string befor every row, default "", `Sep string` : sepperating string between fields `TopChar string`: character of top sepperating row, default "=", `MiddleChar string`: character of middle sepperating row , default "-", `BottomChar string`: character of bottom sepperating row, default "=",

func NewTableFormat

func NewTableFormat() *TableFormat

NewTableFormat return a instance of TableFormat

func (*TableFormat) NFields

func (t *TableFormat) NFields() int

NFields will return number of TableFormat.Fields

func (*TableFormat) Prepare

func (t *TableFormat) Prepare(w io.Writer)

Prepare initialize `TableFormat`

func (*TableFormat) PrintEnd

func (t *TableFormat) PrintEnd()

PrintEnd print end-section into `t.writer`

func (*TableFormat) PrintMiddleSepLine

func (t *TableFormat) PrintMiddleSepLine()

PrintMiddleSepLine print middle sepperating line using `MiddleChar`

func (*TableFormat) PrintRow

func (t *TableFormat) PrintRow(rows ...interface{})

PrintRow print row into `t.writer`

func (*TableFormat) PrintSart

func (t *TableFormat) PrintSart() error

PrintSart print out head-section in `t.Writer`

func (*TableFormat) SetAfterMessage

func (t *TableFormat) SetAfterMessage(msg string)

SetAfterMessage set message to show after table

func (*TableFormat) SetBeforeMessage

func (t *TableFormat) SetBeforeMessage(msg string)

SetBeforeMessage set message to show before table

func (*TableFormat) SetWrapFields

func (t *TableFormat) SetWrapFields()

SetWrapFields set true to TableFormat.IsWrapped

type TextBuilder

type TextBuilder struct {
	Text string
}

TextBuilder contains all tools which can be chained.

func (*TextBuilder) Big5ToUtf8String

func (t *TextBuilder) Big5ToUtf8String() (TextTools, error)

Big5ToUtf8String packs `Big5ToUtf8String(s string)`

func (*TextBuilder) Contains

func (t *TextBuilder) Contains(substr string) bool

Contains return `Contains(t.Text, substr)`

func (*TextBuilder) ContainsAny

func (t *TextBuilder) ContainsAny(chars string) bool

ContainsAny return `ContainsAny(t.Text, chars)`

func (*TextBuilder) ContainsRune

func (t *TextBuilder) ContainsRune(r rune) bool

ContainsAny return ContainsRune(t.Text, r) bool

func (*TextBuilder) CountPlaceHolder

func (t *TextBuilder) CountPlaceHolder() (nHan int, nASCII int)

CountPlaceHolder return `nHan` and `nASCII`

`nHan`: number of occupied space in screen for han-character
`nASCII`: number of occupied space in screen for ASCII-character

func (*TextBuilder) EqualFold

func (t *TextBuilder) EqualFold(s string) bool

EqualFold return EqualFold(t.Text,, t) bool

func (*TextBuilder) Fields

func (t *TextBuilder) Fields() []string

Fields return Fields(t.Text)

func (*TextBuilder) FieldsFunc

func (t *TextBuilder) FieldsFunc(f func(rune) bool) []string

FieldsFunc return FieldsFunc(t.Text, f)

func (*TextBuilder) GbkToUtf8String

func (t *TextBuilder) GbkToUtf8String() (TextTools, error)

GbkToUtf8String packs `GbkToUtf8String(s string)`

func (*TextBuilder) GetAbbrString

func (t *TextBuilder) GetAbbrString(maxlen int, contSymbol string) TextTools

GetAbbrString get a abbreviation of `TextBuilder.TextCollection.Text` and save to `TextBuilder.TextCollection.Text`

`maxlen`: maimium length of the abbreviation
`conSymbole`: tailing symbol of the abbreviation

func (*TextBuilder) GetText

func (t *TextBuilder) GetText() string

GetText return `TextBuilder.TextCollection.Text`

func (*TextBuilder) HasChineseChar

func (t *TextBuilder) HasChineseChar() bool

HasChineseChar return true for that `str` include chinese character

Example:

HasChineseChar("abc 中文") return true
HasChineseChar("abccefgh") return false

func (*TextBuilder) HasPrefix

func (t *TextBuilder) HasPrefix(prefix string) bool

HasPrefix return `HasPrefix(t.Text, prefix)`

func (*TextBuilder) HasSuffix

func (t *TextBuilder) HasSuffix(suffix string) bool

HasSuffix return `HasSuffix(t.Text, Suffix)`

func (*TextBuilder) Index

func (t *TextBuilder) Index(substr string) int

Index return Index(t.Text, substr) int

func (*TextBuilder) IndexAny

func (t *TextBuilder) IndexAny(chars string) int

IndexAny return IndexAny(t.Text, chars) int

func (*TextBuilder) IndexByte

func (t *TextBuilder) IndexByte(c byte) int

IndexByte return IndexByte(t.Text, c) int

func (*TextBuilder) IndexFunc

func (t *TextBuilder) IndexFunc(f func(rune) bool) int

IndexFunc return IndexFunc(t.Text, f) int

func (*TextBuilder) IndexRune

func (t *TextBuilder) IndexRune(r rune) int

IndexRune return IndexRune(t.Text, r) int

func (*TextBuilder) IsEqualString

func (t *TextBuilder) IsEqualString(b string, ignoreCase bool) bool

IsEqualString packs `IsEqualString(a, b string, ignoreCase bool) bool`

func (*TextBuilder) LastIndex

func (t *TextBuilder) LastIndex(substr string) int

LastIndex return LastIndex(t.Text, substr) int

func (*TextBuilder) LastIndexAny

func (t *TextBuilder) LastIndexAny(chars string) int

LastIndexAny return LastIndexAny(t.Text, chars) int

func (*TextBuilder) LastIndexByte

func (t *TextBuilder) LastIndexByte(c byte) int

LastIndexByte return LastIndexByte(t.Text, c) int

func (*TextBuilder) LastIndexFunc

func (t *TextBuilder) LastIndexFunc(f func(rune) bool) int

LastIndexFunc return LastIndexFunc(t.Text, f) int

func (*TextBuilder) Map

func (t *TextBuilder) Map(mapping func(rune) rune) TextTools

Map packs `Map(mapping func(rune) rune, s string)`

set `TextCollection.Text` to the result

func (*TextBuilder) NewTextBuilder

func (t *TextBuilder) NewTextBuilder(s string) TextTools

NewTextBuilder return a instance of `TextBuilder` and return `TextTools`

func (*TextBuilder) NumberBanner

func (t *TextBuilder) NumberBanner() TextTools

NumberBanner return numbers' string with length of `TextBuilder.TextCollection.Text`

Example:

TextBuilder.TextCollection.Text = "Text中文 Collection"
nh, na := CountPlaceHolder("Text中文 Collection")
--> nh=4, na=15 --> length = nh + na = 19
NumberBanner() return "12345678901"

func (*TextBuilder) Repeat

func (t *TextBuilder) Repeat(count int) TextTools

Repeat packs `Repeat(s string, count int)`

set `TextCollection.Text` to the result

func (*TextBuilder) Replace

func (t *TextBuilder) Replace(old, new string, n int) TextTools

Replace packs `Replace(s, old, new string, n int)`

set `TextCollection.Text` to the result

func (*TextBuilder) ReplaceAll

func (t *TextBuilder) ReplaceAll(old, new string) TextTools

ReplaceAll packs `ReplaceAll(s, old, new string)`

set `TextCollection.Text` to the result

func (*TextBuilder) Reverse

func (t *TextBuilder) Reverse() TextTools

Reverse packs `Reverse(s string)`

set `TextCollection.Text` to the result

func (*TextBuilder) SetText

func (t *TextBuilder) SetText(txt string) TextTools

SetText set `TextBuilder.Text` to `txt`

func (*TextBuilder) Split

func (t *TextBuilder) Split(sep string) []string

Split return Split(t.Text, sep) []string

func (*TextBuilder) SplitAfter

func (t *TextBuilder) SplitAfter(sep string) []string

Split return Split(t.Text, sep) []string

func (*TextBuilder) SplitAfterN

func (t *TextBuilder) SplitAfterN(sep string, n int) []string

Split return Split(t.Text, sep) []string

func (*TextBuilder) SplitN

func (t *TextBuilder) SplitN(sep string, n int) []string

Split return Split(t.Text, sep) []string

func (*TextBuilder) String

func (t *TextBuilder) String() string

String return `TextBuilder.TextCollection.Text`

func (*TextBuilder) Title

func (t *TextBuilder) Title() TextTools

Title returns packs `Title(s string)`

set `TextCollection.Text` to the result

func (*TextBuilder) ToLower

func (t *TextBuilder) ToLower() TextTools

ToLower packs ` ToLower(s string)`

set `TextCollection.Text` to the result

func (*TextBuilder) ToTitle

func (t *TextBuilder) ToTitle() TextTools

ToTitle packs `ToTitle(s string)`

set `TextCollection.Text` to the result

func (*TextBuilder) ToUpper

func (t *TextBuilder) ToUpper() TextTools

ToUpper packs `ToUpper(s string)`

set `TextCollection.Text` to the result

func (*TextBuilder) Trim

func (t *TextBuilder) Trim(cutset string) TextTools

Trim packs `Trim(s, cutset)`

set `TextCollection.Text` to the result

func (*TextBuilder) TrimBOM

func (t *TextBuilder) TrimBOM() TextTools

TrimBOM packs `TrimBOM(line string) string`

func (*TextBuilder) TrimFrontEndSpaceLine

func (t *TextBuilder) TrimFrontEndSpaceLine() TextTools

TrimFrontEndSpaceLine packs `TrimFrontEndSpaceLine(content string) string`

func (*TextBuilder) TrimFunc

func (t *TextBuilder) TrimFunc(f func(rune) bool) TextTools

TrimFunc packs `TrimFunc(s string, f func(rune) bool)`

set `TextCollection.Text` to the result

func (*TextBuilder) TrimLeft

func (t *TextBuilder) TrimLeft(cutset string) TextTools

TrimLeft packs `TrimLeft(s, cutset string)`

set `TextCollection.Text` to the result

func (*TextBuilder) TrimLeftFunc

func (t *TextBuilder) TrimLeftFunc(f func(rune) bool) TextTools

TrimLeftFunc packs `TrimLeftFunc(s string, f func(rune) bool)`

set `TextCollection.Text` to the result

func (*TextBuilder) TrimPrefix

func (t *TextBuilder) TrimPrefix(prefix string) TextTools

TrimPrefix packs `TrimPrefix(s, prefix string)`

set `TextCollection.Text` to the result

func (*TextBuilder) TrimRight

func (t *TextBuilder) TrimRight(cutset string) TextTools

TrimRight packs `TrimRight(s, cutset string)`

set `TextCollection.Text` to the result

func (*TextBuilder) TrimRightFunc

func (t *TextBuilder) TrimRightFunc(f func(rune) bool) TextTools

TrimRightFunc packs `TrimRightFunc(s string, f func(rune) bool)`

set `TextCollection.Text` to the result

func (*TextBuilder) TrimSpace

func (t *TextBuilder) TrimSpace() TextTools

TrimSpace packs `TrimSpace(s string)`

set `TextCollection.Text` to the result

func (*TextBuilder) TrimSuffix

func (t *TextBuilder) TrimSuffix(suffix string) TextTools

TrimSuffix packs `TrimSuffix(s, suffix string)`

set `TextCollection.Text` to the result

func (*TextBuilder) Utf8ToBig5String

func (t *TextBuilder) Utf8ToBig5String() (TextTools, error)

Utf8ToBig5String packs `Utf8ToBig5String(s string)`

func (*TextBuilder) Utf8ToGbkString

func (t *TextBuilder) Utf8ToGbkString() (TextTools, error)

Utf8ToGbkString packs `Utf8ToGbkString(s string)`

type TextTools

type TextTools interface {
	GetAbbrString(maxlen int, contSymbol string) TextTools
	Map(mapping func(rune) rune) TextTools
	NumberBanner() TextTools
	Repeat(count int) TextTools
	Replace(old, new string, n int) TextTools
	ReplaceAll(old, new string) TextTools
	Reverse() TextTools
	SetText(txt string) TextTools
	Title() TextTools
	ToLower() TextTools
	ToTitle() TextTools
	ToUpper() TextTools
	Trim(cutset string) TextTools
	TrimFunc(f func(rune) bool) TextTools
	TrimLeft(cutset string) TextTools
	TrimLeftFunc(f func(rune) bool) TextTools
	TrimPrefix(prefix string) TextTools
	TrimRight(cutset string) TextTools
	TrimRightFunc(f func(rune) bool) TextTools
	TrimSpace() TextTools
	TrimSuffix(suffix string) TextTools
	TrimBOM() TextTools
	TrimFrontEndSpaceLine() TextTools

	Big5ToUtf8String() (TextTools, error)
	Utf8ToBig5String() (TextTools, error)
	GbkToUtf8String() (TextTools, error)
	Utf8ToGbkString() (TextTools, error)

	CountPlaceHolder() (nHan int, nASCII int)
	Contains(substr string) bool
	ContainsAny(chars string) bool
	ContainsRune(r rune) bool
	EqualFold(t string) bool
	Fields() []string
	FieldsFunc(f func(rune) bool) []string
	Index(substr string) int
	IndexAny(chars string) int
	IndexByte(c byte) int
	IndexFunc(f func(rune) bool) int
	IndexRune(r rune) int
	LastIndex(substr string) int
	LastIndexAny(chars string) int
	LastIndexByte(c byte) int
	LastIndexFunc(f func(rune) bool) int
	Split(sep string) []string
	SplitN(sep string, n int) []string
	SplitAfter(sep string) []string
	SplitAfterN(sep string, n int) []string

	GetText() string
	HasChineseChar() bool
	HasPrefix(prefix string) bool
	HasSuffix(suffix string) bool
	IsEqualString(b string, ignoreCase bool) bool
}

TextTools is the collections of tools of text

Notes

Bugs

  • The rule Title uses for word boundaries does not handle Unicode punctuation properly.

    Example:

    Compare this example to the ToTitle example.
    fmt.Println(strings.Title("her royal highness"))
    fmt.Println(strings.Title("loud noises"))
    fmt.Println(strings.Title("хлеб"))
    out:
    Her Royal Highness
    Loud Noises
    Хлеб
    

Directories

Path Synopsis
3rd-party
godirwalk/examples/find-fast
* find-fast * * Walks a file system hierarchy using this library.
* find-fast * * Walks a file system hierarchy using this library.
godirwalk/examples/remove-empty-directories
* remove-empty-directories * * Walks a file system hierarchy and removes all directories with no children.
* remove-empty-directories * * Walks a file system hierarchy and removes all directories with no children.
godirwalk/examples/sizes
* sizes * * Walks a file system hierarchy and prints sizes of file system objects, * recursively printing sizes of directories.
* sizes * * Walks a file system hierarchy and prints sizes of file system objects, * recursively printing sizes of directories.
godirwalk/examples/walk-fast
* walk-fast * * Walks a file system hierarchy using this library.
* walk-fast * * Walks a file system hierarchy using this library.
godirwalk/examples/walk-stdlib
* walk-fast * * Walks a file system hierarchy using the standard library.
* walk-fast * * Walks a file system hierarchy using the standard library.
treeprint
Package treeprint provides a simple ASCII tree composing tool.
Package treeprint provides a simple ASCII tree composing tool.
Package cast provides easy and safe casting in Go.
Package cast provides easy and safe casting in Go.
Package bytefmt contains helper methods and constants for converting to and from a human-readable byte format.
Package bytefmt contains helper methods and constants for converting to and from a human-readable byte format.

Jump to

Keyboard shortcuts

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