• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..22-Nov-2021-

str-1.2.0/H23-Jun-2015-2,3261,528

.gitignoreH A D22-Nov-202175 87

CREDITSH A D22-Nov-2021162 63

LICENSEH A D22-Nov-20211.1 KiB2217

README.mdH A D22-Nov-202115 KiB650487

VERSIONH A D22-Nov-20216 21

doc.goH A D22-Nov-2021702 201

funcsAO.goH A D22-Nov-20218.4 KiB338255

funcsPZ.goH A D22-Nov-202112.7 KiB535373

README.md

1# str
2
3    import "github.com/mgutz/str"
4
5Package str is a comprehensive set of string functions to build more Go
6awesomeness. Str complements Go's standard packages and does not duplicate
7functionality found in `strings` or `strconv`.
8
9Str is based on plain functions instead of object-based methods, consistent with
10Go standard string packages.
11
12    str.Between("<a>foo</a>", "<a>", "</a>") == "foo"
13
14Str supports pipelining instead of chaining
15
16    s := str.Pipe("\nabcdef\n", Clean, BetweenF("a", "f"), ChompLeftF("bc"))
17
18User-defined filters can be added to the pipeline by inserting a function or
19closure that returns a function with this signature
20
21    func(string) string
22
23### Index
24
25* [Variables](#variables)
26* [func  Between](#func
27[godoc](https://godoc.org/github.com/mgutz/str)
28between)
29* [func  BetweenF](#func--betweenf)
30* [func  Camelize](#func--camelize)
31* [func  Capitalize](#func--capitalize)
32* [func  CharAt](#func--charat)
33* [func  CharAtF](#func--charatf)
34* [func  ChompLeft](#func--chompleft)
35* [func  ChompLeftF](#func--chompleftf)
36* [func  ChompRight](#func--chompright)
37* [func  ChompRightF](#func--chomprightf)
38* [func  Classify](#func--classify)
39* [func  ClassifyF](#func--classifyf)
40* [func  Clean](#func--clean)
41* [func  Dasherize](#func--dasherize)
42* [func  DecodeHTMLEntities](#func--decodehtmlentities)
43* [func  EnsurePrefix](#func--ensureprefix)
44* [func  EnsurePrefixF](#func--ensureprefixf)
45* [func  EnsureSuffix](#func--ensuresuffix)
46* [func  EnsureSuffixF](#func--ensuresuffixf)
47* [func  EscapeHTML](#func--escapehtml)
48* [func  Humanize](#func--humanize)
49* [func  Iif](#func--iif)
50* [func  IndexOf](#func--indexof)
51* [func  IsAlpha](#func--isalpha)
52* [func  IsAlphaNumeric](#func--isalphanumeric)
53* [func  IsEmpty](#func--isempty)
54* [func  IsLower](#func--islower)
55* [func  IsNumeric](#func--isnumeric)
56* [func  IsUpper](#func--isupper)
57* [func  Left](#func--left)
58* [func  LeftF](#func--leftf)
59* [func  LeftOf](#func--leftof)
60* [func  Letters](#func--letters)
61* [func  Lines](#func--lines)
62* [func  Map](#func--map)
63* [func  Match](#func--match)
64* [func  Pad](#func--pad)
65* [func  PadF](#func--padf)
66* [func  PadLeft](#func--padleft)
67* [func  PadLeftF](#func--padleftf)
68* [func  PadRight](#func--padright)
69* [func  PadRightF](#func--padrightf)
70* [func  Pipe](#func--pipe)
71* [func  QuoteItems](#func--quoteitems)
72* [func  ReplaceF](#func--replacef)
73* [func  ReplacePattern](#func--replacepattern)
74* [func  ReplacePatternF](#func--replacepatternf)
75* [func  Reverse](#func--reverse)
76* [func  Right](#func--right)
77* [func  RightF](#func--rightf)
78* [func  RightOf](#func--rightof)
79* [func  SetTemplateDelimiters](#func--settemplatedelimiters)
80* [func  Slice](#func--slice)
81* [func  SliceContains](#func--slicecontains)
82* [func  SliceF](#func--slicef)
83* [func  SliceIndexOf](#func--sliceindexof)
84* [func  Slugify](#func--slugify)
85* [func  StripPunctuation](#func--strippunctuation)
86* [func  StripTags](#func--striptags)
87* [func  Substr](#func--substr)
88* [func  SubstrF](#func--substrf)
89* [func  Template](#func--template)
90* [func  TemplateDelimiters](#func--templatedelimiters)
91* [func  TemplateWithDelimiters](#func--templatewithdelimiters)
92* [func  ToArgv](#func--toargv)
93* [func  ToBool](#func--tobool)
94* [func  ToBoolOr](#func--toboolor)
95* [func  ToFloat32Or](#func--tofloat32or)
96* [func  ToFloat64Or](#func--tofloat64or)
97* [func  ToIntOr](#func--tointor)
98* [func  Underscore](#func--underscore)
99* [func  UnescapeHTML](#func--unescapehtml)
100* [func  WrapHTML](#func--wraphtml)
101* [func  WrapHTMLF](#func--wraphtmlf)
102
103
104#### Variables
105
106```go
107var ToFloatOr = ToFloat64Or
108```
109ToFloatOr parses as a float64 or returns defaultValue.
110
111```go
112var Verbose = false
113```
114Verbose flag enables console output for those functions that have counterparts
115in Go's excellent stadard packages.
116
117#### func  [Between](#between)
118
119```go
120func Between(s, left, right string) string
121```
122Between extracts a string between left and right strings.
123
124#### func  [BetweenF](#betweenf)
125
126```go
127func BetweenF(left, right string) func(string) string
128```
129BetweenF is the filter form for Between.
130
131#### func  [Camelize](#camelize)
132
133```go
134func Camelize(s string) string
135```
136Camelize return new string which removes any underscores or dashes and convert a
137string into camel casing.
138
139#### func  [Capitalize](#capitalize)
140
141```go
142func Capitalize(s string) string
143```
144Capitalize uppercases the first char of s and lowercases the rest.
145
146#### func  [CharAt](#charat)
147
148```go
149func CharAt(s string, index int) string
150```
151CharAt returns a string from the character at the specified position.
152
153#### func  [CharAtF](#charatf)
154
155```go
156func CharAtF(index int) func(string) string
157```
158CharAtF is the filter form of CharAt.
159
160#### func  [ChompLeft](#chompleft)
161
162```go
163func ChompLeft(s, prefix string) string
164```
165ChompLeft removes prefix at the start of a string.
166
167#### func  [ChompLeftF](#chompleftf)
168
169```go
170func ChompLeftF(prefix string) func(string) string
171```
172ChompLeftF is the filter form of ChompLeft.
173
174#### func  [ChompRight](#chompright)
175
176```go
177func ChompRight(s, suffix string) string
178```
179ChompRight removes suffix from end of s.
180
181#### func  [ChompRightF](#chomprightf)
182
183```go
184func ChompRightF(suffix string) func(string) string
185```
186ChompRightF is the filter form of ChompRight.
187
188#### func  [Classify](#classify)
189
190```go
191func Classify(s string) string
192```
193Classify returns a camelized string with the first letter upper cased.
194
195#### func  [ClassifyF](#classifyf)
196
197```go
198func ClassifyF(s string) func(string) string
199```
200ClassifyF is the filter form of Classify.
201
202#### func  [Clean](#clean)
203
204```go
205func Clean(s string) string
206```
207Clean compresses all adjacent whitespace to a single space and trims s.
208
209#### func  [Dasherize](#dasherize)
210
211```go
212func Dasherize(s string) string
213```
214Dasherize converts a camel cased string into a string delimited by dashes.
215
216#### func  [DecodeHTMLEntities](#decodehtmlentities)
217
218```go
219func DecodeHTMLEntities(s string) string
220```
221DecodeHTMLEntities decodes HTML entities into their proper string
222representation. DecodeHTMLEntities is an alias for html.UnescapeString
223
224#### func  [EnsurePrefix](#ensureprefix)
225
226```go
227func EnsurePrefix(s, prefix string) string
228```
229EnsurePrefix ensures s starts with prefix.
230
231#### func  [EnsurePrefixF](#ensureprefixf)
232
233```go
234func EnsurePrefixF(prefix string) func(string) string
235```
236EnsurePrefixF is the filter form of EnsurePrefix.
237
238#### func  [EnsureSuffix](#ensuresuffix)
239
240```go
241func EnsureSuffix(s, suffix string) string
242```
243EnsureSuffix ensures s ends with suffix.
244
245#### func  [EnsureSuffixF](#ensuresuffixf)
246
247```go
248func EnsureSuffixF(suffix string) func(string) string
249```
250EnsureSuffixF is the filter form of EnsureSuffix.
251
252#### func  [EscapeHTML](#escapehtml)
253
254```go
255func EscapeHTML(s string) string
256```
257EscapeHTML is alias for html.EscapeString.
258
259#### func  [Humanize](#humanize)
260
261```go
262func Humanize(s string) string
263```
264Humanize transforms s into a human friendly form.
265
266#### func  [Iif](#iif)
267
268```go
269func Iif(condition bool, truthy string, falsey string) string
270```
271Iif is short for immediate if. If condition is true return truthy else falsey.
272
273#### func  [IndexOf](#indexof)
274
275```go
276func IndexOf(s string, needle string, start int) int
277```
278IndexOf finds the index of needle in s starting from start.
279
280#### func  [IsAlpha](#isalpha)
281
282```go
283func IsAlpha(s string) bool
284```
285IsAlpha returns true if a string contains only letters from ASCII (a-z,A-Z).
286Other letters from other languages are not supported.
287
288#### func  [IsAlphaNumeric](#isalphanumeric)
289
290```go
291func IsAlphaNumeric(s string) bool
292```
293IsAlphaNumeric returns true if a string contains letters and digits.
294
295#### func  [IsEmpty](#isempty)
296
297```go
298func IsEmpty(s string) bool
299```
300IsEmpty returns true if the string is solely composed of whitespace.
301
302#### func  [IsLower](#islower)
303
304```go
305func IsLower(s string) bool
306```
307IsLower returns true if s comprised of all lower case characters.
308
309#### func  [IsNumeric](#isnumeric)
310
311```go
312func IsNumeric(s string) bool
313```
314IsNumeric returns true if a string contains only digits from 0-9. Other digits
315not in Latin (such as Arabic) are not currently supported.
316
317#### func  [IsUpper](#isupper)
318
319```go
320func IsUpper(s string) bool
321```
322IsUpper returns true if s contains all upper case chracters.
323
324#### func  [Left](#left)
325
326```go
327func Left(s string, n int) string
328```
329Left returns the left substring of length n.
330
331#### func  [LeftF](#leftf)
332
333```go
334func LeftF(n int) func(string) string
335```
336LeftF is the filter form of Left.
337
338#### func  [LeftOf](#leftof)
339
340```go
341func LeftOf(s string, needle string) string
342```
343LeftOf returns the substring left of needle.
344
345#### func  [Letters](#letters)
346
347```go
348func Letters(s string) []string
349```
350Letters returns an array of runes as strings so it can be indexed into.
351
352#### func  [Lines](#lines)
353
354```go
355func Lines(s string) []string
356```
357Lines convert windows newlines to unix newlines then convert to an Array of
358lines.
359
360#### func  [Map](#map)
361
362```go
363func Map(arr []string, iterator func(string) string) []string
364```
365Map maps an array's iitem through an iterator.
366
367#### func  [Match](#match)
368
369```go
370func Match(s, pattern string) bool
371```
372Match returns true if patterns matches the string
373
374#### func  [Pad](#pad)
375
376```go
377func Pad(s, c string, n int) string
378```
379Pad pads string s on both sides with c until it has length of n.
380
381#### func  [PadF](#padf)
382
383```go
384func PadF(c string, n int) func(string) string
385```
386PadF is the filter form of Pad.
387
388#### func  [PadLeft](#padleft)
389
390```go
391func PadLeft(s, c string, n int) string
392```
393PadLeft pads s on left side with c until it has length of n.
394
395#### func  [PadLeftF](#padleftf)
396
397```go
398func PadLeftF(c string, n int) func(string) string
399```
400PadLeftF is the filter form of PadLeft.
401
402#### func  [PadRight](#padright)
403
404```go
405func PadRight(s, c string, n int) string
406```
407PadRight pads s on right side with c until it has length of n.
408
409#### func  [PadRightF](#padrightf)
410
411```go
412func PadRightF(c string, n int) func(string) string
413```
414PadRightF is the filter form of Padright
415
416#### func  [Pipe](#pipe)
417
418```go
419func Pipe(s string, funcs ...func(string) string) string
420```
421Pipe pipes s through one or more string filters.
422
423#### func  [QuoteItems](#quoteitems)
424
425```go
426func QuoteItems(arr []string) []string
427```
428QuoteItems quotes all items in array, mostly for debugging.
429
430#### func  [ReplaceF](#replacef)
431
432```go
433func ReplaceF(old, new string, n int) func(string) string
434```
435ReplaceF is the filter form of strings.Replace.
436
437#### func  [ReplacePattern](#replacepattern)
438
439```go
440func ReplacePattern(s, pattern, repl string) string
441```
442ReplacePattern replaces string with regexp string. ReplacePattern returns a copy
443of src, replacing matches of the Regexp with the replacement string repl. Inside
444repl, $ signs are interpreted as in Expand, so for instance $1 represents the
445text of the first submatch.
446
447#### func  [ReplacePatternF](#replacepatternf)
448
449```go
450func ReplacePatternF(pattern, repl string) func(string) string
451```
452ReplacePatternF is the filter form of ReplaceRegexp.
453
454#### func  [Reverse](#reverse)
455
456```go
457func Reverse(s string) string
458```
459Reverse a string
460
461#### func  [Right](#right)
462
463```go
464func Right(s string, n int) string
465```
466Right returns the right substring of length n.
467
468#### func  [RightF](#rightf)
469
470```go
471func RightF(n int) func(string) string
472```
473RightF is the Filter version of Right.
474
475#### func  [RightOf](#rightof)
476
477```go
478func RightOf(s string, prefix string) string
479```
480RightOf returns the substring to the right of prefix.
481
482#### func  [SetTemplateDelimiters](#settemplatedelimiters)
483
484```go
485func SetTemplateDelimiters(opening, closing string)
486```
487SetTemplateDelimiters sets the delimiters for Template function. Defaults to
488"{{" and "}}"
489
490#### func  [Slice](#slice)
491
492```go
493func Slice(s string, start, end int) string
494```
495Slice slices a string. If end is negative then it is the from the end of the
496string.
497
498#### func  [SliceContains](#slicecontains)
499
500```go
501func SliceContains(slice []string, val string) bool
502```
503SliceContains determines whether val is an element in slice.
504
505#### func  [SliceF](#slicef)
506
507```go
508func SliceF(start, end int) func(string) string
509```
510SliceF is the filter for Slice.
511
512#### func  [SliceIndexOf](#sliceindexof)
513
514```go
515func SliceIndexOf(slice []string, val string) int
516```
517SliceIndexOf gets the indx of val in slice. Returns -1 if not found.
518
519#### func  [Slugify](#slugify)
520
521```go
522func Slugify(s string) string
523```
524Slugify converts s into a dasherized string suitable for URL segment.
525
526#### func  [StripPunctuation](#strippunctuation)
527
528```go
529func StripPunctuation(s string) string
530```
531StripPunctuation strips puncation from string.
532
533#### func  [StripTags](#striptags)
534
535```go
536func StripTags(s string, tags ...string) string
537```
538StripTags strips all of the html tags or tags specified by the parameters
539
540#### func  [Substr](#substr)
541
542```go
543func Substr(s string, index int, n int) string
544```
545Substr returns a substring of s starting at index of length n.
546
547#### func  [SubstrF](#substrf)
548
549```go
550func SubstrF(index, n int) func(string) string
551```
552SubstrF is the filter form of Substr.
553
554#### func  [Template](#template)
555
556```go
557func Template(s string, values map[string]interface{}) string
558```
559Template is a string template which replaces template placeholders delimited by
560"{{" and "}}" with values from map. The global delimiters may be set with
561SetTemplateDelimiters.
562
563#### func  [TemplateDelimiters](#templatedelimiters)
564
565```go
566func TemplateDelimiters() (opening string, closing string)
567```
568TemplateDelimiters is the getter for the opening and closing delimiters for
569Template.
570
571#### func  [TemplateWithDelimiters](#templatewithdelimiters)
572
573```go
574func TemplateWithDelimiters(s string, values map[string]interface{}, opening, closing string) string
575```
576TemplateWithDelimiters is string template with user-defineable opening and
577closing delimiters.
578
579#### func  [ToArgv](#toargv)
580
581```go
582func ToArgv(s string) []string
583```
584ToArgv converts string s into an argv for exec.
585
586#### func  [ToBool](#tobool)
587
588```go
589func ToBool(s string) bool
590```
591ToBool fuzzily converts truthy values.
592
593#### func  [ToBoolOr](#toboolor)
594
595```go
596func ToBoolOr(s string, defaultValue bool) bool
597```
598ToBoolOr parses s as a bool or returns defaultValue.
599
600#### func  [ToFloat32Or](#tofloat32or)
601
602```go
603func ToFloat32Or(s string, defaultValue float32) float32
604```
605ToFloat32Or parses as a float32 or returns defaultValue on error.
606
607#### func  [ToFloat64Or](#tofloat64or)
608
609```go
610func ToFloat64Or(s string, defaultValue float64) float64
611```
612ToFloat64Or parses s as a float64 or returns defaultValue.
613
614#### func  [ToIntOr](#tointor)
615
616```go
617func ToIntOr(s string, defaultValue int) int
618```
619ToIntOr parses s as an int or returns defaultValue.
620
621#### func  [Underscore](#underscore)
622
623```go
624func Underscore(s string) string
625```
626Underscore returns converted camel cased string into a string delimited by
627underscores.
628
629#### func  [UnescapeHTML](#unescapehtml)
630
631```go
632func UnescapeHTML(s string) string
633```
634UnescapeHTML is an alias for html.UnescapeString.
635
636#### func  [WrapHTML](#wraphtml)
637
638```go
639func WrapHTML(s string, tag string, attrs map[string]string) string
640```
641WrapHTML wraps s within HTML tag having attributes attrs. Note, WrapHTML does
642not escape s value.
643
644#### func  [WrapHTMLF](#wraphtmlf)
645
646```go
647func WrapHTMLF(tag string, attrs map[string]string) func(string) string
648```
649WrapHTMLF is the filter form of WrapHTML.
650