-
Notifications
You must be signed in to change notification settings - Fork 0
/
case.go
67 lines (52 loc) · 1.53 KB
/
case.go
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
// Copyright (c) 2018, The GoKi Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package textbuf
import (
"strings"
"github.com/goki/gi/gist"
"github.com/goki/ki/kit"
"github.com/iancoleman/strcase"
)
// Cases are different cases -- Lower, Upper, Camel, etc
type Cases int32
const (
LowerCase Cases = iota
UpperCase
// CamelCase is init-caps
CamelCase
// LowerCamelCase has first letter lower-case
LowerCamelCase
// SnakeCase is snake_case -- lower with underbars
SnakeCase
// UpperSnakeCase is SNAKE_CASE -- upper with underbars
UpperSnakeCase
// KebabCase is kebab-case -- lower with -'s
KebabCase
// CasesN is the number of textview states
CasesN
)
//go:generate stringer -type=Cases
var KiT_Cases = kit.Enums.AddEnum(CasesN, kit.NotBitFlag, gist.StylePropProps)
func (ev Cases) MarshalJSON() ([]byte, error) { return kit.EnumMarshalJSON(ev) }
func (ev *Cases) UnmarshalJSON(b []byte) error { return kit.EnumUnmarshalJSON(ev, b) }
// ReCaseString changes the case of the string according to the given case type.
func ReCaseString(str string, c Cases) string {
switch c {
case LowerCase:
return strings.ToLower(str)
case UpperCase:
return strings.ToUpper(str)
case CamelCase:
return strcase.ToCamel(str)
case LowerCamelCase:
return strcase.ToLowerCamel(str)
case SnakeCase:
return strcase.ToSnake(str)
case UpperSnakeCase:
return strcase.ToScreamingSnake(str)
case KebabCase:
return strcase.ToKebab(str)
}
return str
}