File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -47,3 +47,22 @@ func MessageUnescape(text string) string {
47
47
text = strings .ReplaceAll (text , ">" , ">" )
48
48
return text
49
49
}
50
+
51
+ // UnderlineToCamel convert abc_def to AbcDef
52
+ func UnderlineToCamel (s string ) string {
53
+ sb := strings.Builder {}
54
+ isnextupper := true
55
+ for _ , c := range []byte (strings .ToLower (s )) {
56
+ if c == '_' {
57
+ isnextupper = true
58
+ continue
59
+ }
60
+ if isnextupper {
61
+ sb .WriteString (strings .ToUpper (string (c )))
62
+ isnextupper = false
63
+ continue
64
+ }
65
+ sb .WriteByte (c )
66
+ }
67
+ return sb .String ()
68
+ }
Original file line number Diff line number Diff line change
1
+ package nano
2
+
3
+ import "testing"
4
+
5
+ func TestUnderlineToCamel (t * testing.T ) {
6
+ x := UnderlineToCamel ("GUILD_CREATE" )
7
+ if x != "GuildCreate" {
8
+ t .Fatal ("expected GuildCreate but got" , x )
9
+ }
10
+ x = UnderlineToCamel ("GUILD_MEMBER_UPDATE" )
11
+ if x != "GuildMemberUpdate" {
12
+ t .Fatal ("expected GuildMemberUpdate but got" , x )
13
+ }
14
+ x = UnderlineToCamel ("OPEN_FORUM_THREAD_CREATE" )
15
+ if x != "OpenForumThreadCreate" {
16
+ t .Fatal ("expected OpenForumThreadCreate but got" , x )
17
+ }
18
+ x = UnderlineToCamel ("AUDIO_OR_LIVE_CHANNEL_MEMBER_ENTER" )
19
+ if x != "AudioOrLiveChannelMemberEnter" {
20
+ t .Fatal ("expected AudioOrLiveChannelMemberEnter but got" , x )
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments