improve parsing if only a fullName is given to support the following:

- Becker, Ralf --> surname: Becker, personal: Ralf
- Ralf Becker  --> surname: Becker, personal: Ralf
- Becker --> surname: Becker
This commit is contained in:
Ralf Becker 2021-10-04 10:41:22 +02:00
parent c647ddab60
commit 782c284d37

View File

@ -124,9 +124,23 @@ class JsContact
case 'fullName':
$contact['n_fn'] = self::parseString($value);
// if no separate name-components given, simply split first word off as n_given and rest as n_family
if (!isset($data['name']))
if (!isset($data['name']) && !empty($contact['n_fn']))
{
list($contact['n_given'], $contact['n_family']) = explode(' ', $contact['n_fn'], 2);
if (preg_match('/^([^ ,]+)(,?) (.*)$/', $contact['n_fn'], $matches))
{
if (!empty($matches[2]))
{
list(, $contact['n_family'], , $contact['n_given']) = $matches;
}
else
{
list(, $contact['n_given'], , $contact['n_family']) = $matches;
}
}
else
{
$contact['n_family'] = $contact['n_fn'];
}
}
break;