2019-04-04 01:28:13 +03:00
|
|
|
# golang util library #
|
2018-12-15 20:48:08 +03:00
|
|
|
|
2019-01-21 02:17:20 +03:00
|
|
|
(c) softlandia@gmail.com
|
|
|
|
|
2019-11-26 23:19:00 +03:00
|
|
|
>download: go get -u github.com/softlandia/xlib
|
2019-04-07 00:00:30 +03:00
|
|
|
>install: go install
|
2018-12-15 20:48:08 +03:00
|
|
|
|
2020-02-17 00:12:34 +03:00
|
|
|
## functions ##
|
2019-01-21 02:17:20 +03:00
|
|
|
|
2021-01-23 00:11:25 +03:00
|
|
|
func Secret(s string) string
|
|
|
|
returns a string with the middle removed, "passport" -> "pa...rt"
|
|
|
|
|
|
|
|
func AtoI(s string, def int) int
|
|
|
|
returns int from string, on error return def
|
2020-08-25 15:30:07 +03:00
|
|
|
|
2020-05-18 23:33:44 +03:00
|
|
|
func StrHash(s string) uint32
|
2021-01-23 00:11:25 +03:00
|
|
|
returns 32bit hash from string, using fnv.New32a
|
2020-05-18 23:33:44 +03:00
|
|
|
|
2020-02-17 00:12:34 +03:00
|
|
|
func StrContainBackSlash(s string) bool
|
2021-01-23 00:11:25 +03:00
|
|
|
returns true if string s contain rune back slash '\'
|
2019-01-21 02:17:20 +03:00
|
|
|
|
2020-02-17 00:12:34 +03:00
|
|
|
func StrIsPrintRune(s string) bool
|
2021-01-23 00:11:25 +03:00
|
|
|
returns true if input string contain only of printable rune
|
2019-01-21 02:17:20 +03:00
|
|
|
|
2020-02-17 00:12:34 +03:00
|
|
|
func ChangeFileExt(iFileName, newExt string) string
|
2021-01-23 00:11:25 +03:00
|
|
|
returns file name with new extention
|
2018-12-15 20:48:08 +03:00
|
|
|
|
2020-02-17 00:12:34 +03:00
|
|
|
func FileExists(name string) bool
|
2021-01-23 00:11:25 +03:00
|
|
|
returns true if file exist
|
2019-01-14 19:53:25 +03:00
|
|
|
|
2020-02-17 00:12:34 +03:00
|
|
|
func Max(x, y int) int
|
2021-01-23 00:11:25 +03:00
|
|
|
returns max from int
|
2018-12-15 20:48:08 +03:00
|
|
|
|
2020-02-17 00:12:34 +03:00
|
|
|
func SortBytes(b []byte) []byte
|
2021-01-23 00:11:25 +03:00
|
|
|
returns sorted slice of byte
|
2019-11-26 23:19:00 +03:00
|
|
|
|
|
|
|
func SeekFileStop(fileName, strToSearch string) (int, *bufio.Scanner, error)
|
2020-02-14 20:40:26 +03:00
|
|
|
search string in text file and return *bufio.Scanner at founded line
|
|
|
|
return number of line if string 'strToSearch' founded
|
|
|
|
return scanner on line with string 'strToSearch'. first call scanner.Text() - return this line
|
|
|
|
return (-1, nil, nil) if string 'strToSearch' not founded
|
|
|
|
return (-1, nil, nil) if string 'strToSearch' is empty
|
|
|
|
return (0, nil, err) if file not open or error occure when file reading
|
|
|
|
successfull opened file NOT CLOSED in any case!
|
|
|
|
strToSearch must contain only base ASCII rune
|
2019-04-06 23:59:01 +03:00
|
|
|
|
2019-11-26 23:19:00 +03:00
|
|
|
func FindFilesExt(fileList *[]string, path, fileNameExt string) (int, error)
|
2020-02-14 20:40:26 +03:00
|
|
|
search all files in path with 'ext' & put to slice
|
|
|
|
sample: n, err := FindFilesExt(&fl, "c:\\tmp", ".log")
|
2018-12-15 20:48:08 +03:00
|
|
|
|
2019-08-14 17:55:02 +03:00
|
|
|
## tests ##
|
|
|
|
|
2020-02-17 00:12:34 +03:00
|
|
|
coverage 94%
|
2019-08-14 17:55:02 +03:00
|
|
|
folder "test_files" contain files for testing, no remove/change/add
|