Skip to content

Commit

Permalink
builtin: fix assert '_ISspace'.camel_to_snake() == '_i_sspace' (vla…
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored and raw-bin committed Jul 2, 2024
1 parent 5a38b3c commit 6019991
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions vlib/builtin/string.v
Original file line number Diff line number Diff line change
Expand Up @@ -2662,9 +2662,13 @@ pub fn (s string) camel_to_snake() string {
}
lower_first_c, lower_second_c
} else {
lower_first_c := s[0]
second_c := if s[1].is_capital() { u8(`_`) } else { s[1] }
lower_first_c, second_c
first_c := s[0]
second_c := if s[1].is_capital() {
if first_c == `_` { s[1] + 32 } else { u8(`_`) }
} else {
s[1]
}
first_c, second_c
}
unsafe {
b[0] = first_char
Expand Down
1 change: 1 addition & 0 deletions vlib/builtin/string_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,7 @@ fn test_camel_to_snake() {
assert 'BBaa'.camel_to_snake() == 'b_baa'
assert 'aa_BB'.camel_to_snake() == 'aa_bb'
assert 'JVM_PUBLIC_ACC'.camel_to_snake() == 'jvm_public_acc'
assert '_ISspace'.camel_to_snake() == '_i_sspace'
}

fn test_snake_to_camel() {
Expand Down

0 comments on commit 6019991

Please sign in to comment.