diff options
-rw-r--r-- | pkg/commands/exec_live_default.go | 3 | ||||
-rw-r--r-- | pkg/commands/os.go | 3 | ||||
-rw-r--r-- | pkg/commands/string-to-args.go | 114 | ||||
-rw-r--r-- | vendor/github.com/mgutz/str/CREDITS | 5 | ||||
-rw-r--r-- | vendor/github.com/mgutz/str/LICENSE | 21 | ||||
-rw-r--r-- | vendor/github.com/mgutz/str/README.md | 649 | ||||
-rw-r--r-- | vendor/github.com/mgutz/str/VERSION | 1 | ||||
-rw-r--r-- | vendor/github.com/mgutz/str/doc.go | 19 | ||||
-rw-r--r-- | vendor/github.com/mgutz/str/funcsAO.go | 337 | ||||
-rw-r--r-- | vendor/github.com/mgutz/str/funcsPZ.go | 534 | ||||
-rw-r--r-- | vendor/github.com/mgutz/str/str_test.go | 696 | ||||
-rw-r--r-- | vendor/vendor.json | 6 |
12 files changed, 2272 insertions, 116 deletions
diff --git a/pkg/commands/exec_live_default.go b/pkg/commands/exec_live_default.go index 9e39585bc..685974a1b 100644 --- a/pkg/commands/exec_live_default.go +++ b/pkg/commands/exec_live_default.go @@ -11,6 +11,7 @@ import ( "unicode/utf8" "github.com/kr/pty" + "github.com/mgutz/str" ) // RunCommandWithOutputLiveWrapper runs a command and return every word that gets written in stdout @@ -21,7 +22,7 @@ import ( func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) { cmdOutput := []string{} - splitCmd := ToArgv(command) + splitCmd := str.ToArgv(command) cmd := exec.Command(splitCmd[0], splitCmd[1:]...) cmd.Env = os.Environ() diff --git a/pkg/commands/os.go b/pkg/commands/os.go index 65e25271b..7f2ddde25 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -9,6 +9,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/mgutz/str" "github.com/sirupsen/logrus" gitconfig "github.com/tcnksm/go-gitconfig" ) @@ -49,7 +50,7 @@ func NewOSCommand(log *logrus.Entry, config config.AppConfigurer) *OSCommand { // RunCommandWithOutput wrapper around commands returning their output and error func (c *OSCommand) RunCommandWithOutput(command string) (string, error) { c.Log.WithField("command", command).Info("RunCommand") - splitCmd := ToArgv(command) + splitCmd := str.ToArgv(command) c.Log.Info(splitCmd) return sanitisedCommandOutput( c.command(splitCmd[0], splitCmd[1:]...).CombinedOutput(), diff --git a/pkg/commands/string-to-args.go b/pkg/commands/string-to-args.go deleted file mode 100644 index 88999e9bd..000000000 --- a/pkg/commands/string-to-args.go +++ /dev/null @@ -1,114 +0,0 @@ -// ToArgv is copied from github.com/mgutz/str - -package commands - -import "runtime" - -// ToArgv converts string s into an argv for exec. -func ToArgv(s string) []string { - const ( - InArg = iota - InArgQuote - OutOfArg - ) - currentState := OutOfArg - currentQuoteChar := "\x00" // to distinguish between ' and " quotations - // this allows to use "foo'bar" - currentArg := "" - argv := []string{} - - isQuote := func(c string) bool { - return c == `"` || c == `'` - } - - isEscape := func(c string) bool { - return c == `\` - } - - isWhitespace := func(c string) bool { - return c == " " || c == "\t" - } - - L := len(s) - for i := 0; i < L; i++ { - c := s[i : i+1] - - //fmt.Printf("c %s state %v arg %s argv %v i %d\n", c, currentState, currentArg, args, i) - if isQuote(c) { - switch currentState { - case OutOfArg: - currentArg = "" - fallthrough - case InArg: - currentState = InArgQuote - currentQuoteChar = c - - case InArgQuote: - if c == currentQuoteChar { - currentState = InArg - } else { - currentArg += c - } - } - - } else if isWhitespace(c) { - switch currentState { - case InArg: - argv = append(argv, currentArg) - currentState = OutOfArg - case InArgQuote: - currentArg += c - case OutOfArg: - // nothing - } - - } else if isEscape(c) { - switch currentState { - case OutOfArg: - currentArg = "" - currentState = InArg - fallthrough - case InArg: - fallthrough - case InArgQuote: - if i == L-1 { - if runtime.GOOS == "windows" { - // just add \ to end for windows - currentArg += c - } else { - panic("Escape character at end string") - } - } else { - if runtime.GOOS == "windows" { - peek := s[i+1 : i+2] - if peek != `"` { - currentArg += c - } - } else { - i++ - c = s[i : i+1] - currentArg += c - } - } - } - } else { - switch currentState { - case InArg, InArgQuote: - currentArg += c - - case OutOfArg: - currentArg = "" - currentArg += c - currentState = InArg - } - } - } - - if currentState == InArg { - argv = append(argv, currentArg) - } else if currentState == InArgQuote { - panic("Starting quote has no ending quote.") - } - - return argv -} diff --git a/vendor/github.com/mgutz/str/CREDITS b/vendor/github.com/mgutz/str/CREDITS new file mode 100644 index 000000000..ddb244c30 --- /dev/null +++ b/vendor/github.com/mgutz/str/CREDITS @@ -0,0 +1,5 @@ +* [string.js](http://stringjs.com) - I contributed several + functions to this project. + +* [bbgen.net](http://bbgen.net/blog/2011/06/string-to-argc-argv/) + diff --git a/vendor/github.com/mgutz/str/LICENSE b/vendor/github.com/mgutz/str/LICENSE new file mode 100644 index 000000000..6045e6c75 --- /dev/null +++ b/vendor/github.com/mgutz/str/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013-2014 Mario L. Gutierrez <mario@mgutz.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/mgutz/str/README.md b/vendor/github.com/mgutz/str/README.md new file mode 100644 index 000000000..bce814bc2 --- /dev/null +++ b/vendor/github.com/mgutz/str/README.md @@ -0,0 +1,649 @@ +# 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](#variables) +* [func Between](#func +[godoc](https://godoc.org/github.com/mgutz/str) +between) +* [func BetweenF](#func--betweenf) +* [func Camelize](#func--camelize) +* [func Capitalize](#func--capitalize) +* [func CharAt](#func--charat) +* [func CharAtF](#func--charatf) +* [func ChompLeft](#func--chompleft) +* [func ChompLeftF](#func--chompleftf) +* [func ChompRight](#func--chompright) +* [func ChompRightF](#func--chomprightf) +* [func Classify](#func--classify) +* [func ClassifyF](#func--classifyf) +* [func Clean](#func--clean) +* [func Dasherize](#func--dasherize) +* [func DecodeHTMLEntities](#func--decodehtmlentities) +* [func EnsurePrefix](#func--ensureprefix) +* [func EnsurePrefixF](#func--ensureprefixf) +* [func EnsureSuffix](#func--ensuresuffix) +* [func EnsureSuffixF](#func--ensuresuffixf) +* [func EscapeHTML](#func--escapehtml) +* [func Humanize](#func--humanize) +* [func Iif](#func--iif) +* [func IndexOf](#func--indexof) +* [func IsAlpha](#func--isalpha) +* [func IsAlphaNumeric](#func--isalphanumeric) +* [func IsEmpty](#func--isempty) +* [func IsLower](#func--islower) +* [func IsNumeric](#func--isnumeric) +* [func IsUpper](#func--isupper) +* [func Left](#func--left) +* [func LeftF](#func--leftf) +* [func LeftOf](#func--leftof) +* [func Letters](#func--letters) +* [func Lines](#func--lines) +* [func Map](#func--map) +* [func Match](#func--match) +* [func Pad](#func--pad) +* [func PadF](#func--padf) +* [func PadLeft](#func--padleft) +* [func PadLeftF](#func--padleftf) +* [func PadRight](#func--padright) +* [func PadRightF](#func--padrightf) +* [func Pipe](#func--pipe) +* [func QuoteItems](#func--quoteitems) +* [func ReplaceF](#func--replacef) +* [func ReplacePattern](#func--replacepattern) +* [func ReplacePatternF](#func--replacepatternf) +* [func Reverse](#func--reverse) +* [func Right](#func--right) +* [func RightF](#func--rightf) +* [func RightOf](#func--rightof) +* [func SetTemplateDelimiters](#func--settemplatedelimiters) +* [func Slice](#func--slice) +* [func SliceContains](#func--slicecontains) +* [func SliceF](#func--slicef) +* [func SliceIndexOf](#func--sliceindexof) +* [func Slugify](#func--slugify) +* [func StripPunctuation](#func--strippunctuation) +* [func StripTags](#func--striptags) +* [func Substr](#func--substr) +* [func SubstrF](#func--substrf) +* [func Template](#func--template) +* [func TemplateDelimiters](#func--templatedelimiters) +* [func TemplateWithDelimiters](#func--templatewithdelimiters) +* [func ToArgv](#func--toargv) +* [func ToBool](#func--tobool) +* [func ToBoolOr](#func--toboolor) +* [func ToFloat32Or](#func--tofloat32or) +* [func ToFloat64Or](#func--tofloat64or) +* [func ToIntOr](#func--tointor) +* [func Underscore](#func--underscore) +* [func UnescapeHTML](#func--unescapehtml) +* [func WrapHTML](#func--wraphtml) +* [func WrapHTMLF](#func--wraphtmlf) + + +#### Variables + +```go +var ToFloatOr = ToFloat64Or +``` +ToFloatOr parses as a float64 or returns defaultValue. + +```go +var Verbose = false +``` +Verbose flag enables console output for those functions that have counterparts +in Go's excellent stadard packages. + +#### func [Between](#between) + +```go +func Between(s, left, right string) string +``` +Between extracts a string between left and right strings. + +#### func [BetweenF](#betweenf) + +```go +func BetweenF(left, right string) func(string) string +``` +BetweenF is the filter form for Between. + +#### func [Camelize](#camelize) + +```go +func Camelize(s string) string +``` +Camelize return new string which removes any underscores or dashes and convert a +string into camel casing. + +#### func [Capitalize](#capitalize) + +```go +func Capitalize(s string) string +``` +Capitalize uppercases the first char of s and lowercases the rest. + +#### func [CharAt](#charat) + +```go +func CharAt(s string, index int) string +``` +CharAt returns a string from the character at the specified position. + +#### func [CharAtF](#charatf) + +```go +func CharAtF(index int) func(string) string +``` +CharAtF is the filter form of CharAt. + +#### func [ChompLeft](#chompleft) + +```go +func ChompLeft(s, prefix string) string +``` +ChompLeft removes prefix at the start of a string. + +#### func [ChompLeftF](#chompleftf) + +```go +func ChompLeftF(prefix string) func(string) string +``` +ChompLeftF is the filter form of ChompLeft. + +#### func [ChompRight](#chompright) + +```go +func ChompRight(s, suffix string) string +``` +ChompRight removes suffix from end of s. + +#### func [ChompRightF](#chomprightf) + +```go +func ChompRightF(suffix string) func(string) string +``` +ChompRightF is the filter form of ChompRight. + +#### func [Classify](#classify) + +```go +func Classify(s string) string +``` +Classify returns a camelized string with the first letter upper cased. + +#### func [ClassifyF](#classifyf) + +```go +func ClassifyF(s string) func(string) string +``` +ClassifyF is the filter form of Classify. + +#### func [Clean](#clean) + +```go +func Clean(s string) string +``` +Clean compresses all adjacent whitespace to a single space and trims s. + +#### func [Dasherize](#dasherize) + +```go +func Dasherize(s string) string +``` +Dasherize converts a camel cased string into a string delimited by dashes. + +#### func [DecodeHTMLEntities](#decodehtmlentities) + +```go +func DecodeHTMLEntities(s string) string +``` +DecodeHTMLEntities decodes HTML entities into their proper string +representation. DecodeHTMLEntities is an alias for html.UnescapeString + +#### func [EnsurePrefix](#ensureprefix) + +```go +func EnsurePrefix(s, prefix string) string +``` +EnsurePrefix ensures s starts with prefix. + +#### func [EnsurePrefixF](#ensureprefixf) + +```go +func EnsurePrefixF(prefix string) func(string) string +``` +EnsurePrefixF is the filter form of EnsurePrefix. + +#### func [EnsureSuffix](#ensuresuffix) + +```go +func EnsureSuffix(s, suffix string) string +``` +EnsureSuffix ensures s ends with suffix. + +#### func [EnsureSuffixF](#ensuresuffixf) + +```go +func EnsureSuffixF(suffix string) func(string) string +``` +EnsureSuffixF is the filter form of EnsureSuffix. + +#### func [EscapeHTML](#escapehtml) + +```go +func EscapeHTML(s string) string +``` +EscapeHTML is alias for html.EscapeString. + +#### func [Humanize](#humanize) + +```go +func Humanize(s string) string +``` +Humanize transforms s into a human friendly form. + +#### func [Iif](#iif) + +```go +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](#indexof) + +```go +func IndexOf(s string, needle string, start int) int +``` +IndexOf finds the index of needle in s starting from start. + +#### func [IsAlpha](#isalpha) + +```go +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](#isalphanumeric) + +```go +func IsAlphaNumeric(s string) bool +``` +IsAlphaNumeric returns true if a string contains letters and digits. + +#### func [IsEmpty](#isempty) + +```go +func IsEmpty(s string) bool +``` +IsEmpty returns true if the string is solely composed of whitespace. + +#### func [IsLower](#islower) + +```go +func IsLower(s string) bool +``` +IsLower returns true if s comprised of all lower case characters. + +#### func [IsNumeric](#isnumeric) + +```go +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](#isupper) + +```go +func IsUpper(s string) bool +``` +IsUpper returns true if s contains all upper case chracters. + +#### func [Left](#left) + +```go +func Left(s string, n int) string +``` +Left returns the left substring of length n. + +#### func [LeftF](#leftf) + +```go +func LeftF(n int) func(string) string +``` +LeftF is the filter form of Left. + +#### func [LeftOf](#leftof) + +```go +func LeftOf(s string, needle string) string +``` +LeftOf returns the substring left of needle. + +#### func [Letters](#letters) + +```go +func Letters(s string) []string +``` +Letters returns an array of runes as strings so it can be indexed into. + +#### func [Lines](#lines) + +```go +func Lines(s string) []string +``` +Lines convert windows newlines to unix newlines then convert to an Array of +lines. + +#### func [Map](#map) + +```go +func Map(arr []string, iterator func(string) string) []string +``` +Map maps an array's iitem through an iterator. + +#### func [Match](#match) + +```go +func Match(s, pattern string) bool +``` +Match returns true if patterns matches the string + +#### func [Pad](#pad) + +```go +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](#padf) + +```go +func PadF(c string, n int) func(string) string +``` +PadF is the filter form of Pad. + +#### func [PadLeft](#padleft) + +```go +func PadLeft(s, c string, n int) string +``` +PadLeft pads s on left side with c until it has length of n. + +#### func [PadLeftF](#padleftf) + +```go +func PadLeftF(c string, n int) func(string) string +``` +PadLeftF is the filter form of PadLeft. + +#### func [PadRight](#padright) + +```go +func PadRight(s, c string, n int) string +``` +PadRight pads s on right side with c until it has length of n. + +#### func [PadRightF](#padrightf) + +```go +func PadRightF(c string, n int) func(string) string +``` +PadRightF is the filter form of Padright + +#### func [Pipe](#pipe) + +```go +func Pipe(s string, funcs ...func(string) string) string +``` +Pipe pipes s through one or more string filters. + +#### func [QuoteItems](#quoteitems) + +```go +func QuoteItems(arr []string) []string +``` +QuoteItems quotes all items in array, mostly for debugging. + +#### func [ReplaceF](#replacef) + +```go +func ReplaceF(old, new string, n int) func(string) string +``` +ReplaceF is the filter form of strings.Replace. + +#### func [ReplacePattern](#replacepattern) + +```go +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](#replacepatternf) + +```go +func ReplacePatternF(pattern, repl string) func(string) string +``` +ReplacePatternF is the filter form of ReplaceRegexp. + +#### func [Reverse](#reverse) + +```go +func Reverse(s string) string +``` +Reverse a string + +#### func [Right](#right) + +```go +func Right(s string, n int) string +``` +Right returns the right substring of length n. + +#### func [RightF](#rightf) + +```go +func RightF(n int) func(string) string +``` +RightF is the Filter version of Right. + +#### func [RightOf](#rightof) + +```go +func RightOf(s string, prefix string) string +``` +RightOf returns the substring to the right of prefix. + +#### func [SetTemplateDelimiters](#settemplatedelimiters) + +```go +func SetTemplateDelimiters(opening, closing string) +``` +SetTemplateDelimiters sets the delimiters for Template function. Defaults to +"{{" and "}}" + +#### func [Slice](#slice) + +```go +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](#slicecontains) + +```go +func SliceContains(slice []string, val string) bool +``` +SliceContains determines whether val is an element in slice. + +#### func [SliceF](#slicef) + +```go +func SliceF(start, end int) func(string) string +``` +SliceF is the filter for Slice. + +#### func [SliceIndexOf](#sliceindexof) + +```go +func SliceIndexOf(slice []string, val string) int +``` +SliceIndexOf gets the indx of val in slice. Returns -1 if not found. + +#### func [Slugify](#slugify) + +```go +func Slugify(s string) string +``` +Slugify converts s into a dasherized string suitable for URL segment. + +#### func [StripPunctuation](#strippunctuation) + +```go +func StripPunctuation(s string) string +``` +StripPunctuation strips puncation from string. + +#### func [StripTags](#striptags) + +```go +func StripTags(s string, tags ...string) string +``` +StripTags strips all of the html tags or tags specified by the parameters + +#### func [Substr](#substr) + +```go +func Substr(s string, index int, n int) string +``` +Substr returns a substring of s starting at index of length n. + +#### func [SubstrF](#substrf) + +```go +func SubstrF(index, n int) func(string) string +``` +SubstrF is the filter form of Substr. + +#### func [Template](#template) + +```go +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](#templatedelimiters) + +```go +func TemplateDelimiters() (opening string, closing string) +``` +TemplateDelimiters is the getter for the opening and closing delimiters for +Template. + +#### func [TemplateWithDelimiters](#templatewithdelimiters) + +```go +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](#toargv) + +```go +func ToArgv(s string) []string +``` +ToArgv converts string s into an argv for exec. + +#### func [ToBool](#tobool) + +```go +func ToBool(s string) bool +``` +ToBool fuzzily converts truthy values. + +#### func [ToBoolOr](#toboolor) + +```go +func ToBoolOr(s string, defaultValue bool) bool +``` +ToBoolOr parses s as a bool or returns defaultValue. + +#### func [ToFloat32Or](#tofloat32or) + +```go +func ToFloat32Or(s string, defaultValue float32) float32 +``` +ToFloat32Or parses as a float32 or returns defaultValue on error. + +#### func [ToFloat64Or](#tofloat64or) + +```go +func ToFloat64Or(s string, defaultValue float64) float64 +``` +ToFloat64Or parses s as a float64 or returns defaultValue. + +#### func [ToIntOr](#tointor) + +```go +func ToIntOr(s string, defaultValue int) int +``` +ToIntOr parses s as an int or returns defaultValue. + +#### func [Underscore](#underscore) + +```go +func Underscore(s string) string +``` +Underscore returns converted camel cased string into a string delimited by +underscores. + +#### func [UnescapeHTML](#unescapehtml) + +```go +func UnescapeHTML(s string) string +``` +UnescapeHTML is an alias for html.UnescapeString. + +#### func [WrapHTML](#wraphtml) + +```go +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](#wraphtmlf) + +```go +func WrapHTMLF(tag string, attrs map[string]string) func(string) string +``` +WrapHTMLF is the filter form of WrapHTML. diff --git a/vendor/github.com/mgutz/str/VERSION b/vendor/github.com/mgutz/str/VERSION new file mode 100644 index 000000000..9084fa2f7 --- /dev/null +++ b/vendor/github.com/mgutz/str/VERSION @@ -0,0 +1 @@ +1.1.0 diff --git a/vendor/github.com/mgutz/str/doc.go b/vendor/github.com/mgutz/str/doc.go new file mode 100644 index 000000000..f48742a1f --- /dev/null +++ b/vendor/github.com/mgutz/str/doc.go @@ -0,0 +1,19 @@ +// 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 +// +package str diff --git a/vendor/github.com/mgutz/str/funcsAO.go b/vendor/github.com/mgutz/str/funcsAO.go new file mode 100644 index 000000000..fd17c1c12 --- /dev/null +++ b/vendor/github.com/mgutz/str/funcsAO.go @@ -0,0 +1,337 @@ +package str + +import ( + "fmt" + "html" + //"log" + "regexp" + "strings" +) + +// Verbose flag enables console output for those functions that have +// counterparts in Go's excellent stadard packages. +var Verbose = false +var templateOpen = "{{" +var templateClose = "}}" + +var beginEndSpacesRe = regexp.MustCompile("^\\s+|\\s+$") +var camelizeRe = regexp.MustCompile(`(\-|_|\s)+(.)?`) +var camelizeRe2 = regexp.MustCompile(`(\-|_|\s)+`) +var capitalsRe = regexp.MustCompile("([A-Z])") +var dashSpaceRe = regexp.MustCompile(`[-\s]+`) +var dashesRe = regexp.MustCompile("-+") +var isAlphaNumericRe = regexp.MustCompile(`[^0-9a-z\xC0-\xFF]`) +var isAlphaRe = regexp.MustCompile(`[^a-z\xC0-\xFF]`) +var nWhitespaceRe = regexp.MustCompile(`\s+`) +var notDigitsRe = regexp.MustCompile(`[^0-9]`) +var slugifyRe = regexp.MustCompile(`[^\w\s\-]`) +var spaceUnderscoreRe = regexp.MustCompile("[_\\s]+") +var spacesRe = regexp.MustCompile("[\\s\\xA0]+") +var stripPuncRe = regexp.MustCompile(`[^\w\s]|_`) +var templateRe = regexp.MustCompile(`([\-\[\]()*\s])`) +var templateRe2 = regexp.MustCompile(`\$`) +var underscoreRe = regexp.MustCompile(`([a-z\d])([A-Z]+)`) +var whitespaceRe = regexp.MustCompile(`^[\s\xa0]*$`) + +func min(a, b int) int { + if a < b { + return a + } + return b +} + +func max(a, b int) int { + if a > b { + return a + } + return b +} + +// Between extracts a string between left and right strings. +func Between(s, left, right string) string { + l := len(left) + startPos := strings.Index(s, left) + if startPos < 0 { + return "" + } + endPos := IndexOf(s, right, startPos+l) + //log.Printf("%s: left %s right %s start %d end %d", s, left, right, startPos+l, endPos) + if endPos < 0 { + return "" + } else if right == "" { + return s[endPos:] + } else { + return s[startPos+l : endPos] + } +} + +// BetweenF is the filter form for Between. +func BetweenF(left, right string) func(string) string { + return func(s string) string { + return Between(s, left, right) + } +} + +// Camelize return new string which removes any underscores or dashes and convert a string into camel casing. +func Camelize(s string) string { + return camelizeRe.ReplaceAllStringFunc(s, func(val string) string { + val = strings.ToUpper(val) + val = camelizeRe2.ReplaceAllString(val, "") + return val + }) +} + +// Capitalize uppercases the first char of s and lowercases the rest. +func Capitalize(s string) string { + return strings.ToUpper(s[0:1]) + strings.ToLower(s[1:]) +} + +// CharAt returns a string from the character at the specified position. +func CharAt(s string, index int) string { + l := len(s) + shortcut := index < 0 || index > l-1 || l == 0 + if shortcut { + return "" + } + return s[index : index+1] +} + +// CharAtF is the filter form of CharAt. +func CharAtF(index int) func(string) string { + return func(s string) string { + return CharAt(s, index) + } +} + +// ChompLeft removes prefix at the start of a string. +func ChompLeft(s, prefix string) string { + if strings.HasPrefix(s, prefix) { + return s[len(prefix):] + } + return s +} + +// ChompLeftF is the filter form of ChompLeft. |