s

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: AFL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	M_NEW    = 1
	M_APPEND = 0
)
View Source
var (

	/* CSTR_EXPECT
	set a str expect input bytes if need input within cmd.
	*/
	CSTR_EXPECT = 0b1000
	CSTR_TYPE   = 0b0100
	CSTR_STDOUT = 0b0001
	CSTR_STDIN  = 0b0010
	/* CSTR_IOINPUT
	set use stdinput if need a input within cmd.
	*/
	CSTR_INTERACT = 0b0011
)
View Source
var (
	ERR_UTF16_TO_UTF8 = "Must have even length byte slice"

	TP_ISO_8859_1 = "ISO-8859-1"
	TP_GB_18030   = "GB-18030"
	TP_BIG_5      = "Big5"
	TP_UTF16      = "UTF-16LE"
	TP_UTF8       = "UTF-8"
)
View Source
var (
	FormatRe            = regexp.MustCompile(`(\{\w+?\})`)
	FileRe              = regexp.MustCompile(`(\@[\\\/\w\.\_\-\(\)\~]+)`)
	ANSI_LINE_UP        = "A"
	ANSI_LINE_DOWN      = "B"
	ANSI_LINE_NEXT_LINE = "E"
	ANSI_LINE_PRE_LINE  = "F"

	ANSI_CURSOR_MOVE        = "H"
	ANSI_CURSOR_SAVE        = "s"
	ANSI_CURSOR_SAVE_DARWIN = "7"

	ANSI_CURSOR_RESTORE        = "u"
	ANSI_CURSOR_RESTORE_DARWIN = "8"

	ANSI_COLUMN_MOVE  = "G"
	ANSI_COLUMN_RIGHT = "C"
	ANSI_COLUMN_LEFT  = "D"

	ANSI_ERASE_ALL_TOEND  = "0J"
	ANSI_ERASE_ALL_BEFORE = "1J"
	ANSI_ERASE_ALL_SCREEN = "2J"

	ANSI_THIS_LINE_ERASE_TOEND  = "0K"
	ANSI_THIS_LINE_ERASE_BEFORE = "1K"
	ANSI_THIS_LINE_ERASE_ALL    = "2K"

	ANSI_STYLE = "m"

	ANSI_STYLE_RESET              = 0
	ANSI_STYLE_BOLD               = 1
	ANSI_STYLE_DIM_FAINT          = 2
	ANSI_STYLE_ITALIC             = 3
	ANSI_STYLE_UNDERLINE          = 4
	ANSI_STYLE_BLINK              = 5
	ANSI_STYLE_REVERSE            = 7
	ANSI_CURSOR_HIDDEN_OR_DISPLAY = 8
	ANSI_STYLE_STRIKELINE         = 9

	FgBlack    = 30
	BGBlack    = 40
	FgRed      = 31
	BgRed      = 41
	FgGreen    = 32
	BgGreen    = 42
	FgYellow   = 33
	FgBgYellow = 43
	FgBlue     = 34
	BgBlue     = 44
	FgMagenta  = 35
	BgMagenta  = 45
	FgCyan     = 36
	BgCyan     = 46
	FgWhite    = 37
	BgWhite    = 47
	FgDefault  = 39
	BgDefault  = 49

	NOT    = 0x10010111
	EXCEPT = 0x10010112
	IN     = 0x10010003
	TO     = 0x10010004
	BEFORE = 0x10011015
	AFTER  = 0x10011016
	FROM   = 0x10010117
	LAST   = 0x10010118
)
View Source
var (
	BAR = Dict[Str, int]{}
)
View Source
var (
	ErrStack = List[error]{}
)
View Source
var (
	INSERT = 0x10011100119
)
View Source
var (
	OPT_SHOW_PROGRESS = 1
)

Functions

func Args

func Args()

func ArgsFromINIStruct added in v1.2.5

func ArgsFromINIStruct(obj interface{})

func AutoEncodeToUTF8 added in v1.3.0

func AutoEncodeToUTF8(output []byte) ([]byte, error)

func Big5ToUtf8 added in v1.3.0

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

convert BIG5 to UTF-8

func ByteMSeq added in v1.3.4

func ByteMSeq(c byte) (next byte)

8 rank m sequence f(x) = x^8 + x^4 + x^3 + x^2 + 1

func GbkToUtf8 added in v1.3.0

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

func IfErrWillFatal added in v1.3.0

