strutils

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 5 Imported by: 2

README

Przenies do pakietu malumar/strutil bo jest niezalezny od wszystkiego

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PL_UTF8_CHARSET_PAIRS = []PairOfRunes{
	PairOfRunes{'ę', 'e'},
	PairOfRunes{'ó', 'o'},
	PairOfRunes{'ą', 'a'},
	PairOfRunes{'ś', 's'},
	PairOfRunes{'ł', 'l'},
	PairOfRunes{'ż', 'z'},
	PairOfRunes{'ź', 'z'},
	PairOfRunes{'ć', 'c'},
	PairOfRunes{'ń', 'N'},
	PairOfRunes{'Ę', 'E'},
	PairOfRunes{'Ó', 'O'},
	PairOfRunes{'Ą', 'A'},
	PairOfRunes{'Ś', 'S'},
	PairOfRunes{'Ł', 'L'},
	PairOfRunes{'Ż', 'Z'},
	PairOfRunes{'Ź', 'Ć'},
	PairOfRunes{'Ń', 'N'},
}

Functions

func CutStringToLen

func CutStringToLen(val string, maxLen int) string

func EscWildcard added in v1.0.1

func EscWildcard(source string, addPfx bool) string

func FirstLower

func FirstLower(s string) string

func FirstUpper

func FirstUpper(s string) string

func FlatCase

func FlatCase(s string) string

zmienna abc -> zmiennaabc zmiena ABC -> zmiennaABC zmiena_abc -> zmienaabc

func InArray

func InArray(array []string, search string) bool

func IsAlpha

func IsAlpha(s string) bool

func IsDigit

func IsDigit(c rune) bool

func IsLetter

func IsLetter(c rune) bool

func IsNumber

func IsNumber(s string) bool

func IsNumberOrNumberWithSign

func IsNumberOrNumberWithSign(s string) bool

func IsUnicodeLetter

func IsUnicodeLetter(s string) bool

func LeftPad

func LeftPad(s string, padStr string, pLen int) string

TODO convert these into a

* leftPad and rightPad just repoeat the padStr the indicated * number of times *

func LeftPad2Len

func LeftPad2Len(s string, padStr string, overallLen int) string

func Match

func Match(pattern, name string) (matched bool)

Match - finds whether the text matches/satisfies the pattern string. supports '*' and '?' wildcards in the pattern string. unlike path.Match(), considers a path as a flat name space while matching the pattern. The difference is illustrated in the example here https://play.golang.org/p/Ega9qgD4Qz .

func MatchAsPatternPrefix added in v1.0.1

func MatchAsPatternPrefix(pattern, text string) bool

MatchAsPatternPrefix matches text as a prefix of the given pattern. Examples:

| Pattern | Text    | Match Result |
====================================
| abc*    | ab      | True         |
| abc*    | abd     | False        |
| abc*c   | abcd    | True         |
| ab*??d  | abxxc   | True         |
| ab*??d  | abxc    | True         |
| ab??d   | abxc    | True         |
| ab??d   | abc     | True         |
| ab??d   | abcxdd  | False        |

This function is only useful in some special situations.

func MatchSimple

func MatchSimple(pattern, name string) bool

MatchSimple - finds whether the text matches/satisfies the pattern string. supports '*' wildcard in the pattern and ? for single characters. Only difference to Match is that `?` at the end is optional, meaning `a?` pattern will match name `a`.

func PascalCase

func PascalCase(s string) string

zamiana zmienna --> zmienna zmienna_inna ZmiennaInna

func PascalSnakeCaseAllFirstUpper

func PascalSnakeCaseAllFirstUpper(s string) string

func RemoveDoubleWhiteSpace

func RemoveDoubleWhiteSpace(str string) string

func RemoveNonAlphaNumeric

func RemoveNonAlphaNumeric(s string) string

func RemoveUtf8PlAccentsFromQuery

func RemoveUtf8PlAccentsFromQuery(text string) string

func RemoveWhiteSpaces

func RemoveWhiteSpaces(s string) string

func ReplaceAll

func ReplaceAll(s string, newString string, searches ...string) string

func ReplaceAllPairs

func ReplaceAllPairs(s string, pairs ...Pair) string

func ReplacePairOfRunes

func ReplacePairOfRunes(s string, pairs ...PairOfRunes) string

func RightPad

