Skip to content

Instantly share code, notes, and snippets.

@TwistingTwists
Created January 11, 2023 11:21
Show Gist options
  • Save TwistingTwists/50c55c0de147e82511350acb8fad1b4b to your computer and use it in GitHub Desktop.
Save TwistingTwists/50c55c0de147e82511350acb8fad1b4b to your computer and use it in GitHub Desktop.
defmodule Username do
def sanitize(username) do
# ä becomes ae
# ö becomes oe
# ü becomes ue
# ß becomes ss
for u <- username do
case u do
# _
?_ -> '_'
# \s
# ?\s -> nil
# ü
?ü -> 'ue'
# ö
?ö -> 'oe'
# ä
?ä -> 'ae'
# ß
?ß -> 'ss'
a when a <= ?z and a >= ?a -> [a]
# a when (a >= ?0 and a <= ?9) -> nil
_ -> ''
end
end
# |> Enum.filter(
# fn entry -> entry != nil end
# )
|> List.flatten()
# Please implement the sanitize/1 function
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment