From a6b8dcde35569b34185fc011be4f0f41cf393f3d Mon Sep 17 00:00:00 2001 From: Nathan Baulch Date: Sun, 16 Aug 2020 22:35:25 +1000 Subject: [PATCH] Fix incorrect delimiter between dot and cap --- snake.go | 4 ++-- snake_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/snake.go b/snake.go index 30223f4..159c1b5 100644 --- a/snake.go +++ b/snake.go @@ -78,8 +78,8 @@ func ToScreamingDelimited(s string, delimiter uint8, ignore uint8, screaming boo // add underscore if next letter case type is changed if (vIsCap && nextIsLow) || (vIsLow && nextIsCap) { if prevIgnore := ignore > 0 && i > 0 && s[i-1] == ignore; !prevIgnore { - if i > 0 && vIsCap && nextIsLow { - if prevDelim := len(n) > 0 && n[len(n)-1] == delimiter; !prevDelim { + if vIsCap && nextIsLow { + if prevIsCap := i > 0 && s[i-1] >= 'A' && s[i-1] <= 'Z'; prevIsCap { n += string(delimiter) } } diff --git a/snake_test.go b/snake_test.go index 7f89e4b..5482999 100644 --- a/snake_test.go +++ b/snake_test.go @@ -84,7 +84,7 @@ func toSnakeWithIgnore(tb testing.TB) { {"JSONData", "json_data"}, {"AwesomeActivity.UserID", "awesome_activity.user_id", "."}, {"AwesomeActivity.User.Id", "awesome_activity.user.id", "."}, - {"AwesomeUsername@Awesome.Com", "awesome_username@awesome._com", "@"}, + {"AwesomeUsername@Awesome.Com", "awesome_username@awesome.com", "@"}, } for _, i := range cases { in := i[0]