xref: /webtrees/app/SurnameTradition/IcelandicSurnameTradition.php (revision 0a016d046f63b3b1ece7ec913216782c17f0cbad)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2017 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16namespace Fisharebest\Webtrees\SurnameTradition;
17
18/**
19 * Children take a patronym instead of a surname.
20 *
21 * Sons get their father’s given name plus “sson”
22 * Daughters get their father’s given name plus “sdottir”
23 */
24class IcelandicSurnameTradition extends DefaultSurnameTradition implements SurnameTraditionInterface {
25	/**
26	 * Does this surname tradition use surnames?
27	 *
28	 * @return bool
29	 */
30	public function hasSurnames() {
31		return false;
32	}
33
34	/**
35	 * What names are given to a new child
36	 *
37	 * @param string $father_name A GEDCOM NAME
38	 * @param string $mother_name A GEDCOM NAME
39	 * @param string $child_sex   M, F or U
40	 *
41	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
42	 */
43	public function newChildNames($father_name, $mother_name, $child_sex) {
44		if (preg_match(self::REGEX_GIVN, $father_name, $father_match)) {
45			switch ($child_sex) {
46			case 'M':
47				return [
48					'NAME' => $father_match['GIVN'] . 'sson',
49				];
50			case 'F':
51				return [
52					'NAME' => $father_match['GIVN'] . 'sdottir',
53				];
54			}
55		}
56
57		return [];
58	}
59
60	/**
61	 * What names are given to a new parent
62	 *
63	 * @param string $child_name A GEDCOM NAME
64	 * @param string $parent_sex M, F or U
65	 *
66	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
67	 */
68	public function newParentNames($child_name, $parent_sex) {
69		if ($parent_sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson|sdottir)$~', $child_name, $child_match)) {
70			return [
71				'NAME' => $child_match['GIVN'],
72				'GIVN' => $child_match['GIVN'],
73			];
74		} else {
75			return [];
76		}
77	}
78
79	/**
80	 * What names are given to a new spouse
81	 *
82	 * @param string $spouse_name A GEDCOM NAME
83	 * @param string $spouse_sex  M, F or U
84	 *
85	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
86	 */
87	public function newSpouseNames($spouse_name, $spouse_sex) {
88		return [];
89	}
90}
91