File tree 2 files changed +4
-3
lines changed
2 files changed +4
-3
lines changed Original file line number Diff line number Diff line change 1
1
import re
2
2
3
3
4
- # From this response in Stackoverflow
4
+ # Adapted from this response in Stackoverflow
5
5
# http://stackoverflow.com/a/19053800/1072990
6
6
def to_camel_case (snake_str ):
7
7
components = snake_str .split ('_' )
8
8
# We capitalize the first letter of each component except the first one
9
- # with the 'title ' method and join them together.
10
- return components [0 ] + "" .join (x .title () if x else '_' for x in components [1 :])
9
+ # with the 'capitalize ' method and join them together.
10
+ return components [0 ] + '' .join (x .capitalize () if x else '_' for x in components [1 :])
11
11
12
12
13
13
# From this response in Stackoverflow
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ def test_camel_case():
16
16
assert to_camel_case ('snakes_on_a_plane' ) == 'snakesOnAPlane'
17
17
assert to_camel_case ('snakes_on_a__plane' ) == 'snakesOnA_Plane'
18
18
assert to_camel_case ('i_phone_hysteria' ) == 'iPhoneHysteria'
19
+ assert to_camel_case ('field_i18n' ) == 'fieldI18n'
19
20
20
21
21
22
def test_to_const ():
You can’t perform that action at this time.
0 commit comments