genLib

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2019 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

get-c-class.go

/ +build OMIT

/ +build OMIT

csvfunc.go

fileText.go

strings.go

tools.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendAt

func AppendAt(slice []string, pos int, insert ...string) []string

Add data at a specified position in slice of a string

func ByteToHexStr

func ByteToHexStr(bytes []byte) string

Convert []byte to hexString

func CharsetToUtf8

func CharsetToUtf8(str string) string

Get charset and convert to utf-8 if needed

func Check

func Check(err error, message ...string)

Check error function input message is optional or accept multiple arguments.

func CheckP

func CheckP(err error)

Check error function, this one do panic !!

func DeleteSl

func DeleteSl(slice []string, pos int) []string

Delete value at specified position in string slice

func DeleteSl1

func DeleteSl1(slice []string, pos int) []string

Delete value at specified position in string slice

func DetectCharsetFile

func DetectCharsetFile(filename string) (name string)

Detect encoding type for files

func DetectCharsetStr

func DetectCharsetStr(inputStr string) (name string)

Detect encoding type for strings

func FileCharsetSwitch

func FileCharsetSwitch(inCharset, outCharset, inFilename string, outFilename ...string)

Change charset of a text file

func FindDate

func FindDate(inputString, fmtDate string) []string

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 FormatDate

func FormatDate(fmtDate string, inpDate string) time.Time

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

func FormatText(str string, max int) string

Format words text to fit (column/windows with limited width) "max" chars.

func GenFileName

func GenFileName() string

Generate a randomized file name

func GetEOL

func GetEOL(filename string) string

Open file and get (CR, LF, CRLF) > string

func GetSep

func GetSep(str string) []string

Get separator char

func GetStrIndex

func GetStrIndex(slice []string, item string) int

Get index of a string in a slice

func IsDate

func IsDate(inString string) bool

Check if string is date

func IsError

func IsError(err error) bool

Check error and return true if error exist

func IsExist

func IsExist(slice [][]string, cmpRow []string) bool

Search in 2d string slice if a row exist.

func IsFloat

func IsFloat(inString string) bool

Check if string is float

func LinesToTextFile

func LinesToTextFile(filename string, values interface{}) error

Write slice to file

func Md5String

func Md5String(inString string) string

Get MD5 checksum from string.

func Md5Sum

func Md5Sum(filename string) string

Get MD5 checksum from file.

func NewDateFormat

func NewDateFormat() []string

func PathSep

func PathSep() string

Get OS path separator

func Preppend

func Preppend(slice []string, prepend ...string) []string

Add data at the begining of a string slice

func ReadCsv

func ReadCsv(filename, comma string, fields, startLine int, endLine ...int) [][]string

Read data from CSV file

func ReadFile

func ReadFile(filename string) []byte

Read file low lvl format

func ReadJson

func ReadJson(filename string, interf interface{})

read json datas from file to given interface / structure ReadJson(filename, &person)

func RemovIfExist

func RemovIfExist(filename string)

func RemoveDupSl

func RemoveDupSl(slice []string) []string

Remove duplicat entry in a string slice

func RemoveNonAlNum

func RemoveNonAlNum(inString string) string

Remove all non alpha-numeric char

func ReplaceSpace

func ReplaceSpace(inString string) string

replace all [[:space::]] with underscore "_"

func SearchSl

func SearchSl(find string, table [][]string, cs, ww, rx bool) ([][]string, error)

Search in 2d string slice. cs=case sensitive, ww=whole word, rx=regex

func SetEOL

func SetEOL(filename, eol string)

Open file and convert EOL (CR, LF, CRLF) then write it back.

func SliceSortDate

func SliceSortDate(slice [][]string, fmtDate string, dateCol, secDateCol int, ascendant bool) [][]string

Sort 2d string slice with date inside

func SliceSortFloat

func SliceSortFloat(slice [][]string, col int, ascendant bool, decimalChar string)

Sort 2d string with float value

func SliceSortString

func SliceSortString(slice [][]string, col int, ascendant, caseSensitive bool)

Sort 2d string slice

func StringDecimalSwitchFloat

func StringDecimalSwitchFloat(decimalChar, inString string) float64

Convert comma to dot if needed and return 0 if input string is empty.

func StringToCharacterClasses

func StringToCharacterClasses(inpString string, caseSensitive, strictMode bool) string

Convert string to character classes equivalent's string

func TempMake

func TempMake(prefix string) string

Make temporary directory

func TempRemove

func TempRemove(fName string)

Remove directory

func TextFileToLines

func TextFileToLines(filename string, opt ...string) []string

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

func TrimSpace(inputString string, cmds ...string) string

Some multiple way to trim strings. cmds is optionnal or accept multiples args

func TruncateString

func TruncateString(inString, prefix string, max, option int) string

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 Use

func Use(vals ...interface{})

Use function to avoid "Unused variable ..." msgs

func WriteCsv

func WriteCsv(filename, comma string, rows [][]string)

Write data to CSV file

func WriteJson

func WriteJson(filename string, interf interface{})

Write json datas to file from given interface / structure i.e: WriteJson(filename, &person)

func WriteTextFile

func WriteTextFile(filename, data string, appendIfExist ...bool)

Write string to file low lvl format

Types

type CharsetList

type CharsetList struct {
	SimpleCharsetList []string
	FullCharsetList   []string
}

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 Entry

type Entry struct {
	InPos  int
	OutPos int
	Val    int
	Str    string
}

type File

type File struct {
	Path         string
	Name         string
	NameNoExt    string
	Ext          string
	RealPath     string
	RealName     string
	Output       string
	OutputNewExt string
	Absolute     string
	OsSep        string
	OsListSep    string
}

func SplitFilePath

func SplitFilePath(filename string, toAdd ...string) File

Split full filename into path, ext, name, ... optionally add suffix before original extension or change extension

type RowStore

type RowStore struct {
	Idx int
	Cnt int
	Tot int
	Str string
}

func AppendIfMissing

func AppendIfMissing(inputSlice []RowStore, input RowStore) []RowStore

Append to slice if not already exist (RowStore version)

func AppendIfMissingC

func AppendIfMissingC(inputSlice []RowStore, input RowStore) []RowStore

Append to slice if RowStore.cnt value does not already exist (Quote version)

func FindCountStr

func FindCountStr(str, regExpression string) []RowStore

Get count of non alphanum chars in a string in struct(RowStore) format

func FindQuote

func FindQuote(str string, sep string) []RowStore

Get Quote char

Jump to

Keyboard shortcuts

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