Documentation
¶
Overview ¶
/ +build OMIT
csvfunc.go
Index ¶
- Constants
- func AppendAt(slice []string, pos int, insert ...string) []string
- func BaseNoExt(filename string) (outFilename string)
- func BinFilesToHexFile(outFilename string, assets []VarFile, doBackup bool) (err error)
- func BinToHexString(filename string) (outString string, err error)
- func Bpcheck(val1, val2 int, pos ...int)
- func ByteCountBinary(b int64) string
- func ByteCountDecimal(b int64) string
- func ByteToHexStr(bytes []byte) string
- func CharsetToUtf8(str string) string
- func Check(err error, message ...string) (state bool)
- func CheckCmd(cmd string) bool
- func CheckE(err error, message ...string)
- func CheckForDupSl2d(sl [][]string) bool
- func CheckMime(filename string) (mime string, err error)
- func CmpRemSl2d(sl1, sl2 [][]string) (outSlice [][]string)
- func CopyFile(inFile, outFile string, doBackup ...bool) (err error)
- func CreateTarballGzip(tarballFilePath string, filePaths []string, compressLvl int) (countedWrittenFiles int, err error)
- func CreateTarballXz(tarballFilePath string, filePaths []string, compressLvl int) (countedWrittenFiles int, err error)
- func DeleteSl(slice []string, pos int) []string
- func DeleteSl1(slice []string, pos int) []string
- func DetectCharsetFile(filename string) (name string)
- func DetectCharsetStr(inputStr string) (name string)
- func DispRights(value int)
- func ExecCommand(commands string, args ...string) (output []byte, err error)
- func ExtEnsure(filename, ext string) (outFilename string)
- func FileCharsetSwitch(inCharset, outCharset, inFilename string, outFilename ...string)
- func FileExist(name string) bool
- func FindDate(inputString, fmtDate string) []string
- func FindDir(dir, mask string, returnedStrSlice *[][]string, ...) error
- func FormatDate(fmtDate string, inpDate string) time.Time
- func FormatText(str string, max int, truncateWordOverMaxSize bool, indenT ...string) string
- func FormatTextParagraphFormatting(str string, max int, truncateWordOverMaxSize bool, indentFirstLinetr ...string) string
- func FormatTextQuoteBlankLines(str string) (out string)
- func GenFileName() string
- func GenericReader(filename string) (io.Reader, *os.File, error)
- func GetCurrentDir() (dir string, err error)
- func GetFileBytesString(filename string, from, to int) (outString string)
- func GetFileEOL(filename string) (outString string, err error)
- func GetFileMime(filename string) string
- func GetOsLineEnd() string
- func GetOsPathSep() string
- func GetSep(str string) []string
- func GetStdin(ask string) (input string)
- func GetStrIndex(slice []string, item string) int
- func GetStrIndex2dCol(slice [][]string, value string, col int) int
- func GetTextEOL(inTextBytes []byte) (outString string)
- func GetUser() (realUser, currentUser *user.User, err error)
- func GoFormatting(filename string)
- func Gzip(source, target string) error
- func HexToBytes(varPath string, gzipData []byte) (outByte []byte)
- func Increment(inSL []string, separator string, startAt int, atLeft ...bool) (outSL []string)
- func IsDate(inString string) bool
- func IsDirEmpty(name string) (empty bool, err error)
- func IsError(err error) bool
- func IsExist2d(slice [][]string, cmpRow []string) bool
- func IsExist2dCol(slice [][]string, value string, col int) bool
- func IsExistSl(slice []string, item string) bool
- func IsFloat(inString string) bool
- func IsTextFile(filename string) (fileType string, err error)
- func JsonRead(filename string, interf interface{}) (err error)
- func JsonWrite(filename string, interf interface{}) (err error)
- func LinesToTextFile(filename string, values interface{}) error
- func Lorem(wordCount ...int) string
- func LoremGenerateTextFile(filename string, maxWords, maxChars int) error
- func LowercaseAtFirst(inString string) bool
- func Md5String(inString string) string
- func Md5Sum(filename string) string
- func NewDateFormat() []string
- func Preppend(slice []string, prepend ...string) []string
- func ReadCsv(filename, comma string, fields, startLine int, endLine ...int) (records [][]string, err error)
- func ReadFile(filename string) (data []byte, err error)
- func RecurseScanSymlink(path, linkEndPoint string) (fileList []string, err error)
- func RemoveDupSl(slice []string) []string
- func RemoveDupSl2d(slice [][]string, col int) (outSlice [][]string)
- func RemoveNonAlNum(inString string) string
- func RemoveNonNum(inString string) string
- func RemoveSpace(inString string) string
- func ReplacePunct(inString string) string
- func ReplaceSpace(inString string) string
- func ScanDir(root string, showDirs ...bool) (files []string, err error)
- func ScanDirDepth(root string, depth int, showDirs ...bool) (files []string, err error)
- func ScanFile(file string) (fi fileInfos)
- func ScanFiles(inFiles []string) (outFiles []fileInfos)
- func ScanSubDir(root string, showDirs ...bool) (files []string, err error)
- func SearchSl(find string, table [][]string, ...) (out [][]string, err error)
- func SetFileEOL(filename, eol string) error
- func SetTextEOL(inTextBytes []byte, eol string) (outTextBytes []byte, err error)
- func SliceSortDate(slice [][]string, fmtDate string, dateCol, secDateCol int, ascendant bool) [][]string
- func SliceSortFloat(slice [][]string, col int, ascendant bool, decimalChar string)
- func SliceSortString(slice [][]string, col int, ascendant, caseSensitive, numbered bool)
- func SplitAtEOL(data []byte) (outSlice []string)
- func SplitNumeric(inString string) (outText []string, err error)
- func StringDecimalSwitchFloat(decimalChar, inString string) float64
- func StringToCharacterClasses(inpString string, caseSensitive, strictMode bool) (outString string)
- func Tar(source, target string) error
- func TempMake(prefix string) string
- func TempRemove(fName string) (err error)
- func TextFileToLines(filename string, opt ...string) (stringsText []string, err error)
- func TimeStamp() *timeStamp
- func ToCamel(inString string, lowerAtFirst ...bool) (outString string)
- func TrimSpace(inputString string, cmds ...string) (newstring string, err error)
- func TruncatePath(fullpath string, count ...int) (reduced string)
- func TruncateString(inString, prefix string, max, option int) string
- func UnGzip(source, target string) error
- func Untar(tarball, target string) error
- func UntarGzip(sourcefile, dst string, filesList *[]string, removeDir bool) (countedWrittenFiles int, err error)
- func UrlsGet(inString string) []string
- func Use(vals ...interface{})
- func WordsFrequency(text string) (list [][]string)
- func WriteCsv(filename, comma string, rows [][]string) error
- func WriteFile(filename string, datas []byte, doBackup ...bool) (err error)
- func WriteTextFile(filename, data string, appendIfExist ...bool) error
- func Zip(source, target string) error
- type Bench
- type CharsetList
- type DateEntry
- type Filepath
- type Find_s
- type GoDeclarations
- type Pos_s
- type Process
- type RowStore
- type Search
- func (toFind *Search) Find(root string) (files []string, err error)
- func (toFind *Search) FindDepth(root string, depth int) (files []string, err error)
- func (toFind *Search) FindDepthTest(root string, depth int) (files []string, err error)
- func (s *Search) SearchAdd(searchFor, wWord, logicalOp string)
- func (s *Search) SearchCompile()
- func (s *Search) SearchInAdd(searchIn string)
- type StringWriter
- type UnixProcess
- type VarFile
- type WordWithDigit
Constants ¶
const ( OS_READ = 04 OS_WRITE = 02 OS_EX = 01 OS_USER_SHIFT = 6 OS_GROUP_SHIFT = 3 OS_OTH_SHIFT = 0 OS_USER_R = OS_READ << OS_USER_SHIFT OS_USER_W = OS_WRITE << OS_USER_SHIFT OS_USER_X = OS_EX << OS_USER_SHIFT OS_USER_RW = OS_USER_R | OS_USER_W OS_USER_RWX = OS_USER_RW | OS_USER_X OS_GROUP_R = OS_READ << OS_GROUP_SHIFT OS_GROUP_W = OS_WRITE << OS_GROUP_SHIFT OS_GROUP_X = OS_EX << OS_GROUP_SHIFT OS_GROUP_RW = OS_GROUP_R | OS_GROUP_W OS_GROUP_RWX = OS_GROUP_RW | OS_GROUP_X OS_OTH_R = OS_READ << OS_OTH_SHIFT OS_OTH_W = OS_WRITE << OS_OTH_SHIFT OS_OTH_X = OS_EX << OS_OTH_SHIFT OS_OTH_RW = OS_OTH_R | OS_OTH_W OS_OTH_RWX = OS_OTH_RW | OS_OTH_X OS_ALL_R = OS_USER_R | OS_GROUP_R | OS_OTH_R OS_ALL_W = OS_USER_W | OS_GROUP_W | OS_OTH_W OS_ALL_X = OS_USER_X | OS_GROUP_X | OS_OTH_X OS_ALL_RW = OS_ALL_R | OS_ALL_W OS_ALL_RWX = OS_ALL_RW | OS_ALL_X )
Const for FileMode
Usage to Create any directories needed to put this file in them:
var dir_file_mode os.FileMode
dir_file_mode = os.ModeDir | (OS_USER_RWX | OS_ALL_R)
os.MkdirAll(dir_str, dir_file_mode)
fmt.Printf("%o\n%o\n%o\n%o\n",
os.ModePerm&OS_ALL_RWX,
os.ModePerm&OS_USER_RW|OS_GROUP_R|OS_OTH_R,
os.ModePerm&OS_USER_RW|OS_GROUP_RW|OS_OTH_R,
os.ModePerm&OS_USER_RWX|OS_GROUP_RWX|OS_OTH_R)
Variables ¶
This section is empty.
Functions ¶
func BinFilesToHexFile ¶
BinFilesToHexFile: Convert binary files to gzipped []byte in specific file. Much faster than the previous version that only deals with one file at a time.
func BinToHexString ¶
BinToHex: Convert binary file to gzipped []byte
func ByteCountBinary ¶
ByteCountBinary: Format byte size to human readable format
func ByteCountDecimal ¶
ByteCountDecimal: Format byte size to human readable format
func ByteToHexStr ¶
ByteToHexStr: Convert []byte to hexString
func CharsetToUtf8 ¶
Get charset and convert to utf-8 if needed
func Check ¶
Check: Display error messages in HR version with onClickJump enabled in my favourite Golang IDE editor. Return true if error exist.
func CheckE ¶
Check error function, and exit if error, input message is optional or accept multiple arguments.
func CheckForDupSl2d ¶
CheckForDupSl2d: Return true if duplicated row is found
func CmpRemSl2d ¶
CmpRemSl2d: Compare slice1 and slice2 if row exist on both, the raw is removed from slice2 and result returned.
func CreateTarballGzip ¶
func CreateTarballGzip(tarballFilePath string, filePaths []string, compressLvl int) (countedWrittenFiles int, err error)
CreateTarball: create tar.gz file from given filenames. -2 = HuffmanOnly (linear compression, low gain, fast compression) -1 = DefaultCompression
0 = NoCompression 1 -> 9 = BestSpeed -> BestCompression
func CreateTarballXz ¶
func CreateTarballXz(tarballFilePath string, filePaths []string, compressLvl int) (countedWrittenFiles int, err error)
CreateTarballLXz: create tar.xz file from given filenames. Just for fun test ... but it's really slow, no multi-threading and low size gain.
func DetectCharsetFile ¶
Detect encoding type for files
func DetectCharsetStr ¶
Detect encoding type for strings
func DispRights ¶
func DispRights(value int)
DispRights: display right. i.e: g.DispRights(g.OS_USER_RWX | g.OS_GROUP_RWX | g.OS_OTH_R)
func ExecCommand ¶
ExecCommand: launch commandline application with arguments return output and error.
func FileCharsetSwitch ¶
Change charset of a text file
func FindDate ¶
Find the date in relation to the given format. (French format like %d, %m, %y or Y%). input fmtDate: "%d-%m-%y %H:%M:%S"
func FindDir ¶
func FindDir(dir, mask string, returnedStrSlice *[][]string, scanSub, showDir, followSymlinkDir bool) error
FindDir retrieve file in a specific directory with more options.
func FormatDate ¶
Change date format to unix model with pattern like: fmtDate:='%d-%m-%y %H:%M:%S' --> '$y-%m-%d %H:%M:%S' Note: year format must be in lowercase ...
func FormatText ¶
FormatText: Format words text to fit (column/windows with limited width) "max" chars. An unwanted behavior may occur on string where word's length > max...
func FormatTextParagraphFormatting ¶
func FormatTextParagraphFormatting(str string, max int, truncateWordOverMaxSize bool, indentFirstLinetr ...string) string
FormatTextParagraphFormatting:
func FormatTextQuoteBlankLines ¶
An unwanted behavior may occur on string where word's length > max...
func GenericReader ¶
GenericReader: return io.reader for standar files and .bz2, gz.
func GetCurrentDir ¶
GetCurrentDir: Get current directory
func GetFileBytesString ¶
GetFileBytesString: Retrieve 'from' 'to' bytes from file in string format.
func GetFileEOL ¶
GetFileEOL: Open file and get (CR, LF, CRLF) > string or get OS line end.
func GetFileMime ¶
GetFileMime: scan first bytes to detect mime type of file.
func GetStrIndex ¶
GetStrIndex: Get index of a string in a slice, Return -1 if no entry found ...
func GetStrIndex2dCol ¶
GetStrIndex2dCol: Search in 2d string slice if a column's value exist and return row number.
func GetTextEOL ¶
GetTextEOL: Get EOL from text bytes (CR, LF, CRLF) > string or get OS line end.
func GoFormatting ¶
func GoFormatting(filename string)
goFormatting: Format output file using gofmt function.
func HexToBytes ¶
HexToBytes: Convert Gzip Hex to []byte used for embedded binary in source code
func IsExist2dCol ¶
IsExist2dCol: Search in 2d string slice if a column's value exist.
func IsTextFile ¶
IsTextFile: check for first 512 bytes if they contains some bytes usually present in utf-32, utf-16 or ascii/utf-8 files. Return detected type, including binary.
func JsonRead ¶
JsonRead: datas from file to given interface / structure i.e: err := ReadJson(filename, &person) remember to put upper char at left of variables names to be saved.
func JsonWrite ¶
JsonWrite: datas to file from given interface / structure i.e: err := WriteJson(filename, &person) remember to put upper char at left of variables names to be saved.
func LinesToTextFile ¶
Write slice to file
func LoremGenerateTextFile ¶
Generate Lorem Ipsum texte file
func LowercaseAtFirst ¶
LowercaseAtFirst: true if 1st char is lowercase
func NewDateFormat ¶
func NewDateFormat() []string
func ReadCsv ¶
func ReadCsv(filename, comma string, fields, startLine int, endLine ...int) (records [][]string, err error)
Read data from CSV file
func RecurseScanSymlink ¶
Scan dir and subdir to get symlinks with specified endpoint.
func RemoveDupSl ¶
RemoveDupSl: Remove duplicate entry in a string slice TODO rewrite this function using "reflect.DeepEqual"... on next use
func RemoveDupSl2d ¶
RemoveDupSl2d: Remove duplicate entry in a 2d string slice based on column number content. TODO rewrite this function using "reflect.DeepEqual"... on next use
func RemoveNonAlNum ¶
RemoveNonAlNum: Remove all non alpha-numeric char
func RemoveNonNum ¶
RemoveNonNum: Remove all non numeric char
func RemoveSpace ¶
ReplaceSpace: replace all [[:space::]] with underscore "_"
func ReplacePunct ¶
ReplacePunct: replace all [[:punct::]] with underscore "_"
func ReplaceSpace ¶
ReplaceSpace: replace all [[:space::]] with underscore "_"
func ScanDirDepth ¶
ScanSubDir retrieve files in a specific directory and his sub-directory depending on depth argument. depth = -1 mean infinite.
func ScanFile ¶
func ScanFile(file string) (fi fileInfos)
ScanFile: Scan a file and retreive informations about it stored in a fileInfos structure.
func ScanFiles ¶
func ScanFiles(inFiles []string) (outFiles []fileInfos)
ScanFiles: Scan given files and retreive informations about them stored in a []fileInfos structure.
func ScanSubDir ¶
ScanSubDir retrieve files in a specific directory and his sub-directory. don't follow symlink (walk)
func SearchSl ¶
func SearchSl(find string, table [][]string, caseSensitive, POSIXcharClass, POSIXstrictMode, regex, wholeWord bool) (out [][]string, err error)
SearchSl: Search in 2d string slice. cs=case sensitive, ww=whole word, rx=regex
func SetFileEOL ¶
SetFileEOL: Open file and convert EOL (CR, LF, CRLF) then write it back.
func SetTextEOL ¶
SetTextEOL: Get EOL from text bytes and convert it to another EOL (CR, LF, CRLF)
func SliceSortDate ¶
func SliceSortDate(slice [][]string, fmtDate string, dateCol, secDateCol int, ascendant bool) [][]string
SliceSortDate: Sort 2d string slice with date inside
func SliceSortFloat ¶
SliceSortFloat: Sort 2d string with float value
func SliceSortString ¶
SliceSortString: Sort 2d string slice
func SplitNumeric ¶
SplitNumeric: Split and keep all numeric values in a string
func StringDecimalSwitchFloat ¶
Convert comma to dot if needed and return 0 if input string is empty.
func StringToCharacterClasses ¶
Convert string to character classes equivalent's string
func TempRemove ¶
TempRemove: Remove directory recursively
func TextFileToLines ¶
Load text file to slice, opt are same as TrimSpace function "-c, -s, +& or -&" and can be cumulative. This function Reconize "CR", "LF", "CRLF", and convert charset to utf-8
func TrimSpace ¶
TrimSpace: Some multiple way to trim strings. cmds is optionnal or accept multiples args
func TruncatePath ¶
ReducePath: Reduce patch length by preserving count element from the end
func TruncateString ¶
TruncateString: Reduce string length for display (prefix is separator like: "...", option=0 -> put separator at the begening of output string. Option=1 -> center, is where separation is placed. option=2 -> line feed, trunc the whole string using LF without shorting it. Max, is max char length of the output string.
func UntarGzip ¶
func UntarGzip(sourcefile, dst string, filesList *[]string, removeDir bool) (countedWrittenFiles int, err error)
UntarGzip: unpack tar.gz files list. Return len(filesList)=0 if all files has been restored. removeDir mean that, before restore folder content, the existing dir will be removed.
func WordsFrequency ¶
WordsFrequency: Counts the frequency with which words appear in a text.
func WriteTextFile ¶
Write string to file low lvl format
Types ¶
type Bench ¶
type Bench struct {
Results []string
Average string
Display bool
// contains filtered or unexported fields
}
Measuring lapse (may be multiples) between operations
type CharsetList ¶
func NewCharsetList ¶
func NewCharsetList() CharsetList
func (*CharsetList) GetCharset ¶
func (cl *CharsetList) GetCharset(pos int) (chLong, chShort string)
func (*CharsetList) GetPos ¶
func (cl *CharsetList) GetPos(ch string) (posLong, posShort int)
func (*CharsetList) Init ¶
func (cl *CharsetList) Init()
type Filepath ¶
type Filepath struct {
Absolute string
Relative string
Path string
Base string
BaseNoExt string
Ext string
ExecFullName string
RealPath string
RealName string
OutputNewExt string
OutputAppendFilename string
OsSeparator string
IsDir bool
SymLink bool
SymLinkTo string
}
File struct (SplitFilePath)
func SplitFilepath ¶
Split full filename into path, ext, name, ... optionally add suffix before original extension or change extension Relative: SplitFilepath("wanted relative path", fullpath).Relative Absolute: SplitFilepath("relative path", fullpath).Absolute
type Find_s ¶
type Find_s struct {
TextBytes []byte
FileName string
LineEnd string
ToSearch string
ReplaceWith string
CaseSensitive bool
UseEscapeChar bool
POSIXcharClass bool
POSIXstrictMode bool
Regex bool
Wildcard bool
WholeWord bool
DoReplace bool
Positions Pos_s
}
func SearchAndReplaceInMultipleFiles ¶
func SearchAndReplaceInMultipleFiles(filenames []string, toSearch, replaceWith string, caseSensitive, POSIXcharClass, POSIXstrictMode, regex, wildcard, useEscapeChar, wholeWord, doReplace, doSave, doBackup, acceptBinary, removeEmptyResult bool) (founds []Find_s, err error)
Search in multiples text files , using "the Find_s struct" to fill needed informations about search preferences. return a slice type []Find_s that contain all informations about found patterns. Output can be saved with backup option.
func (*Find_s) SearchAndReplace ¶
Search in plain text, use "the Find_s struct" to fill needed informations about search preferences. return a structure type Find_s that contain all informations about found patterns in the text
type GoDeclarations ¶
type GoDeclarations struct {
Filename string
PackageName string
Functions []storeDecl
FunctNoComment []storeDecl
FullFunc []storeDecl
Types []storeDecl
TypesNoComment []storeDecl
Imports []storeDecl
FoundRows []storeDecl
// contains filtered or unexported fields
}
func (*GoDeclarations) GoSourceGetInfos ¶
func (d *GoDeclarations) GoSourceGetInfos(filename string, funcName ...string) (err error)
getPackageName: retrieve package name of Go source file
func (*GoDeclarations) GoSourceGetLines ¶
func (d *GoDeclarations) GoSourceGetLines(filename string, wholeWord bool, terms ...string) (exist bool, err error)
getPackageName: retrieve package name of Go source file
type Process ¶
type Process interface {
// Pid is the process ID for this process.
Pid() int
// PPid is the parent process ID for this process.
PPid() int
// Executable name running this process. This is not a path to the
// executable.
Executable() string
}
Process is the generic interface that is implemented on every platform and provides common operations for processes.
func FindProcess ¶
FindProcess looks up a single process by pid.
Process will be nil and error will be nil if a matching process is not found.
func Processes ¶
Processes returns all processes.
This of course will be a point-in-time snapshot of when this method was called. Some operating systems don't provide snapshot capability of the process table, in which case the process table returned might contain ephemeral entities that happened to be running when this was called.
type RowStore ¶
func AppendIfMissing ¶
Append to slice if not already exist (RowStore version)
func AppendIfMissingC ¶
Append to slice if RowStore.cnt value does not already exist (Quote version)
func FindCountStr ¶
Get count of non alphanum chars in a string in struct(RowStore) format
type Search ¶
type Search struct {
BrowsedFiles int
Ready bool
SearchTime searchTime
ShowDir bool
CaseSensitive bool
POSIXcharClass bool
POSIXstrictMode bool
Regex bool
UseEscapeChar bool
Wildcard bool
WholeWord bool
Type searchType
// contains filtered or unexported fields
}
func (*Search) Find ¶
Find: Search for file in dir all subdir. Equal performances between this one and the (Depth) version This function get parameter from a Search structure which contain all search options.
func (*Search) FindDepth ¶
FindDepth: Search for file in dir and subdir depending on depth argument. depth = -1 mean infinite. This function get parameter from a Search structure which contain all search options.
func (*Search) FindDepthTest ¶
FindDepth: Search for file in dir and subdir depending on depth argument. depth = -1 mean infinite. This function get parameter from a Search structure which contain all search options.
func (*Search) SearchAdd ¶
SearchAdd: Adding entry to be searched. Format: "wordToFind", "w", "&" "w", "", mean WholeWord or no. "&", "|", "!", mean and, or, not
func (*Search) SearchCompile ¶
func (s *Search) SearchCompile()
SearchCompile: create regex string and compile it..
func (*Search) SearchInAdd ¶
type StringWriter ¶
type UnixProcess ¶
type UnixProcess struct {
// contains filtered or unexported fields
}
UnixProcess is an implementation of Process that contains Unix-specific fields and information.
func (*UnixProcess) Executable ¶
func (p *UnixProcess) Executable() string
func (*UnixProcess) PPid ¶
func (p *UnixProcess) PPid() int
func (*UnixProcess) Pid ¶
func (p *UnixProcess) Pid() int
func (*UnixProcess) Refresh ¶
func (p *UnixProcess) Refresh() error
Refresh reloads all the data associated with this process.
type WordWithDigit ¶
type WordWithDigit struct {
ForceRightDigit bool
// contains filtered or unexported fields
}
func (*WordWithDigit) FillWordToMatchMaxLength ¶
func (w *WordWithDigit) FillWordToMatchMaxLength(inString string, removeExt ...bool) (outString string)
FillWordToMatchMaxLength: Convert word(s) into numbered one, like "label1" -> "label000001" etc... results are based on list of words that determine max length of them to determinate the final length of the modified word. This is used in case of sorting list of words that contains numeric value to avoid the disorder result like "1label", "10label", "2label" etc ...
func (*WordWithDigit) Init ¶
func (w *WordWithDigit) Init(words []string)