From 189d92d91a34af9ff255fd5a014a489fb4e17328 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Mon, 9 Feb 2026 13:30:47 +0100 Subject: [PATCH 1/2] Make deSymbolify faster --- src/Common.elm | 61 ++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/Common.elm b/src/Common.elm index a085bc3..23f4a96 100644 --- a/src/Common.elm +++ b/src/Common.elm @@ -250,38 +250,45 @@ deSymbolify replacement str = else let - removeLeadingUnderscores : String -> String - removeLeadingUnderscores acc = - case String.uncons acc of - Nothing -> - "empty__" + replaced : List Char + replaced = + str + |> String.foldl + (\c acc -> + let + code : Int + code = + Char.toCode c + in + if + (code == {- '_' -} 95) + || -- lowercase + (0x61 <= code && code <= 0x7A) + || -- uppercase + (0x41 <= code && code <= 0x5A) + || -- digits + (0x30 <= code && code <= 0x39) + then + c :: acc + + else if List.isEmpty acc then + acc - Just ( head, tail ) -> - if head == replacement then - removeLeadingUnderscores tail - - else if Char.isDigit head then - "N" ++ acc - - else - acc + else + replacement :: acc + ) + [] in - str - |> replaceSymbolsWith replacement - |> removeLeadingUnderscores - + case List.reverse replaced of + [] -> + "empty__" -replaceSymbolsWith : Char -> String -> String -replaceSymbolsWith replacement input = - input - |> String.map - (\c -> - if Char.toCode c /= {- '_' -} 95 && not (Char.isAlphaNum c) then - replacement + (h :: _) as nonEmpty -> + if Char.isDigit h then + "N" ++ String.fromList nonEmpty else - c - ) + String.fromList nonEmpty initialUppercaseWordToLowercase : String -> String From 22e245a99588232095188189355efbb15ce0786b Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Mon, 9 Feb 2026 14:04:08 +0100 Subject: [PATCH 2/2] Fix empty cases --- src/Common.elm | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Common.elm b/src/Common.elm index 23f4a96..9cd40ff 100644 --- a/src/Common.elm +++ b/src/Common.elm @@ -244,10 +244,6 @@ deSymbolify replacement str = |> String.replace "+" "Plus" ) - else if String.startsWith "$" str then - -- This was first identified in the BIMcloud OAS, the fields of `Resource` were prefixed with `$` - deSymbolify replacement (String.dropLeft 1 str) - else let replaced : List Char @@ -261,9 +257,8 @@ deSymbolify replacement str = Char.toCode c in if - (code == {- '_' -} 95) - || -- lowercase - (0x61 <= code && code <= 0x7A) + -- lowercase + (0x61 <= code && code <= 0x7A) || -- uppercase (0x41 <= code && code <= 0x5A) || -- digits @@ -274,6 +269,9 @@ deSymbolify replacement str = else if List.isEmpty acc then acc + else if code == {- '_' -} 95 then + c :: acc + else replacement :: acc )