simpleutils

package module
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 11 Imported by: 3

README

simpleutils

import "github.com/jimsnab/go-simpleutils"

Index

func CharGet

func CharGet(input string, position int) rune

Charget returns the rune at the logical index position

func CopyFile

func CopyFile(srcPath, destPath string) (int64, error)

CopyFile reads file content into memory and writes it to a new file

func DeepCopy

func DeepCopy(src interface{}) (dest interface{})

DeepCopy generates a separate copy of a source object

func Escape

func Escape(s string) string

Escape translates control characters to backslash escape sequence; e.g., '\r' becomes `\r`

func FileExists

func FileExists(path string) (bool, error)

FileExists returns true if path corresponds to a file, and false if it corresponds to nothing or to a directory.

func GenerateRandomBytes

func GenerateRandomBytes(count int) ([]byte, error)

GenerateRandomBytes returns a byte array of cryptographic (true) random numbers. The byte array length is specified by count.

func GenerateRandomString

func GenerateRandomString(count int) (string, error)

GenerateRandomString returns a base-64 encoding of a cryptographic (true) random number byte array. The byte array length is specified by count.

func IndexAt

func IndexAt(testString, substring string, startingIndex int) int

IndexAt is like strings.Index with a starting index

func IndexAtAny

func IndexAtAny(testString, chars string, startingIndex int) int

IndexAtAny is like strings.Index with a starting index

func IsDirectory

func IsDirectory(path string) (bool, error)

IsDirectory returns true if path corresponds to a directory, and false if it corresponds to nothing or to a file.

func IsTokenCharFirst

func IsTokenCharFirst(ch rune) bool

IsTokenCharFirst returns true if ch is a letter or underscore

func IsTokenCharNext

func IsTokenCharNext(ch rune) bool

IsTokenCharNext returns true if ch is a letter, number or underscore

func IsTokenName

func IsTokenName(s string) bool

IsTokenName returns true if s contains only letters, numbers or underscores, and does not start with a number, and has at least one letter

func IsTokenNameWithMiddleChars

func IsTokenNameWithMiddleChars(s string, middleChars string) bool

IsTokenNameWithMiddleChars returns true if s contains only letters, numbers or underscores, or has allowed characters that are not first or last, does not start with a number, and has at least one letter. A common middleChars string is "-".

func PatternMatch

func PatternMatch(pattern string, testString string) bool

PatternMatch performs a simple asterisk-based pattern match

func PrintableStr

func PrintableStr(input string) string

PrintableStr converts non-printable characters in input to a dot

func RuneIndexAt

func RuneIndexAt(testString, substring []rune, startingIndex int) int

RuneIndexAt is a version of IndexAt for rune arrays

func RuneIndexAtAny

func RuneIndexAtAny(testString, chars []rune, startingIndex int) int

RuneIndexAtAny is a version of IndexAtAny for rune arrays

func SortedKeys

func SortedKeys(m interface{}) []string

SortedKeys returns the key array for the map, sorted A-Z

func StringArrayToString

func StringArrayToString(strs []string, delimiter string) string

StringArrayToStrings converts an array of strings to a single string, placing the delimiter string between each

func Substr

func Substr(input string, start int, length int) string

Substr returns a string based on logical character start and length, instead of bytes like a slice

func Utf8len

func Utf8len(data []byte, offset int) int

Utf8len returns the number of bytes in the logical UTF-8 character, 0 if the character is incomplete, or -1 if the character is invalid,

func WhichSuffix

func WhichSuffix(s string, suffixes ...string) *string

WhichSuffix returns a pointer to the first suffix matching s, or nil if none of the suffixes match

type HashedText

HashedText is a typed alias for string

type HashedText string
func HashText
func HashText(text string) HashedText

HashText returns a sha1 hash of text in base64 encoding.

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CharGet added in v1.0.3

func CharGet(input string, position int) rune

Charget returns the rune at the logical index position

func CopyFile added in v1.0.4

