Documentation ¶
Overview ¶
Package stringhelp contains various helpers for strings and collections thereof.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotMap = errors.New("not a map with string keys")
ErrNotMap occurs when a generic string map function receives something that isn't a string map.
Functions ¶
func JoinNonEmpty ¶
JoinNonEmpty joins the non-empty strings in xs using sep.
Example ¶
ExampleJoinNonEmpty is a testable example for JoinNonEmpty.
package main import ( "fmt" "github.com/c4-project/c4t/internal/helper/stringhelp" ) func main() { fmt.Println(stringhelp.JoinNonEmpty("/")) fmt.Println(stringhelp.JoinNonEmpty("/", "")) fmt.Println(stringhelp.JoinNonEmpty("/", "example1", "")) fmt.Println(stringhelp.JoinNonEmpty("/", "", "example2")) fmt.Println(stringhelp.JoinNonEmpty("/", "example1", "example2")) fmt.Println(stringhelp.JoinNonEmpty("/", "the", "", "quick brown", "", "fox")) }
Output: example1 example2 example1/example2 the/quick brown/fox
func PluralQuantity ¶
PluralQuantity formats a quantity n using the components stem, one, and many as follows: if n is 1, we return '[n] [stem][one]'; else, '[n] [stem][many]'.
Example ¶
ExamplePluralQuantity is a runnable example for PluralQuantity.
package main import ( "fmt" "github.com/c4-project/c4t/internal/helper/stringhelp" ) func main() { fmt.Println(stringhelp.PluralQuantity(0, "director", "y", "ies")) fmt.Println(stringhelp.PluralQuantity(1, "fil", "e", "es")) fmt.Println(stringhelp.PluralQuantity(2, "corp", "us", "ora")) }
Output: 0 directories 1 file 2 corpora
func SafeMapKeys ¶
SafeMapKeys is the same as calling MapKeys on m, but checks to make sure m is a string map first.
Types ¶
Click to show internal directories.
Click to hide internal directories.