Giter Club home page Giter Club logo

str's Introduction

str

import "github.com/mgutz/str"

Package str is a comprehensive set of string functions to build more Go awesomeness. Str complements Go's standard packages and does not duplicate functionality found in strings or strconv.

Str is based on plain functions instead of object-based methods, consistent with Go standard string packages.

str.Between("<a>foo</a>", "<a>", "</a>") == "foo"

Str supports pipelining instead of chaining

s := str.Pipe("\nabcdef\n", Clean, BetweenF("a", "f"), ChompLeftF("bc"))

User-defined filters can be added to the pipeline by inserting a function or closure that returns a function with this signature

func(string) string

Index

Variables

var ToFloatOr = ToFloat64Or

ToFloatOr parses as a float64 or returns defaultValue.

var Verbose = false

Verbose flag enables console output for those functions that have counterparts in Go's excellent stadard packages.

func Between

func Between(s, left, right string) string

Between extracts a string between left and right strings.

func BetweenF(left, right string) func(string) string

BetweenF is the filter form for Between.

func Camelize(s string) string

Camelize return new string which removes any underscores or dashes and convert a string into camel casing.

func Capitalize(s string) string

Capitalize uppercases the first char of s and lowercases the rest.

func CharAt

func CharAt(s string, index int) string

CharAt returns a string from the character at the specified position.

func CharAtF

func CharAtF(index int) func(string) string

CharAtF is the filter form of CharAt.

func ChompLeft(s, prefix string) string

ChompLeft removes prefix at the start of a string.

func ChompLeftF(prefix string) func(string) string

ChompLeftF is the filter form of ChompLeft.

func ChompRight(s, suffix string) string

ChompRight removes suffix from end of s.

func ChompRightF(suffix string) func(string) string

ChompRightF is the filter form of ChompRight.

func Classify(s string) string

Classify returns a camelized string with the first letter upper cased.

func ClassifyF(s string) func(string) string

ClassifyF is the filter form of Classify.

func Clean

func Clean(s string) string

Clean compresses all adjacent whitespace to a single space and trims s.

func Dasherize(s string) string

Dasherize converts a camel cased string into a string delimited by dashes.

func DecodeHTMLEntities(s string) string

DecodeHTMLEntities decodes HTML entities into their proper string representation. DecodeHTMLEntities is an alias for html.UnescapeString

func EnsurePrefix(s, prefix string) string

EnsurePrefix ensures s starts with prefix.

func EnsurePrefixF(prefix string) func(string) string

EnsurePrefixF is the filter form of EnsurePrefix.

func EnsureSuffix(s, suffix string) string

EnsureSuffix ensures s ends with suffix.

func EnsureSuffixF(suffix string) func(string) string

EnsureSuffixF is the filter form of EnsureSuffix.

func EscapeHTML(s string) string

EscapeHTML is alias for html.EscapeString.

func Humanize(s string) string

Humanize transforms s into a human friendly form.

func Iif

func Iif(condition bool, truthy string, falsey string) string

Iif is short for immediate if. If condition is true return truthy else falsey.

func IndexOf

func IndexOf(s string, needle string, start int) int

IndexOf finds the index of needle in s starting from start.

func IsAlpha

func IsAlpha(s string) bool

IsAlpha returns true if a string contains only letters from ASCII (a-z,A-Z). Other letters from other languages are not supported.

func IsAlphaNumeric(s string) bool

IsAlphaNumeric returns true if a string contains letters and digits.

func IsEmpty

func IsEmpty(s string) bool

IsEmpty returns true if the string is solely composed of whitespace.

func IsLower

func IsLower(s string) bool

IsLower returns true if s comprised of all lower case characters.

func IsNumeric(s string) bool

IsNumeric returns true if a string contains only digits from 0-9. Other digits not in Latin (such as Arabic) are not currently supported.

func IsUpper

func IsUpper(s string) bool

IsUpper returns true if s contains all upper case chracters.

func Left

func Left(s string, n int) string

Left returns the left substring of length n.

func LeftF

func LeftF(n int) func(string) string

LeftF is the filter form of Left.

func LeftOf

func LeftOf(s string, needle string) string

LeftOf returns the substring left of needle.

func Letters

func Letters(s string) []string

Letters returns an array of runes as strings so it can be indexed into.

func Lines

func Lines(s string) []string

Lines convert windows newlines to unix newlines then convert to an Array of lines.

func Map

func Map(arr []string, iterator func(string) string) []string

Map maps an array's iitem through an iterator.

func Match

func Match(s, pattern string) bool

Match returns true if patterns matches the string

func Pad

func Pad(s, c string, n int) string

Pad pads string s on both sides with c until it has length of n.

func PadF

func PadF(c string, n int) func(string) string