func IfErrWillFatal()

func PrintlnStrcut added in v1.2.5

func PrintlnStrcut(obj any)

func ProgressShow

func ProgressShow(percent int, info string)

func SafePop added in v1.3.0

func SafePop[T any](s *List[T], ix ...int) T

func SafePopErr added in v1.3.2

func SafePopErr() (err error)

func SafePushErr added in v1.3.2

func SafePushErr(err error)

func StatusShow

func StatusShow(pre, info string)

func Tr

func Tr(a any) interface{}

func TryAsNumber

func TryAsNumber[num Number](a string) (num, error)

func UTF16ToUTF8 added in v1.3.0

func UTF16ToUTF8(b []byte) ([]byte, error)

func Utf8ToGbk added in v1.3.0

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

Types

type Bytes added in v1.3.3

type Bytes []byte

func MakeBytes added in v1.3.4

func MakeBytes(len int) Bytes

func (Bytes) Bytes added in v1.3.4

func (b Bytes) Bytes() []byte

func (Bytes) Decode added in v1.3.3

func (b Bytes) Decode() Str

func (Bytes) DecodeHex added in v1.3.4

func (b Bytes) DecodeHex() Str

func (Bytes) HXor added in v1.3.4

func (b Bytes) HXor(k Bytes) (db Bytes)

func (Bytes) Hex added in v1.3.4

func (b Bytes) Hex() Str

func (Bytes) Len added in v1.3.3

func (b Bytes) Len() int

func (Bytes) MBytes added in v1.3.4

func (b Bytes) MBytes() Bytes

MBytes return small-m sequence , for every byte in bytes , will use ByteMSeq to generate a new byte

func (Bytes) ToFile added in v1.3.3

func (b Bytes) ToFile(fname Str, mode ...int) error

type CStr added in v1.3.0

type CStr struct {
	Str
	// contains filtered or unexported fields
}

func (CStr) BackgroundCheckRunning added in v1.3.2

func (cstr CStr) BackgroundCheckRunning()

func (CStr) Cd added in v1.3.0

func (cstr CStr) Cd(path any) CStr

func (CStr) DelSelf added in v1.3.4

func (cstr CStr) DelSelf(delay int) CStr

func (CStr) Delay added in v1.3.4

func (cstr CStr) Delay(sec int) CStr

func (CStr) Exec added in v1.3.0

func (cstr CStr) Exec(cmd string, opts ...any) CStr

func (CStr) ExecDaemon added in v1.3.2

func (cstr CStr) ExecDaemon(cmd string, logPath ...string) CStr

func (CStr) GetProcess added in v1.3.2

func (cstr CStr) GetProcess() Dict[int, Str]

func (CStr) Histories added in v1.3.0

func (cstr CStr) Histories() List[Str]

func (CStr) History added in v1.3.0

func (cstr CStr) History(ix ...int) Str

func (CStr) Log added in v1.3.2

func (cstr CStr) Log() CStr

func (CStr) Output added in v1.3.0

func (cstr CStr) Output(ix ...int) Str

func (CStr) Outputs added in v1.3.0

func (cstr CStr) Outputs() List[Str]

func (CStr) Plat added in v1.3.4

func (cstr CStr) Plat() Str

func (CStr) Run added in v1.3.4

func (cstr CStr) Run(opts ...any) CStr

func (CStr) RunDaemon added in v1.3.4

func (cstr CStr) RunDaemon(logPath ...string) CStr

func (CStr) RunningStatus added in v1.3.2

func (cstr CStr) RunningStatus() Dict[Str, bool]

func (CStr) Self added in v1.3.4

func (cstr CStr) Self() Str

type Chars added in v1.3.1

type Chars List[byte]

func (Chars) Join added in v1.3.1

func (self Chars) Join(a rune) Str

type Dict

type Dict[K comparable, T any] map[K]T

func FromIni

func FromIni(content Str) Dict[Str, any]

func (Dict[K, T]) Any added in v1.3.2

func (d Dict[K, T]) Any(comkey func(k K, v T) bool) (outk K, outv T, found bool)

func (Dict[K, T]) AsIniStr

func (dict Dict[K, T]) AsIniStr(tmp, sep Str, sec ...Str) Str

func (Dict[K, T]) AsStr

func (dict Dict[K, T]) AsStr(tmp, sep Str, sec ...Str) (Str, error)

