in name_utils.js [165:213]
_splitCJKName(nameTokens) {
// The convention for CJK languages is to put the surname (last name) first,
// and the given name (first name) second. In a continuous text, there is
// normally no space between the two parts of the name. When entering their
// name into a field, though, some people add a space to disambiguate. CJK
// names (almost) never have a middle name.
let reHangulName = new RegExp(
"^[" + this.HANGUL_RANGE.join("") + this.WHITESPACE.join("") + "]+$");
let nameParts = {
given: "",
middle: "",
family: "",
};
if (nameTokens.length == 1) {
// There is no space between the surname and given name. Try to infer
// where to separate between the two. Most Chinese and Korean surnames
// have only one character, but there are a few that have 2. If the name
// does not start with a surname from a known list, default to one
// character.
let name = nameTokens[0];
let isKorean = reHangulName.test(name);
let surnameLength = 0;
// 4-character Korean names are more likely to be 2/2 than 1/3, so use
// the full list of Korean 2-char surnames. (instead of only the common
// ones)
let multiCharSurnames = (isKorean && name.length > 3) ?
this.KOREAN_MULTI_CHAR_SURNAMES :
this.COMMON_CJK_MULTI_CHAR_SURNAMES;
// Default to 1 character if the surname is not in the list.
surnameLength =
multiCharSurnames.some(surname => name.startsWith(surname)) ? 2 : 1;
nameParts.family = name.substr(0, surnameLength);
nameParts.given = name.substr(surnameLength);
} else if (nameTokens.length == 2) {
// The user entered a space between the two name parts. This makes our job
// easier. Family name first, given name second.
nameParts.family = nameTokens[0];
nameParts.given = nameTokens[1];
} else {
return null;
}
return nameParts;
},