From 152b7cbb19cb239ac1bf06f66ee51f3dfc8e88f6 Mon Sep 17 00:00:00 2001 From: Simon Herteby Date: Tue, 15 Jan 2019 10:53:30 +0100 Subject: [PATCH] Make String.toTitleCase work with non-english alphabets The behavior might slightly differ from the original in cases where there's a special character in front of a word. It's a lot simpler though! --- src/String/Extra.elm | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/String/Extra.elm b/src/String/Extra.elm index 5fd06b8..8472cdc 100644 --- a/src/String/Extra.elm +++ b/src/String/Extra.elm @@ -147,15 +147,8 @@ decapitalize word = -} toTitleCase : String -> String -toTitleCase ws = - let - uppercaseMatch = - Regex.replace (regexFromString "\\w+") (.match >> toSentenceCase) - in - ws - |> Regex.replace - (regexFromString "^([a-z])|\\s+([a-z])") - (.match >> uppercaseMatch) +toTitleCase phrase = + phrase |> String.split " " |> List.map String.toSentenceCase |> String.join " " {-| Replace text within a portion of a string given a substitution