Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ public HumanNameParserBuilder(Name name) {
*/
public HumanNameParserParser build() {
if (this.salutations == null) {
this.salutations = DEFAULT_SALUTATIONS;
this.salutations = formatToRegex(DEFAULT_SALUTATIONS);
}
if (this.postnominals == null) {
this.postnominals = DEFAULT_POSTNOMINALS;
this.postnominals = formatToRegex(DEFAULT_POSTNOMINALS);
}
if (this.prefixes == null) {
this.prefixes = DEFAULT_PREFIXES;
this.prefixes = formatToRegex(DEFAULT_PREFIXES);
}
if (this.suffixes == null) {
this.suffixes = DEFAULT_SUFFIXES;
this.suffixes = formatToRegex(DEFAULT_SUFFIXES);
}
final HumanNameParserParser parser = new HumanNameParserParser(
name,
Expand All @@ -159,6 +159,14 @@ public HumanNameParserParser build() {
return parser;
}

private List<String> formatToRegex(List<String> list) {
List<String> regexList = new ArrayList<>();
for (String s : list) {
regexList.add(s.replace(".", "\\."));
}
return regexList;
}

// salutations

public HumanNameParserBuilder withSalutations(List<String> salutations) {
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/tupilabs/human_name_parser/BuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ public void testExtraSalutations() {
assertTrue(parser.salutations.contains("sinho"));
}

@Test
public void testLastNameNotMistakenForPostnominal() {
HumanNameParserBuilder builder = new HumanNameParserBuilder("ruvin phidd");
HumanNameParserParser parser = builder.build();
assertTrue(parser.getFirst().contains("ruvin"));
assertTrue(parser.getLast().contains("phidd"));
}

// validations

@Test
Expand Down