func (Dict[K, T]) DecodeAsStruct added in v1.2.5

func (self Dict[K, T]) DecodeAsStruct(obj interface{})

func (Dict[K, T]) Each

func (d Dict[K, T]) Each(do func(k K, v T)) Dict[K, T]

func (Dict[K, T]) EveryWith

func (d Dict[K, T]) EveryWith(do func(k K, v T) T) Dict[K, T]

func (Dict[k, T]) Json

func (d Dict[k, T]) Json() (Str, error)

func (Dict[K, T]) Keys

func (d Dict[K, T]) Keys() List[K]

func (Dict[K, T]) Len added in v1.3.4

func (d Dict[K, T]) Len() int

func (Dict[k, T]) Values

func (d Dict[k, T]) Values() List[T]

type EStr added in v1.2.4

type EStr struct {
	Str
	Start int
	End   int
	Next  int
}

func (EStr) String added in v1.2.4

func (self EStr) String() string

type InsertFunc added in v1.2.4

type InsertFunc func(ex EStr) Str

type List

type List[T any] []T

func SafePush added in v1.3.0

func SafePush[T any](s *List[T], o T) *List[T]

func (List[T]) Any added in v1.3.2

func (s List[T]) Any(key func(i int, v T) bool) (out T, found bool)

func (List[T]) Count

func (s List[T]) Count(b T, eq func(a, v T) bool) int

func (List[T]) Each

func (s List[T]) Each(do func(i int, item T), asyncNum ...int) List[T]

func (List[T]) EveryWith

func (s List[T]) EveryWith(do func(i int, item T) T) List[T]

func (List[T]) Filter

func (s List[T]) Filter(filterFunc func(i int, item T) bool) (nl List[T])

func (List[T]) Has

func (s List[T]) Has(b T, eq func(a, b T) bool) bool

func (List[T]) Index

func (s List[T]) Index(body T, eq func(a, b T) bool) (ix int)

func (List[T]) Join

func (s List[T]) Join(sepIfNoIsSpace ...string) Str

func (List[T]) Last

func (s List[T]) Last() T

func (List[T]) Len

func (s List[T]) Len() int

func (List[T]) MapWith

func (s List[T]) MapWith(do func(i int, item T) any) (mp Dict[Str, any])

func (List[T]) Pop

func (s List[T]) Pop(ix ...int) T

func (List[T]) Push

func (s List[T]) Push(body T) List[T]

func (List[T]) Reverse

func (s List[T]) Reverse() (nl List[T])

func (List[T]) S added in v1.3.2

func (s List[T]) S(start int, end ...int) List[T]

short of Slice

func (List[T]) Slice added in v1.3.2

func (s List[T]) Slice(start int, end ...int) List[T]

Slice extract sub slice

func (List[T]) Sort

func (s List[T]) Sort(compareFunc ...func(a T, b T) bool) List[T]

func (List[T]) Uniq added in v1.3.4

func (s List[T]) Uniq() (uq List[T])

type Number

type Number interface {
	int32 | float32 | float64 | int64
}

type Pip added in v1.3.4

type Pip struct {
	Reader  io.Reader
	Writeer io.Writer
	Size    int64
	// contains filtered or unexported fields
}

func AsPip added in v1.3.4

func AsPip(raw any, size ...int64) *Pip

func (*Pip) Close added in v1.3.4

func (pip *Pip) Close() error

func (*Pip) Copy added in v1.3.4

func (p *Pip) Copy(dst any, showProgressOrTmp ...any) (*Pip, error)

func (*Pip) CopyBuffer added in v1.3.4

func (pip *Pip) CopyBuffer(dst io.Writer, src io.Reader, buf []byte, intervalFunc func(usedSec float64, written int64, finish bool)) (written int64, err error)

func (*Pip) Pipe added in v1.3.4

func (pip *Pip) Pipe(other io.ReadWriter, showProgress ...any) error

func (*Pip) Read added in v1.3.4

func (pip *Pip) Read(buf []byte) (readed int, err error)

func (*Pip) Write added in v1.3.4

func (pip *Pip) Write(buf []byte) (written int, err error)

type RWeader added in v1.3.0

type RWeader struct {
	S chan []byte
	// contains filtered or unexported fields
}

func NewTmpRWer added in v1.3.0

func NewTmpRWer(n int) *RWeader

func (*RWeader) Close added in v1.3.0

func (rw *RWeader) Close() error

