when converting file name from kebab case to pascal case, remove extension if there is any

This commit is contained in:
2025-08-26 15:21:59 +01:00
parent 060e3779f5
commit 6c9149bfaa

View File

@@ -1,6 +1,16 @@
structure CollisionTree =
struct
local
fun findLastDot (str, pos) =
if pos < 0 then ~1
else if String.sub (str, pos) = #"." then pos
else findLastDot (str, pos - 1)
fun removeFileExtension str =
let val lastDot = findLastDot (str, String.size str - 1)
in if lastDot = ~1 then str else String.substring (str, 0, lastDot)
end
fun finish acc =
let val acc = List.rev acc
in String.implode acc
@@ -16,10 +26,14 @@ struct
| loop ([], acc) = finish acc
in
fun kebabCaseToPascalCase str =
(* capitalise first character in string *)
case String.explode str of
chr :: tl => let val chr = Char.toUpper chr in loop (tl, [chr]) end
| [] => ""
let
val str = removeFileExtension str
in
(* capitalise first character in string *)
case String.explode str of
chr :: tl => let val chr = Char.toUpper chr in loop (tl, [chr]) end
| [] => ""
end
end
structure BinTree =