go: github.com/openmpp/go/ompp/helper Index | Files

package helper

import "github.com/openmpp/go/ompp/helper"

Package helper is a set common helper functions

Index

Package Files

helper.go json.go utf8.go zip.go

Variables

var (
    Utf8bom    = []byte{0xEF, 0xBB, 0xBF}
    Utf16LEbom = []byte{0xFF, 0xFE}
    Utf16BEbom = []byte{0xFE, 0xFF}
    Utf32LEbom = []byte{0xFF, 0xFE, 0x00, 0x00}
    Utf32BEbom = []byte{0x00, 0x00, 0xFE, 0xFF}
)

byte order mark bytes

func CleanSpecialChars Uses

func CleanSpecialChars(src string) string

CleanSpecialChars replace all ["'`$}{@\] by _ underscore

func DeepCopy Uses

func DeepCopy(src interface{}, dst interface{}) error

DeepCopy using gob to make a deep copy from src into dst, both src and dst expected to be a pointers

func FileToUtf8 Uses

func FileToUtf8(filePath string, encodingName string) (string, error)

FileToUtf8 read file content and convert it to UTF-8 string.

If file starts with BOM (utf-8 utf-16LE utf-16BE utf-32LE utf-32BE) then BOM is used. If no BOM and encodingName is "" empty then file content probed to see is it already utf-8. If encodingName explicitly specified then it is used to convert file content to string. If none of above then assume default encoding: "windows-1252" on Windows and "utf-8" on Linux.

func FromJson Uses

func FromJson(srcJson []byte, dst interface{}) (bool, error)

FromJson restore from json string bytes and convert to destination pointer.

func FromJsonFile Uses

func FromJsonFile(jsonPath string, dst interface{}) (bool, error)

FromJsonFile reads read from json file and convert to destination pointer.

func MakeDateTime Uses

func MakeDateTime(t time.Time) string

MakeDateTime return date-time string, ie: 2012-08-17 16:04:59.148

func MakeTimeStamp Uses

func MakeTimeStamp(t time.Time) string

MakeTimeStamp retrun timestamp string as: 2012_08_17_16_04_59_148

func PackZip Uses

func PackZip(srcPath string, dstDir string) (string, error)

PackZip create new (overwrite) zip archive from specified file or directory and all subdirs. If dstDir is "" empty then result located in source base directory.

func ParseKeyValue Uses

func ParseKeyValue(src string) (map[string]string, error)

ParseKeyValue string of multiple key=value; pairs separated by semicolon. Key cannot be empty, value can be. Value can be escaped with "double" or 'single' quotes

func ToAlphaNumeric Uses

func ToAlphaNumeric(src string) string

ToAlphaNumeric replace all non [A-Z,a-z,0-9] by _ underscore and remove repetitive underscores

func ToJsonFile Uses

func ToJsonFile(jsonPath string, src interface{}) error

ToJsonFile convert source to json and write into jsonPath file.

func ToJsonIndent Uses

func ToJsonIndent(src interface{}) (string, error)

ToJsonIndent return source conveted to json indeneted string.

func UnQuote Uses

func UnQuote(src string) string

UnQuote trim spaces and remove "double" or 'single' quotes around string

func UnpackZip Uses

func UnpackZip(zipPath string, dstDir string) error

UnpackZip unpack zip archive into specified directory, creating it if not exist. If dstDir is "" empty then result located in source base directory.

func Utf8Reader Uses

func Utf8Reader(f *os.File, encodingName string) (io.Reader, error)

Utf8Reader return a reader to transform file content to utf-8.

If file starts with BOM (utf-8 utf-16LE utf-16BE utf-32LE utf-32BE) then BOM is used. If no BOM and encodingName is "" empty then file content probed to see is it already utf-8. If encodingName explicitly specified then it is used to convert file content to string. If none of above then assume default encoding: "windows-1252" on Windows and "utf-8" on Linux.

Package helper imports 21 packages (graph) and is imported by 5 packages. Updated 2019-03-05. Refresh now. Tools for package owners.