func (*RWeader) Read added in v1.3.0

func (rw *RWeader) Read(buf []byte) (n int, err error)

func (*RWeader) Write added in v1.3.0

func (rw *RWeader) Write(buf []byte) (n int, err error)

type SchedulTask added in v1.3.4

type SchedulTask struct {
	Tn  Str `ini:"tn" def:"task-name"` // 计划任务的计划名
	Cmd Str `ini:"task-body"`          // 计划任务的 命令本体
	Sc  Str `ini:"sc" def:"DAILY"`     // 指定计划类型。有效值为 MINUTE、HOURLY、DAILY、WEEKLY、MONTHLY、ONCE、ONSTART、ONLOGON、ONIDLE。
	Mo  int `ini:"mo" def:"1"`         // 计划任务
}

type Str

type Str string

func AutoDecode added in v1.3.0

func AutoDecode(fromBytes []byte) (utfStr Str, err error)

func FromStructToINIStr added in v1.2.5

func FromStructToINIStr(obj any) Str

func RandomStr added in v1.3.4

func RandomStr(i int) Str

func Sprintf added in v1.2.5

func Sprintf(tmp string, obj ...any) Str

func (Str) A added in v1.2.5

func (self Str) A(a any) Str

A append in end

func (Str) ANSI

func (self Str) ANSI(ANSI_FUNC_C string, ANSI_ARGS ...int) Str
func (self Str) ANSIBlink() Str

func (Str) ANSIBlue

func (self Str) ANSIBlue() Str

func (Str) ANSIBold

func (self Str) ANSIBold() Str

func (Str) ANSIClearThisLine

func (self Str) ANSIClearThisLine() Str

func (Str) ANSICursor

func (self Str) ANSICursor(line, column int) Str

func (Str) ANSICyan added in v1.2.5

func (self Str) ANSICyan() Str

func (Str) ANSIDimFaint added in v1.3.4

func (self Str) ANSIDimFaint() Str

func (Str) ANSIEraseALL

func (self Str) ANSIEraseALL() Str

func (Str) ANSIEraseToEND

func (self Str) ANSIEraseToEND() Str

func (Str) ANSIGreen

func (self Str) ANSIGreen() Str

func (Str) ANSIHideOrDisCursor

func (self Str) ANSIHideOrDisCursor() Str

func (Str) ANSIItalic added in v1.2.5

func (self Str) ANSIItalic() Str

func (Str) ANSIMagenta added in v1.2.5

func (self Str) ANSIMagenta() Str

func (Str) ANSIPreLine

func (self Str) ANSIPreLine() Str

func (Str) ANSIRandomBeautiful added in v1.3.4

func (self Str) ANSIRandomBeautiful() Str

func (Str) ANSIRed added in v1.2.5

func (self Str) ANSIRed() Str

func (Str) ANSIReset added in v1.3.4

func (self Str) ANSIReset() Str

func (Str) ANSIRestore

func (self Str) ANSIRestore() Str

func (Str) ANSISave

func (self Str) ANSISave() Str

func (Str) ANSISelected

func (self Str) ANSISelected() Str

func (Str) ANSIStrike added in v1.2.5

func (self Str) ANSIStrike() Str

func (Str) ANSIStyle

func (self Str) ANSIStyle(ansiColorCode ...int) Str

func (Str) ANSIUnderline

func (self Str) ANSIUnderline() Str

func (Str) ANSIYellow

func (self Str) ANSIYellow() Str

func (Str) AsCharacters added in v1.3.1

func (self Str) AsCharacters() Chars

func (Str) AsCmd added in v1.3.0

func (str Str) AsCmd(cdPath ...any) CStr

func (Str) AsInput added in v1.3.0

func (self Str) AsInput() Str

func (Str) BarPrint added in v1.3.4

func (self Str) BarPrint(tag Str) Str

func (Str) BarShowSize added in v1.3.4

func (self Str) BarShowSize(tag Str, usedSec float64, size int64, finish bool, allSize ...int64) Str
BarShowSize

