diff --git a/lib/recase/cases/name_case.ex b/lib/recase/cases/name_case.ex index a4202f0..ce17586 100644 --- a/lib/recase/cases/name_case.ex +++ b/lib/recase/cases/name_case.ex @@ -25,29 +25,31 @@ defmodule Recase.NameCase do String.downcase(apostophe_ess) end) |> replace_irish() - |> replace(~r|\bVon\b|u, "von") + |> replace(~r|\bVon(?=\s+\w)|u, "von") |> replace(~r|\bVan(?=\s+\w)|u, "van") - |> replace(~r|\bAp\b|u, "ap") + |> replace(~r|\bAp(?=\s+\w)|u, "ap") |> replace(~r|\bAl(?=\s+\w)|u, "al") - |> replace(~r|\bEl\b|u, "el") - |> replace(~r|\bLa\b|u, "la") + |> replace(~r|\bEl(?=\s+\w)|u, "el") + |> replace(~r|\bLa(?=\s+\w)|u, "la") |> replace(~r|\bBen(?=\s+\w)|u, "ben") - |> replace(~r/\b(Bin|Binti|Binte)\b/u, fn bin_prefix -> + |> replace(~r/\b(Bin|Binti|Binte)(?=\s+\w)/u, fn bin_prefix -> String.downcase(bin_prefix) end) - |> replace(~r|\bD([aeiou])\b|u, fn da_prefix -> + |> replace(~r|\bD([aeiou])(?=\s+\w)|u, fn da_prefix -> String.downcase(da_prefix) end) - |> replace(~r|\bD([ao]s)\b|u, fn das_prefix -> + |> replace(~r|\bD([ao]s)(?=\s+\w)|u, fn das_prefix -> String.downcase(das_prefix) end) - |> replace(~r|\bDell([ae])\b|u, fn dell_prefix -> + |> replace(~r|\bDell([ae])(?=\s+\w)|u, fn dell_prefix -> String.downcase(dell_prefix) end) - |> replace(~r|\bDe([lr])\b|u, fn del_prefix -> + |> replace(~r|\bDe([lr])(?=\s+\w)|u, fn del_prefix -> String.downcase(del_prefix) end) - |> replace(~r|\bL([eo])\b|u, fn le_prefix -> String.downcase(le_prefix) end) + |> replace(~r|\bL([eo])(?=\s+\w)|u, fn le_prefix -> + String.downcase(le_prefix) + end) |> replace_roman_numerals() |> replace(~r|\b([YEI])\b|u, fn conjunction -> String.downcase(conjunction) diff --git a/test/recase_test/name_case_test.exs b/test/recase_test/name_case_test.exs index 6a4f596..e1acdbb 100644 --- a/test/recase_test/name_case_test.exs +++ b/test/recase_test/name_case_test.exs @@ -18,21 +18,34 @@ defmodule Recase.NameCaseTest do assert convert("al fahd") == "al Fahd" assert convert("al") == "Al" assert convert("el grecco") == "el Grecco" + assert convert("el") == "El" assert convert("bin friendly") == "bin Friendly" + assert convert("bin") == "Bin" assert convert("ben gurion") == "ben Gurion" assert convert("ben") == "Ben" assert convert("dos brasileiros") == "dos Brasileiros" + assert convert("dos") == "Dos" assert convert("da vinci") == "da Vinci" + assert convert("da") == "Da" assert convert("di caprio") == "di Caprio" + assert convert("di") == "Di" assert convert("du pont") == "du Pont" + assert convert("du") == "Du" assert convert("de legate") == "de Legate" + assert convert("de") == "De" assert convert("del crond") == "del Crond" + assert convert("del") == "Del" assert convert("della crond") == "della Crond" + assert convert("della") == "Della" assert convert("der sind") == "der Sind" + assert convert("der") == "Der" assert convert("van der Post") == "van der Post" assert convert("von trapp") == "von Trapp" + assert convert("von") == "Von" assert convert("la poisson") == "la Poisson" + assert convert("la") == "La" assert convert("le figaro") == "le Figaro" + assert convert("le") == "Le" assert convert("mack knife") == "Mack Knife" assert convert("dougal macdonald") == "Dougal MacDonald" assert convert("ruiz y picasso") == "Ruiz y Picasso"