str

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: MIT Imports: 4 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

str

Some convenient string functions.

What

This package contains a couple of functions to remove duplicates from string slices and optionally sort them, plus a rather over-engineered wrapper around strings.Builder.

Primary functions
  • RemoveDuplicateStrings() - Removes duplicate strings from a slice of strings, optionally sorting them.
  • RemoveDuplicateStringsAndTitle() - Removes duplicate strings from a slice of strings, turns the first character to upper case and optionally sorts the slice.
  • NewStringer() - Creates an expanded strings.Builder. Its Write() function accepts many datatypes, and slices can optionally have a configurable separator added between elements.

Stringer

The main functions in Stringer are as follows:

  • Write(): Writes strings, bytes, integers, floats, booleans, maps, and slices to the underlying strings.Builder.
  • WriteStrings(): Writes an arbitrary number of strings to the underlying strings.Builder.
  • SetCliceComma(): Sets the separator for slice elements when concatenating them into the underlying strings.Builder.
  • SetEquals(): Sets the separator for map keys and values when concatenating them into the underlying strings.Builder.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveDuplicateStrings

func RemoveDuplicateStrings(list []string, sorted bool) []string

RemoveDuplicateStrings returns a list with no duplicates. Case matters.

func RemoveDuplicateStringsAndTitle

func RemoveDuplicateStringsAndTitle(list []string, sorted bool) []string

RemoveDuplicateStringsAndTitle converts the names to lowercase and returns a list with no duplicates and the first letter capitalised.

Types

type Stringer

type Stringer struct {
	strings.Builder
	// contains filtered or unexported fields
}

Stringer extends strings.Builder.

func NewStringer

func NewStringer() *Stringer

NewStringer returns a new Stringer.

func (*Stringer) SetComma

func (s *Stringer) SetComma(c rune) *Stringer

SetComma sets the symbol to use for joining slices and map k-v pairs.

func (*Stringer) SetEquals

func (s *Stringer) SetEquals(e rune) *Stringer

SetEquals sets the symbol to join keys and values in maps.

func (*Stringer) SetMapComma

func (s *Stringer) SetMapComma(b bool) *Stringer

SetMapComma enables adding a comma between elements in supplied maps.

func (*Stringer) SetSliceComma

func (s *Stringer) SetSliceComma(b bool) *Stringer

SetSliceComma enables adding a comma between elements in supplied slices.

func (*Stringer) Write

func (s *Stringer) Write(v ...interface{}) (int, error)

Write writes any number of different types at once. Special notes: Integers - int and int64 are the only approved types, and untyped whole numbers will be parsed as int Floating point numbers - all numbers with a decimal point are interpreted as float64, with the fewest necessary decimal places Maps & slices - commas are not on by default, and maps will have "=" between each key-value pair

func (*Stringer) WriteStrings

func (s *Stringer) WriteStrings(v ...string) (int, error)

WriteStrings writes any number of strings in one go.

Jump to

Keyboard shortcuts

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