func RightPad(s string, padStr string, pLen int) string

func RightPad2Len

func RightPad2Len(s string, padStr string, overallLen int) string
the Pad2Len functions are generally assumed to be padded with short sequences of strings

* in many cases with a single character sequence * * so we assume we can build the string out as if the char seq is 1 char and then * just substr the string if it is longer than needed * * this means we are wasting some cpu and memory work * but this always get us to want we want it to be * * in short not optimized to for massive string work * * If the overallLen is shorter than the original string length * the string will be shortened to this length (substr) *

func SnakeCaseAllFirstUpper

func SnakeCaseAllFirstUpper(s string) string

func SnakeCaseFirstLower

func SnakeCaseFirstLower(s string) string

zamiana: zmienna -> zmienna zmiennaInna -> zmiennaInna ZmiennnaInnaDruga -> zmiennaInnaDruga Zmienna1 Zmienna2 -> zmienna1Zmienna2

func SnakeCaseFirstUpper

func SnakeCaseFirstUpper(s string) string

zamiana: zmienna -> Zmienna zmiennaInna -> ZmiennaInna ZmiennnaInnaDruga -> ZmiennaInnaDruga Zmienna1 Zmienna2 -> Zmienna1Zmienna2

func Split

func Split(src string, skip string) (entries []string)

Split splits the camelcase word and returns a list of words. It also supports digits. Both lower camel case and upper camel case are supported. For more info please check: http://en.wikipedia.org/wiki/CamelCase

Examples

"" =>                     [""]
"lowercase" =>            ["lowercase"]
"Class" =>                ["Class"]
"MyClass" =>              ["My", "Class"]
"MyC" =>                  ["My", "C"]
"HTML" =>                 ["HTML"]
"PDFLoader" =>            ["PDF", "Loader"]
"AString" =>              ["A", "String"]
"SimpleXMLParser" =>      ["Simple", "XML", "Parser"]
"vimRPCPlugin" =>         ["vim", "RPC", "Plugin"]
"GL11Version" =>          ["GL", "11", "Version"]
"99Bottles" =>            ["99", "Bottles"]
"May5" =>                 ["May", "5"]
"BFG9000" =>              ["BFG", "9000"]
"BöseÜberraschung" =>     ["Böse", "Überraschung"]
"Two  spaces" =>          ["Two", "  ", "spaces"]
"BadUTF8\xe2\xe2\xa1" =>  ["BadUTF8\xe2\xe2\xa1"]

Splitting rules

  1. If string is not valid UTF-8, return it without splitting as single item array.
  2. Assign all unicode characters into one of 4 sets: lower case letters, upper case letters, numbers, and all other characters.
  3. Iterate through characters of string, introducing splits between adjacent characters that belong to different sets.
  4. Iterate through array of split strings, and if a given string is upper case: if subsequent string is lower case: move last character of upper case string to beginning of lower case string

func SplitQuotedString

func SplitQuotedString(text string) (items []string)

func StripWhiteSpaces

func StripWhiteSpaces(str string) string

func UnderscoreCase

func UnderscoreCase(s string) string

zamiana: zmienna -> zmienna zmiennaInna -> zmienna_Inna ZmiennnaInnaDruga -> Zmienna_Inna_Drug

func UnderscoreCaseLower

func UnderscoreCaseLower(s string) string

zamiana: zmienna -> zmienna zmiennaInna -> zmienna_inna ZmiennnaInnaDruga -> zmienna_inna_drug

func UnderscoreCaseUpper

func UnderscoreCaseUpper(s string) string

zamiana: zmienna -> ZMIENNA zmiennaInna -> ZMIENNA_INNA ZmiennnaInnaDruga -> ZMIENNA_INNA_DRUGA

Types

type Pair

type Pair struct {
	Search  string
	Replace string
}

type PairOfRunes

type PairOfRunes struct {
	Search  rune
	Replace rune
}

type Strings

type Strings []string

func (Strings) IsIn

func (ss Strings) IsIn(value string) bool

func (Strings) IsInCaseSensitive

func (ss Strings) IsInCaseSensitive(value string) bool

func (Strings) ToInterfaceSlice

func (ss Strings) ToInterfaceSlice() []interface{}

func (Strings) ToStringSlice

func (ss Strings) ToStringSlice() []string

Jump to

Keyboard shortcuts

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