File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,9 +16,7 @@ type Buffer struct {
1616}
1717
1818// NewBuffer instance
19- func NewBuffer () * Buffer {
20- return & Buffer {}
21- }
19+ func NewBuffer () * Buffer { return & Buffer {} }
2220
2321// PrintByte to buffer, ignore error. alias of WriteByte()
2422func (b * Buffer ) PrintByte (c byte ) {
@@ -112,16 +110,10 @@ func (b *Buffer) ResetAndGet() string {
112110}
113111
114112// Close buffer
115- func (b * Buffer ) Close () error {
116- return b .CloseErr
117- }
113+ func (b * Buffer ) Close () error { return b .CloseErr }
118114
119115// Flush buffer
120- func (b * Buffer ) Flush () error {
121- return b .FlushErr
122- }
116+ func (b * Buffer ) Flush () error { return b .FlushErr }
123117
124118// Sync anf flush buffer
125- func (b * Buffer ) Sync () error {
126- return b .SyncErr
127- }
119+ func (b * Buffer ) Sync () error { return b .SyncErr }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package maputil
33import "fmt"
44
55// Aliases implemented a simple string alias map.
6+ // - key: alias, value: real name
67type Aliases map [string ]string
78
89// AddAlias to the Aliases
Original file line number Diff line number Diff line change @@ -40,6 +40,11 @@ type ConvOption[T any] struct {
4040 // - if true: will use real type try convert. default is false
4141 // - NOTE: current T type's ptr is default support.
4242 HandlePtr bool
43+ // StrictMode for convert value. default is false
44+ //
45+ // TRUE:
46+ // - to int: string, float will return error
47+ StrictMode bool
4348 // set custom fallback convert func for not supported type.
4449 UserConvFn ToTypeFunc [T ]
4550}
@@ -309,7 +314,7 @@ func StrIntOr(s string, defVal int) int {
309314}
310315
311316/*************************************************************
312- * convert value to int64
317+ * region convert to int64
313318 *************************************************************/
314319
315320// Int64 convert value to int64, return error on failed
Original file line number Diff line number Diff line change @@ -95,10 +95,10 @@ func IContainsOne(s string, subs []string) bool {
9595 return false
9696}
9797
98- // ContainsAll substr(s) in the given string . alias of HasAllSubs()
98+ // ContainsAll given string should contain all substrings . alias of HasAllSubs()
9999func ContainsAll (s string , subs []string ) bool { return HasAllSubs (s , subs ) }
100100
101- // HasAllSubs all substr in the given string.
101+ // HasAllSubs given string should contain all substrings
102102func HasAllSubs (s string , subs []string ) bool {
103103 for _ , sub := range subs {
104104 if ! strings .Contains (s , sub ) {
Original file line number Diff line number Diff line change @@ -75,8 +75,8 @@ func Utf8Width(s string) int { return RunesWidth([]rune(s)) }
7575// str := "hi,你好"
7676//
7777// len(str) // 9
78- // strutil.Utf8Width (str) // 7
79- // len([]rune(str)) = utf8.RuneCountInString(s) // 5
78+ // strutil.RunesWidth (str) // 7 一个中文字占两个字符
79+ // len([]rune(str)) = utf8.RuneCountInString(s) // 5 按字算
8080func RunesWidth (rs []rune ) (w int ) {
8181 if len (rs ) == 0 {
8282 return
Original file line number Diff line number Diff line change @@ -72,6 +72,10 @@ func MockOsEnvByText(envText string, fn func()) {
7272 if line = strings .TrimSpace (line ); line == "" {
7373 continue
7474 }
75+ if line [0 ] == '#' || strings .HasPrefix (line , "//" ) {
76+ continue
77+ }
78+
7579 nodes := strings .SplitN (line , "=" , 2 )
7680 envKey := strings .TrimSpace (nodes [0 ])
7781
@@ -85,11 +89,6 @@ func MockOsEnvByText(envText string, fn func()) {
8589 MockCleanOsEnv (mp , fn )
8690}
8791
88- // MockOsEnv by env map data. alias of MockCleanOsEnv
89- func MockOsEnv (mp map [string ]string , fn func ()) {
90- MockCleanOsEnv (mp , fn )
91- }
92-
9392var envGroupSet = make (map [string ]map [string ]string )
9493
9594// SetOsEnvs by map data with a group key. should call RemoveTmpEnvs after tested.
@@ -153,7 +152,10 @@ func RunOnCleanEnv(runFn func()) {
153152 RevertOSEnv ()
154153}
155154
156- // MockCleanOsEnv by env map data.
155+ // MockOsEnv by input map data. alias of MockCleanOsEnv
156+ func MockOsEnv (mp map [string ]string , fn func ()) { MockCleanOsEnv (mp , fn ) }
157+
158+ // MockCleanOsEnv by input env map data.
157159//
158160// will CLEAR all old ENV data, use given a data map.
159161// will RECOVER old ENV after fn run.
Original file line number Diff line number Diff line change @@ -142,9 +142,7 @@ func SetTimeLocal(tl *time.Location) {
142142}
143143
144144// SetTimeLocalUTC custom time.Local=UTC for testing.
145- func SetTimeLocalUTC () {
146- SetTimeLocal (time .UTC )
147- }
145+ func SetTimeLocalUTC () { SetTimeLocal (time .UTC ) }
148146
149147// RestoreTimeLocal restore time.Local
150148func RestoreTimeLocal () {
You can’t perform that action at this time.
0 commit comments