rstrings

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2020 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Overview

Package rstrings contains string and file-based operations, such as reading a file into a string

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CsvToMap added in v0.3.1

func CsvToMap(fname string) (result map[string][]string, err error)

CsvToMap takes the given filename, reads the file in CSV format, and returns a 2d map first dimension is the column name, second dimension is the row values for that column. input CSV file is expected to have a header row.

func DefaultIfEmpty added in v0.3.1

func DefaultIfEmpty(s, deflt string) string

DefaultIfEmpty returns the given string. If the given string is empty (see rstrings.IsEmpty), the given default is returned

func EnsurePrefix added in v0.4.1

func EnsurePrefix(input string, prefix string) string

EnsurePrefix prefixes the given string with the given prefix if it doesn't have it already examples: EnsurePrefix("foo", "f") = "foo" EnsurePrefix("foo", "new-") = "new-foo"

func EnsureSuffix added in v0.4.1

func EnsureSuffix(input string, suffix string) string

EnsureSuffix suffixes the given string with the given suffix if it doesn't have it already examples: EnsureSuffix("foo", "o") = "foo" EnsureSuffix("foo", "-new") = "foo-new"

func EnsureWrapped added in v0.4.1

func EnsureWrapped(input string, wrapper string) string

EnsureWrapped wraps the given string with the given prefix/suffix if it doesn't have it already examples: EnsureWrapped("foo", "'") = "'foo'" EnsureSuffix("fluff", "f") = "fluff"

func FileToString added in v0.2.0

func FileToString(fname string) (result string, err error)

FileToString reads from the given filename and returns the contents as a string

func IsEmpty

func IsEmpty(s string) bool

IsEmpty returns whether the given string has a length of 0 or is only whitespace examples: IsEmpty("") = true IsEmpty(" ") = True IsEmpty("b") = false IsEmpty(" b") = false IsEmpty("b ") = false IsEmpty(" b ") = false

func LeftPad added in v0.4.0

func LeftPad(input string, length int) string

LeftPad prepend-pads the given string to the desired length with space characters. See LeftPadWith for implementation details

func LeftPadWith added in v0.4.0

func LeftPadWith(input string, char rune, length int) string

LeftPadWith prepend-pads the given string to the given length with the given rune. If the input string is already longer than the desired length, it is returned and NOT truncated

func MapToString added in v0.3.1

func MapToString(input map[string]interface{}, isPretty ...bool) string

MapToString converts the given map to a string. The variadic bool is a flag indicating whether the result should be prettified with newlines and whitespace default is false, for compatibility

func RightPad added in v0.4.0

func RightPad(input string, length int) string

RightPad append-pads the given string to the desired length with space characters. See RightPadWith for implementation details

func RightPadWith added in v0.4.0

func RightPadWith(input string, char rune, length int) string

RightPadWith append-pads the given string to the given length with the given rune. If the input string is already longer than the desired length, it is returned and NOT truncated

Types

This section is empty.

Jump to

Keyboard shortcuts

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