strutils

package
v0.0.0-...-5da7bf1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(str string, strs ...string) string

Append appends the given strings to the first string.

func Deduplicate

func Deduplicate(names []string) []string

Deduplicate removes duplicate string that are either equal or contain each other. The string contained in the other string will be removed.

func Ignore

func Ignore(ignored string, names ...string) []string

Ignore returns all strings that are not equal to the ignored string. Equality check is case insensitive.

func Merge

func Merge(a, b string) string

Merge concatenates two strings removing duplicate overlaps between joins.

func MergeAll

func MergeAll(strs ...string) string

MergeAll concatenates all strings removing duplicate overlaps between joins and overlaps across all previous joined strings with the next abC + CdeF + Fgh = abCdeFgh

func MergeAllTypeNames

func MergeAllTypeNames(names ...string) string

MergeAllTypeNames merges all type names and prefixes the result with an "N" if the result starts with an integer.

func MimeTypeName

func MimeTypeName(mt string) string

MimeTypeName returns the last part of a mime type. And converts the mime type to a Go type name.

func MimeTypeNames

func MimeTypeNames(mimes []string) []string

MimeTypeNames takes the mime types and returns the last part of each mime type. And converts the mime types to Go type names.

func Overlap

func Overlap(a, b string) int

Overlap returns the maximum overlap of two strings. The end of the first string is compared to the beginning of the second string. Order of the strings is important.

func PrefixInteger

func PrefixInteger(name string) string

PrefixInteger prefixes the given name with an "N" if it is a valid integer.

func RangeStatusCode

func RangeStatusCode(nxx string) string

RangeStatusCode converts nXX status codes to a string representation. 1XX -> Info 2XX -> Success 3XX -> Redirect 4XX -> ClientError 5XX -> ServerError Any other will be converted to a type name.

func Size

func Size(ss ...string) int

func Split

func Split(s string) []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 SplitAll

func SplitAll(names ...string) []string

SplitAll splits a slice of strings into a slice of words by splitting on camelcase.

func Squeeze

func Squeeze(s string) string

Squeeze removes all whitespace from a string. A b C -> AbC

func StatusCode

func StatusCode(status string) string

StatusCode returns the status code name for a given status code. If the status code is not a valid integer, it will be returned as is. If the status code is a valid integer, but not a valid http status code, it will be returned as is.

func StatusCodes

func StatusCodes(statuses []string) []string

func ToTitle

func ToTitle(name string) string

func TypeName

func TypeName(name string) string

TypeName removes all non alpha numeric characters Integers are prefixed with an "N" The first character is capitalized.

func UnwrapAllPathParameters

func UnwrapAllPathParameters(modify func(string) string, path ...string) []string

UnwrapAllPathParameters unwraps all path placeholders

func UnwrapPathParameters

func UnwrapPathParameters(modifyNew func(string) string, path string) string

UnwrapPathParameters unwraps and modifies unwrapped values: {version} -> modify(version)

Types

This section is empty.

Jump to

Keyboard shortcuts

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