@@ -90,7 +90,7 @@ type Tokenizer interface {
90
90
//
91
91
// style: Expected output caps.Style of the string.
92
92
// repStyle: The caps.ReplaceStyle to use if a word needs to be replaced.
93
- // join: The delimiter to use when joining the words. For CamelCase , this is an empty string.
93
+ // join: The delimiter to use when joining the words. For Camel , this is an empty string.
94
94
// allowedSymbols: The set of allowed symbols. If set, these should take precedence over any delimiters
95
95
// numberRules: Any custom rules dictating how to handle special characters in numbers.
96
96
type Formatter interface {
@@ -153,8 +153,6 @@ func (t TokenizerImpl) Tokenize(str string, allowedSymbols []rune, numberRules m
153
153
allowed := newRunes (allowedSymbols )
154
154
155
155
for i , r := range str {
156
- rStr := string (r )
157
- _ = rStr
158
156
switch {
159
157
case unicode .IsUpper (r ):
160
158
if foundLower && current .Len () > 0 {
@@ -304,10 +302,10 @@ type ReplaceStyle uint8
304
302
305
303
type (
306
304
Replacement struct {
307
- // Camelcase variant of the word which should be replaced.
305
+ // Camel case variant of the word which should be replaced.
308
306
// e.g. "Http"
309
307
Camel string
310
- // Screaming (all uppercase ) representation of the word to replace.
308
+ // Screaming (all upper case ) representation of the word to replace.
311
309
// e.g. "HTTP"
312
310
Screaming string
313
311
}
@@ -318,8 +316,8 @@ type Style uint8
318
316
const (
319
317
StyleLower Style = iota // The output should be lowercase (e.g. "an_example")
320
318
StyleScreaming // The output should be screaming (e.g. "AN_EXAMPLE")
321
- StyleCamel // The output should be camelcase (e.g. "AnExample")
322
- StyleLowerCamel // The output should be lower camelcase (e.g. "anExample")
319
+ StyleCamel // The output should be camel case (e.g. "AnExample")
320
+ StyleLowerCamel // The output should be lower camel case (e.g. "anExample")
323
321
)
324
322
325
323
const (
@@ -616,7 +614,7 @@ func loadOpts(opts []Opts) Opts {
616
614
result := Opts {
617
615
AllowedSymbols : "" ,
618
616
Formatter : DefaultFormatter ,
619
- ReplaceStyle : ReplaceStyleNotSpecified ,
617
+ ReplaceStyle : ReplaceStyleScreaming ,
620
618
}
621
619
if len (opts ) == 0 {
622
620
return result
@@ -628,6 +626,13 @@ func loadOpts(opts []Opts) Opts {
628
626
if opts [0 ].Formatter != nil {
629
627
result .Formatter = opts [0 ].Formatter
630
628
}
629
+ if opts [0 ].ReplaceStyle != ReplaceStyleNotSpecified {
630
+ result .ReplaceStyle = opts [0 ].ReplaceStyle
631
+ }
632
+ if opts [0 ].NumberRules != nil {
633
+ result .NumberRules = opts [0 ].NumberRules
634
+ }
635
+
631
636
return result
632
637
}
633
638
@@ -653,22 +658,22 @@ func WithoutNumbers[T ~string](s T) T {
653
658
}, string (s )))
654
659
}
655
660
656
- // ToCamel transforms the case of str into Camelcase (e.g. AnExampleString) using
661
+ // ToCamel transforms the case of str into Camel Case (e.g. AnExampleString) using
657
662
// either the provided Formatter or the DefaultFormatter otherwise.
658
663
//
659
664
// The default Formatter detects case so that "AN_EXAMPLE_STRING" becomes "AnExampleString".
660
665
// It also has a configurable set of replacements, such that "some_json" becomes "SomeJSON"
661
666
// so long as opts.ReplacementStyle is set to ReplaceStyleScreaming. A ReplaceStyle of
662
667
// ReplaceStyleCamel would result in "SomeJson".
663
668
//
664
- // caps.ToCamel("This is [an] {example}${id32}.") // thisIsAnExampleID32
665
- // caps.ToCamel("AN_EXAMPLE_STRING", ) // anExampleString
669
+ // caps.ToCamel("This is [an] {example}${id32}.") // ThisIsAnExampleID32
670
+ // caps.ToCamel("AN_EXAMPLE_STRING", ) // AnExampleString
666
671
func ToCamel [T ~ string ](str T , options ... Opts ) T {
667
672
opts := loadOpts (options )
668
673
return T (opts .Formatter .Format (StyleCamel , opts .ReplaceStyle , string (str ), "" , []rune (opts .AllowedSymbols ), opts .NumberRules ))
669
674
}
670
675
671
- // ToLowerCamel transforms the case of str into Lower Camelcase (e.g. anExampleString) using
676
+ // ToLowerCamel transforms the case of str into Lower Camel Case (e.g. anExampleString) using
672
677
// either the provided Formatter or the DefaultFormatter otherwise.
673
678
//
674
679
// The default Formatter detects case so that "AN_EXAMPLE_STRING" becomes "anExampleString".
@@ -682,15 +687,15 @@ func ToLowerCamel[T ~string](str T, options ...Opts) T {
682
687
return T (opts .Formatter .Format (StyleLowerCamel , opts .ReplaceStyle , string (str ), "" , []rune (opts .AllowedSymbols ), opts .NumberRules ))
683
688
}
684
689
685
- // ToSnake transforms the case of str into Lower Snakecase (e.g. an_example_string) using
690
+ // ToSnake transforms the case of str into Lower Snake Case (e.g. an_example_string) using
686
691
// either the provided Formatter or the DefaultFormatter otherwise.
687
692
//
688
693
// caps.ToSnake("This is [an] {example}${id32}.") // this_is_an_example_id_32
689
694
func ToSnake [T ~ string ](str T , options ... Opts ) T {
690
695
return ToDelimited (str , '_' , true , options ... )
691
696
}
692
697
693
- // ToScreamingSnake transforms the case of str into Screaming Snakecase (e.g.
698
+ // ToScreamingSnake transforms the case of str into Screaming Snake Case (e.g.
694
699
// AN_EXAMPLE_STRING) using either the provided Formatter or the
695
700
// DefaultFormatter otherwise.
696
701
//
@@ -699,41 +704,41 @@ func ToScreamingSnake[T ~string](str T, options ...Opts) T {
699
704
return ToDelimited (str , '_' , false , options ... )
700
705
}
701
706
702
- // ToKebab transforms the case of str into Lower Kebabcase (e.g. an-example-string) using
707
+ // ToKebab transforms the case of str into Lower Kebab Case (e.g. an-example-string) using
703
708
// either the provided Formatter or the DefaultFormatter otherwise.
704
709
//
705
710
// caps.ToKebab("This is [an] {example}${id32}.") // this-is-an-example-id-32
706
711
func ToKebab [T ~ string ](str T , options ... Opts ) T {
707
- return ToDelimited (str , '_ ' , true , options ... )
712
+ return ToDelimited (str , '- ' , true , options ... )
708
713
}
709
714
710
- // ToScreamingKebab transforms the case of str into Screaming Kebab (e.g.
715
+ // ToScreamingKebab transforms the case of str into Screaming Kebab Snake (e.g.
711
716
// AN-EXAMPLE-STRING) using either the provided Formatter or the
712
717
// DefaultFormatter otherwise.
713
718
//
714
- // caps.ToScreamingSnake ("This is [an] {example}${id32}.") // THIS-IS-AN-EXAMPLE-ID-32
719
+ // caps.ToScreamingKebab ("This is [an] {example}${id32}.") // THIS-IS-AN-EXAMPLE-ID-32
715
720
func ToScreamingKebab [T ~ string ](str T , options ... Opts ) T {
716
- return ToDelimited (str , '_ ' , false , options ... )
721
+ return ToDelimited (str , '- ' , false , options ... )
717
722
}
718
723
719
- // ToDot transforms the case of str into Lower Dot notation case (e.g. an.example.string) using
724
+ // ToDot transforms the case of str into Lower Dot Notation Case (e.g. an.example.string) using
720
725
// either the provided Formatter or the DefaultFormatter otherwise.
721
726
//
722
727
// caps.ToDot("This is [an] {example}${id32}.") // this.is.an.example.id.32
723
728
func ToDot [T ~ string ](str T , options ... Opts ) T {
724
- return ToDelimited (str , '_ ' , true , options ... )
729
+ return ToDelimited (str , '. ' , true , options ... )
725
730
}
726
731
727
- // ToScreamingKebab transforms the case of str into Screaming Kebab (e.g.
732
+ // ToScreamingKebab transforms the case of str into Screaming Kebab Case (e.g.
728
733
// AN-EXAMPLE-STRING) using either the provided Formatter or the
729
734
// DefaultFormatter otherwise.
730
735
//
731
736
// caps.ToScreamingDot("This is [an] {example}${id32}.") // THIS.IS.AN.EXAMPLE.ID.32
732
737
func ToScreamingDot [T ~ string ](str T , options ... Opts ) T {
733
- return ToDelimited (str , '_ ' , false , options ... )
738
+ return ToDelimited (str , '. ' , false , options ... )
734
739
}
735
740
736
- // ToTitle transforms the case of str into Lower Dot notation case (e.g. An Example String) using
741
+ // ToTitle transforms the case of str into Title Case (e.g. An Example String) using
737
742
// either the provided Formatter or the DefaultFormatter otherwise.
738
743
//
739
744
// caps.ToTitle("This is [an] {example}${id32}.") // This Is An Example ID 32
@@ -752,8 +757,8 @@ func ToTitle[T ~string](str T, options ...Opts) T {
752
757
// # Example
753
758
//
754
759
// caps.ToDelimited("This is [an] {example}${id}.#32", '.', true) // this.is.an.example.id.32
755
- // caps.ToDelimited("This is [an] {example}${id32 }.break32", '.', false) // THIS.IS.AN.EXAMPLE.ID.BREAK.32
756
- // caps.ToDelimited("This is [an] {example}${id32 }.v32", '.', true, caps.Opts{AllowedSymbols: "$" }) // this.is.an.example.id.$ .v32
760
+ // caps.ToDelimited("This is [an] {example}${id }.break32", '.', false) // THIS.IS.AN.EXAMPLE.ID.BREAK.32
761
+ // caps.ToDelimited("This is [an] {example}${id }.v32", '.', true, caps.Opts{AllowedSymbols: "$"}) // this.is.an.example.$.id .v32
757
762
func ToDelimited [T ~ string ](str T , delimiter rune , lowercase bool , options ... Opts ) T {
758
763
opts := loadOpts (options )
759
764
var style Style
0 commit comments