use {key} {speed} {size} example : Str("[{key}] : speed : {speed} | size : {size} "

func (Str) Copy

func (self Str) Copy() Str

func (Str) Count

func (self Str) Count(sub string) int

func (Str) Cut2

func (self Str) Cut2(by string) (left, right Str)

func (Str) Cut3

func (self Str) Cut3(by string) (left, mid, right Str)

func (Str) Edit added in v1.2.4

func (self Str) Edit(limit ...any) Str

Edit(s.IN, 'xxx', 'xxxend', func(ex ExStr) Str{})

func (Str) Encode

func (self Str) Encode() Bytes

func (Str) EndWith

func (self Str) EndWith(s string) bool

func (Str) Eq

func (self Str) Eq(other string) bool

func (Str) Extract

func (self Str) Extract(pre string, ends ...string) (ex List[EStr])

func (Str) ExtractQuote

func (self Str) ExtractQuote() (ex List[EStr])

func (Str) FileExists added in v1.3.0

func (self Str) FileExists() bool

func (Str) FileList added in v1.3.0

func (self Str) FileList() List[Str]

func (Str) FilePathJoin added in v1.3.0

func (self Str) FilePathJoin(otherPaths ...any) Str

func (Str) Format

func (self Str) Format(args Dict[Str, any]) (n Str)

func (Str) HXorHex added in v1.3.4

func (self Str) HXorHex(k string) (hexS Str)

func (Str) Has

func (self Str) Has(s string, limit ...any) bool

func (Str) Hex

func (self Str) Hex(key ...string) Str

func (Str) Index

func (self Str) Index(key string, fromLast ...bool) int

func (Str) Insert added in v1.2.4

func (self Str) Insert(content string, condss ...any) Str

func (Str) IsDir added in v1.3.0

func (self Str) IsDir() bool

func (Str) IsFile added in v1.3.0

func (self Str) IsFile() bool

func (Str) Join

func (self Str) Join(lst ...any) Str

func (Str) LastChar

func (self Str) LastChar() string

func (Str) Len

func (self Str) Len() int

func (Str) OpenAsReader added in v1.3.4

func (self Str) OpenAsReader() *Pip

func (Str) OpenAsWriter added in v1.3.4

func (self Str) OpenAsWriter(opt ...int) *Pip

func (Str) P added in v1.2.5

func (self Str) P(a any) Str

P prepend in start

func (Str) ParseAsArgument

func (self Str) ParseAsArgument() (args List[Str], kargs Dict[Str, Str])

func (Str) ParseAsIniArg added in v1.2.5

func (self Str) ParseAsIniArg() (kargs Dict[Str, any])

func (Str) ParseFileContent

func (self Str) ParseFileContent() Str

func (Str) ParseHex

func (self Str) ParseHex(key ...string) []byte

func (Str) Pre

func (self Str) Pre(s string) Str

func (Str) Print

func (self Str) Print(pre ...any) Str

func (Str) Printf

func (self Str) Printf(tmp string) Str

func (Str) Println

func (self Str) Println(pre ...any) Str

func (Str) ReFindAll added in v1.3.0

func (self Str) ReFindAll(rex string) (ss List[Str])

func (Str) ReMatch added in v1.3.0

func (self Str) ReMatch(rex string) bool

func (Str) Remove

func (self Str) Remove(c string) Str

func (Str) Replace

func (self Str) Replace(i, e string, skip ...string) Str

func (Str) Split

func (self Str) Split(s ...string) (ss List[Str])

func (Str) SplitQuote

func (self Str) SplitQuote(by string, num int, quotes ...string) (ss List[Str])

func (Str) StartWith

func (self Str) StartWith(s string) bool

func (Str) StatusBar

func (self Str) StatusBar(pre string) Str

func (Str) String

func (self Str) String() string

func (Str) Strip

func (self Str) Strip() Str

func (Str) SubStr

func (self Str) SubStr(limit ...any) Str
SubStr

select sub str :

// 筛选 从 。。。 到 。。。。。
x.SubStr(s.FROM, "<div>",s.TO, "</div>")
// 更详细的选项有 第几个 或者最后一个如
// 从第二个 <div> 到 最后一个  </div>
x.SubStr(x.FROM , 2, "<div>", s.TO, s.LAST, "</div>")

func (Str) Trim

func (self Str) Trim(pre string, reverse ...bool) Str

func (Str) TryAsFloat

func (self Str) TryAsFloat() (float64, error)

func (Str) TryAsInt

func (self Str) TryAsInt() (int, error)

func (Str) TryAsJson

func (self Str) TryAsJson(buildStruct *interface{}) (Dict[string, any], error)

func (Str) Words added in v1.3.4

func (self Str) Words() (wl List[Str])

Jump to

Keyboard shortcuts

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