From 712786c92788b2b840dd9992c11083de73448761 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 4 Oct 2021 10:41:22 +0200 Subject: [PATCH] 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 --- api/src/Contacts/JsContact.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/api/src/Contacts/JsContact.php b/api/src/Contacts/JsContact.php index 9c8c9b932f..e6493dc5a7 100644 --- a/api/src/Contacts/JsContact.php +++ b/api/src/Contacts/JsContact.php @@ -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;