PadF is the filter form of Pad.

func PadLeft

func PadLeft(s, c string, n int) string

PadLeft pads s on left side with c until it has length of n.

func PadLeftF(c string, n int) func(string) string

PadLeftF is the filter form of PadLeft.

func PadRight(s, c string, n int) string

PadRight pads s on right side with c until it has length of n.

func PadRightF(c string, n int) func(string) string

PadRightF is the filter form of Padright

func Pipe

func Pipe(s string, funcs ...func(string) string) string

Pipe pipes s through one or more string filters.

func QuoteItems(arr []string) []string

QuoteItems quotes all items in array, mostly for debugging.

func ReplaceF(old, new string, n int) func(string) string

ReplaceF is the filter form of strings.Replace.

func ReplacePattern(s, pattern, repl string) string

ReplacePattern replaces string with regexp string. ReplacePattern returns a copy of src, replacing matches of the Regexp with the replacement string repl. Inside repl, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first submatch.

func ReplacePatternF(pattern, repl string) func(string) string

ReplacePatternF is the filter form of ReplaceRegexp.

func Reverse

func Reverse(s string) string

Reverse a string

func Right

func Right(s string, n int) string

Right returns the right substring of length n.

func RightF

func RightF(n int) func(string) string

RightF is the Filter version of Right.

func RightOf

func RightOf(s string, prefix string) string

RightOf returns the substring to the right of prefix.

func SetTemplateDelimiters(opening, closing string)

SetTemplateDelimiters sets the delimiters for Template function. Defaults to "{{" and "}}"

func Slice

func Slice(s string, start, end int) string

Slice slices a string. If end is negative then it is the from the end of the string.

func SliceContains(slice []string, val string) bool

SliceContains determines whether val is an element in slice.

func SliceF

func SliceF(start, end int) func(string) string

SliceF is the filter for Slice.

func SliceIndexOf(slice []string, val string) int

SliceIndexOf gets the indx of val in slice. Returns -1 if not found.

func Slugify

func Slugify(s string) string

Slugify converts s into a dasherized string suitable for URL segment.

func StripPunctuation(s string) string

StripPunctuation strips puncation from string.

func StripTags(s string, tags ...string) string

StripTags strips all of the html tags or tags specified by the parameters

func Substr

func Substr(s string, index int, n int) string

Substr returns a substring of s starting at index of length n.

func SubstrF

func SubstrF(index, n int) func(string) string

SubstrF is the filter form of Substr.

func Template(s string, values map[string]interface{}) string

Template is a string template which replaces template placeholders delimited by "{{" and "}}" with values from map. The global delimiters may be set with SetTemplateDelimiters.

func TemplateDelimiters() (opening string, closing string)

TemplateDelimiters is the getter for the opening and closing delimiters for Template.

func TemplateWithDelimiters(s string, values map[string]interface{}, opening, closing string) string

TemplateWithDelimiters is string template with user-defineable opening and closing delimiters.

func ToArgv

func ToArgv(s string) []string

ToArgv converts string s into an argv for exec.

func ToBool

func ToBool(s string) bool

ToBool fuzzily converts truthy values.

func ToBoolOr(s string, defaultValue bool) bool

ToBoolOr parses s as a bool or returns defaultValue.

func ToFloat32Or(s string, defaultValue float32) float32

ToFloat32Or parses as a float32 or returns defaultValue on error.

func ToFloat64Or(s string, defaultValue float64) float64

ToFloat64Or parses s as a float64 or returns defaultValue.

func ToIntOr

func ToIntOr(s string, defaultValue int) int

ToIntOr parses s as an int or returns defaultValue.

func Underscore(s string) string

Underscore returns converted camel cased string into a string delimited by underscores.

func UnescapeHTML(s string) string

UnescapeHTML is an alias for html.UnescapeString.

func WrapHTML(s string, tag string, attrs map[string]string) string

WrapHTML wraps s within HTML tag having attributes attrs. Note, WrapHTML does not escape s value.

func WrapHTMLF(tag string, attrs map[string]string) func(string) string

WrapHTMLF is the filter form of WrapHTML.

str's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

str's Issues

godo.v2/util/prompt.go:22:9: cannot assign 1 values to 2 variables

Hi,

With the latest versions of everything (except howeyc-gopass stuck at 2c70fa7 due to go-godo/godo#44 )

  • go test -compiler gc -ldflags ' -extldflags '''-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ''''
    ~/build/BUILD/str-1.2.0/_build/src/github.com/mgutz/str/Gododir ~/build/BUILD/str-1.2.0

gopkg.in/godo.v2/util

/usr/share/gocode/src/gopkg.in/godo.v2/util/prompt.go:22:9: cannot assign 1 values to 2 variables

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.