VCardName.fromPlainText constructor
VCardName.fromPlainText(
- String plainText
Constructor from the plain text.
Exmaple: N:Doe;John;;Dr;
Implementation
factory VCardName.fromPlainText(String plainText) {
if (!plainText.startsWith('N:')) {
throw VCardParsingError('Property "name" must starts with "N:"');
}
final n = plainText.substring(2).split(';');
if (n.length != 5) {
throw VCardParsingError('This text is not recognized as a correct structure');
}
return VCardName(
lastName: n[0].isNotEmpty ? n[0] : null,
name: n[1],
middleNames: n[2].isNotEmpty ? n[2] : null,
prefixes: n[3].isNotEmpty ? n[3] : null,
suffixes: n[4].isNotEmpty ? n[4] : null,
);
}