Codebase list golang-github-mgutz-str / HEAD
HEAD

Tree @HEAD (Download .tar.gz)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
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.