summaryrefslogtreecommitdiff
path: root/src/StringUtils.ml
diff options
context:
space:
mode:
authorSon Ho2022-02-03 21:33:46 +0100
committerSon Ho2022-02-03 21:33:46 +0100
commitd8024ac7b85340a33b6034cea620de5b2a2cb5c2 (patch)
tree81722d67eab58ca082c4a6f165d94c11815d9ea2 /src/StringUtils.ml
parent1b9e19381744d94c722adcd73186432fccbcb216 (diff)
Fix an issue with StringUtils.to_snake_case
Diffstat (limited to '')
-rw-r--r--src/StringUtils.ml9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/StringUtils.ml b/src/StringUtils.ml
index 7c628184..adf63151 100644
--- a/src/StringUtils.ml
+++ b/src/StringUtils.ml
@@ -71,9 +71,11 @@ let to_snake_case (s : string) : string =
let apply ((prev_is_low, prev_is_digit, acc) : bool * bool * char list)
(c : char) : bool * bool * char list =
let acc =
- if prev_is_digit then if is_letter_ascii c then '_' :: acc else acc
+ if c = '_' then acc
+ else if prev_is_digit then if is_letter_ascii c then '_' :: acc else acc
else if prev_is_low then
- if is_lowercase_ascii c || is_digit_ascii c then acc else '_' :: acc
+ if (is_lowercase_ascii c || is_digit_ascii c) && c <> '_' then acc
+ else '_' :: acc
else acc
in
let prev_is_low = is_lowercase_ascii c in
@@ -101,4 +103,5 @@ let _ =
assert (to_snake_case "HelloWorld36Hello" = "hello_world36_hello");
assert (to_snake_case "HELLO" = "hello");
assert (to_snake_case "T1" = "t1");
- assert (to_camel_case "list" = "List")
+ assert (to_camel_case "list" = "List");
+ assert (to_snake_case "is_cons" = "is_cons")