func CopyFile(srcPath, destPath string) (int64, error)

CopyFile reads file content into memory and writes it to a new file

func DeepCopy added in v1.0.11

func DeepCopy(src interface{}) (dest interface{})

DeepCopy generates a separate copy of a source object

func Escape

func Escape(s string) string

Escape translates control characters to backslash escape sequence; e.g., '\r' becomes `\r`

func FileExists added in v1.0.3

func FileExists(path string) (bool, error)

FileExists returns true if path corresponds to a file, and false if it corresponds to nothing or to a directory.

func GenerateRandomBytes added in v1.0.3

func GenerateRandomBytes(count int) ([]byte, error)

GenerateRandomBytes returns a byte array of cryptographic (true) random numbers. The byte array length is specified by count.

func GenerateRandomString added in v1.0.3

func GenerateRandomString(count int) (string, error)

GenerateRandomString returns a base-64 encoding of a cryptographic (true) random number byte array. The byte array length is specified by count.

func IndexAt added in v1.0.8

func IndexAt(testString, substring string, startingIndex int) int

IndexAt is like strings.Index with a starting index

func IndexAtAny added in v1.0.8

func IndexAtAny(testString, chars string, startingIndex int) int

IndexAtAny is like strings.Index with a starting index

func IsDirectory added in v1.0.3

func IsDirectory(path string) (bool, error)

IsDirectory returns true if path corresponds to a directory, and false if it corresponds to nothing or to a file.

func IsTokenCharFirst

func IsTokenCharFirst(ch rune) bool

IsTokenCharFirst returns true if ch is a letter or underscore

func IsTokenCharNext

func IsTokenCharNext(ch rune) bool

IsTokenCharNext returns true if ch is a letter, number or underscore

func IsTokenName

func IsTokenName(s string) bool

IsTokenName returns true if s contains only letters, numbers or underscores, and does not start with a number, and has at least one letter

func IsTokenNameWithMiddleChars added in v1.0.5

func IsTokenNameWithMiddleChars(s string, middleChars string) bool

IsTokenNameWithMiddleChars returns true if s contains only letters, numbers or underscores, or has allowed characters that are not first or last, does not start with a number, and has at least one letter. A common middleChars string is "-".

func PatternMatch added in v1.0.3

func PatternMatch(pattern string, testString string) bool

PatternMatch performs a simple asterisk-based pattern match

func PrintableStr added in v1.0.3

func PrintableStr(input string) string

PrintableStr converts non-printable characters in input to a dot

func RuneIndexAt added in v1.0.8

func RuneIndexAt(testString, substring []rune, startingIndex int) int

RuneIndexAt is a version of IndexAt for rune arrays

func RuneIndexAtAny added in v1.0.8

func RuneIndexAtAny(testString, chars []rune, startingIndex int) int

RuneIndexAtAny is a version of IndexAtAny for rune arrays

func SortedKeys

func SortedKeys(m interface{}) []string

SortedKeys returns the key array for the map, sorted A-Z

func StringArrayToString added in v1.0.6

func StringArrayToString(strs []string, delimiter string) string

StringArrayToStrings converts an array of strings to a single string, placing the delimiter string between each

func Substr

func Substr(input string, start int, length int) string

Substr returns a string based on logical character start and length, instead of bytes like a slice

func Utf8len added in v1.0.3

func Utf8len(data []byte, offset int) int

Utf8len returns the number of bytes in the logical UTF-8 character, 0 if the character is incomplete, or -1 if the character is invalid,

func WhichSuffix

func WhichSuffix(s string, suffixes ...string) *string

WhichSuffix returns a pointer to the first suffix matching s, or nil if none of the suffixes match

Types

type HashedText added in v1.0.3

type HashedText string

HashedText is a typed alias for string

func HashText added in v1.0.3

func HashText(text string) HashedText

HashText returns a sha1 hash of text in base64 encoding.

Jump to

Keyboard shortcuts

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