Skip to content

Commit

Permalink
Improve parsing of names like Amir Al Sadi
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jul 25, 2023
1 parent 857957c commit f94b23c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static function name($firstName, $lastName, $email, $flags) {
if ($firstName !== "" && $lastName !== "") {
if (($flags & (NAME_L | NAME_PARSABLE)) === NAME_PARSABLE
&& substr_count($lastName, " ") !== 0
&& !preg_match('/\A(?:v[oa]n |d[eu] )?\S+(?: jr\.?| sr\.?| i+v?i*)?\z/i', $lastName)) {
&& !preg_match('/\A(?:v[oa]n |d[eu] |al )?\S+(?: jr\.?| sr\.?| i+v?i*)?\z/i', $lastName)) {
$flags |= NAME_L;
}
if (($flags & NAME_I) !== 0
Expand Down Expand Up @@ -226,7 +226,7 @@ static function split_name($name, $with_email = false) {
$ret[1] = substr($m[1], $space + 1) . $m[2] . $paren;
// see also split_von
if (strpos($ret[0], " ") !== false
&& preg_match('/\A(\S.*?)((?: (?:v[ao]n|d[aeiu]|de[nr]|l[ae]))+)\z/i', $ret[0], $m)) {
&& preg_match('/\A(\S.*?)((?: (?:v[ao]n|d[aeiu]|de[nr]|l[ae]|al))+)\z/i', $ret[0], $m)) {
list($ret[0], $ret[1]) = [$m[1], ltrim($m[2]) . " " . $ret[1]];
}
} else if ($m[1] !== ""
Expand Down
1 change: 1 addition & 0 deletions test/t_unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ function test_le_von() {
xassert_eqq((Text::split_name("C. Von La Le Goues"))[1], "Von La Le Goues");
xassert_eqq(Text::analyze_von("Von Le Goues"), null);
xassert_eqq(Text::analyze_von("von le Goues"), ["von le", "Goues"]);
xassert_eqq((Text::split_name("Amir Al Sadi"))[1], "Al Sadi");
}

function test_prefix_suffix() {
Expand Down

0 comments on commit f94b23c

Please sign in to comment.