Skip to content

Commit da81308

Browse files
committed
ToSnakeCase = strutil.ToSnakeCase
1 parent b006361 commit da81308

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.21
44

55
require (
66
github.com/domonda/go-errs v0.0.0-20230810132956-1b6272f9fc8f
7-
github.com/domonda/go-types v0.0.0-20230810134814-bd15ee23faf5
7+
github.com/domonda/go-types v0.0.0-20230829145420-30f9974e0bc7
88
github.com/go-sql-driver/mysql v1.7.1
99
github.com/lib/pq v1.10.9
1010
github.com/stretchr/testify v1.8.4

go.sum

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ github.com/domonda/go-errs v0.0.0-20230810132956-1b6272f9fc8f h1:OQaXlKXZc52Vsz7
44
github.com/domonda/go-errs v0.0.0-20230810132956-1b6272f9fc8f/go.mod h1:DYkFE3rxUGhTCMmR5MpQ2NTtoCPiORdjBATGkIEeGKM=
55
github.com/domonda/go-pretty v0.0.0-20230810130018-8920f571470a h1:b3a6MwwMrHR9dw6585e3Ky51T50OKuD3fRuLyh8ziEw=
66
github.com/domonda/go-pretty v0.0.0-20230810130018-8920f571470a/go.mod h1:3QkM8UJdyJMeKZiIo7hYzSkQBpRS3k0gOHw4ysyEIB4=
7-
github.com/domonda/go-types v0.0.0-20230810133443-7fcb0a5a218b h1:owt4+9DbUZvPYKjUfUnE+unOlVmJ35CItJTM2Sr8iwk=
8-
github.com/domonda/go-types v0.0.0-20230810133443-7fcb0a5a218b/go.mod h1:qMSeU/23ZUopt+1kY0pJ27iqNRtsY1jATQklyCyLRAU=
9-
github.com/domonda/go-types v0.0.0-20230810134814-bd15ee23faf5 h1:hILmOg7w0+ozEd/AXCiGlCt0MsnD7cp5drmrq2D3xtc=
10-
github.com/domonda/go-types v0.0.0-20230810134814-bd15ee23faf5/go.mod h1:qMSeU/23ZUopt+1kY0pJ27iqNRtsY1jATQklyCyLRAU=
7+
github.com/domonda/go-types v0.0.0-20230829145420-30f9974e0bc7 h1:riEK9SQ1O0ADGI66P1Rz2zqB+g3qlREm/wF7DINj7RI=
8+
github.com/domonda/go-types v0.0.0-20230829145420-30f9974e0bc7/go.mod h1:qMSeU/23ZUopt+1kY0pJ27iqNRtsY1jATQklyCyLRAU=
119
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
1210
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
1311
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@@ -23,8 +21,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
2321
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2422
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
2523
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
26-
github.com/ungerik/go-reflection v0.0.0-20220113085621-6c5fc1f2694a h1:9vfYtqoyrPw08TbSLxkSXEflp6iXa3RL86Qjs+DrVas=
27-
github.com/ungerik/go-reflection v0.0.0-20220113085621-6c5fc1f2694a/go.mod h1:6Hnd2/4g3Tpt6TjvxHx8wXOZziwApVxRdIGkr7vNpXs=
2824
github.com/ungerik/go-reflection v0.0.0-20230810134712-a63435f6bc7e h1:BPksMeVdgSD8L4yXHYSY3HpdJ/5z2Ok5lF6PxHIVgEQ=
2925
github.com/ungerik/go-reflection v0.0.0-20230810134712-a63435f6bc7e/go.mod h1:1Q14POg/xa/P6/hWKfnUexqUhW1X6jgw+6gG7lOne1E=
3026
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

structfieldmapping.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import (
44
"fmt"
55
"reflect"
66
"strings"
7-
"unicode"
7+
8+
"github.com/domonda/go-types/strutil"
89
)
910

1011
// FieldFlag is a bitmask for special properties
@@ -59,6 +60,9 @@ func NewTaggedStructFieldMapping() *TaggedStructFieldMapping {
5960
// Implements StructFieldMapper.
6061
var DefaultStructFieldMapping = NewTaggedStructFieldMapping()
6162

63+
// TaggedStructFieldMapping implements StructFieldMapper
64+
var _ StructFieldMapper = new(TaggedStructFieldMapping)
65+
6266
// TaggedStructFieldMapping implements StructFieldMapper with a struct field NameTag
6367
// to be used for naming and a UntaggedNameFunc in case the NameTag is not set.
6468
type TaggedStructFieldMapping struct {
@@ -141,18 +145,6 @@ func IgnoreStructField(string) string { return "" }
141145
// ToSnakeCase converts s to snake case
142146
// by lower casing everything and inserting '_'
143147
// before every new upper case character in s.
144-
func ToSnakeCase(s string) string {
145-
var b strings.Builder
146-
b.Grow(len(s) + 2)
147-
lastWasUpper := true
148-
for _, r := range s {
149-
lr := unicode.ToLower(r)
150-
isUpper := lr != r
151-
if isUpper && !lastWasUpper {
152-
b.WriteByte('_')
153-
}
154-
b.WriteRune(lr)
155-
lastWasUpper = isUpper
156-
}
157-
return b.String()
158-
}
148+
// Whitespace, symbol, and punctuation characters
149+
// will be replace by '_'.
150+
var ToSnakeCase = strutil.ToSnakeCase

0 commit comments

Comments
 (0)