Skip to content

Commit

Permalink
Add positive lookahead for names that are also connectors (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
neel-tanda authored Jun 25, 2024
1 parent 76f24f0 commit 7da7309
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/recase/cases/name_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions test/recase_test/name_case_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7da7309

Please sign in to comment.