public class

NameSplitter

extends Object
java.lang.Object
   ↳ com.android.providers.contacts.NameSplitter

Class Overview

The purpose of this class is to split a full name into given names and last name. The logic only supports having a single last name. If the full name has multiple last names the output will be incorrect.

Core algorithm:

  1. Remove the suffixes (III, Ph.D., M.D.).
  2. Remove the prefixes (Mr., Pastor, Reverend, Sir).
  3. Assign the last remaining token as the last name.
  4. If the previous word to the last name is one from LASTNAME_PREFIXES, use this word also as the last name.
  5. Assign the rest of the words as the "given names".

Summary

Nested Classes
class NameSplitter.Name  
Constants
int MAX_TOKENS
Public Constructors
NameSplitter(String commonPrefixes, String commonLastNamePrefixes, String commonSuffixes, String commonConjunctions, Locale locale)
Constructor.
Public Methods
int getAdjustedFullNameStyle(int nameStyle)
If the supplied name style is undefined, returns a default based on the language, otherwise returns the supplied name style itself.
int getAdjustedNameStyleBasedOnPhoneticNameStyle(int nameStyle, int phoneticNameStyle)
Updates the display name style according to the phonetic name style if we were unsure about display name style based on the name components, but phonetic name makes it more definitive.
int guessFullNameStyle(String name)
void guessNameStyle(NameSplitter.Name name)
Makes the best guess at the expected full name style based on the character set used in the supplied name.
int guessPhoneticNameStyle(String name)
String join(NameSplitter.Name name, boolean givenNameFirst)
Concatenates components of a name according to the rules dictated by the name style.
String joinPhoneticName(NameSplitter.Name name)
Concatenates components of the phonetic name following the CJK tradition: family name + middle name + given name(s).
void split(NameSplitter.Name name, String fullName)
Parses a full name and returns parsed components in the Name object.
int tokenize(String[] tokens, String fullName)
Parses a full name and returns components as a list of tokens.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int MAX_TOKENS

Constant Value: 10 (0x0000000a)

Public Constructors

public NameSplitter (String commonPrefixes, String commonLastNamePrefixes, String commonSuffixes, String commonConjunctions, Locale locale)

Constructor.

Parameters
commonPrefixes comma-separated list of common prefixes, e.g. "Mr, Ms, Mrs"
commonLastNamePrefixes comma-separated list of common last name prefixes, e.g. "d', st, st., von"
commonSuffixes comma-separated list of common suffixes, e.g. "Jr, M.D., MD, D.D.S."
commonConjunctions comma-separated list of common conjuctions, e.g. "AND, Or"

Public Methods

public int getAdjustedFullNameStyle (int nameStyle)

If the supplied name style is undefined, returns a default based on the language, otherwise returns the supplied name style itself.

Parameters
nameStyle See FullNameStyle.

public int getAdjustedNameStyleBasedOnPhoneticNameStyle (int nameStyle, int phoneticNameStyle)

Updates the display name style according to the phonetic name style if we were unsure about display name style based on the name components, but phonetic name makes it more definitive.

public int guessFullNameStyle (String name)

public void guessNameStyle (NameSplitter.Name name)

Makes the best guess at the expected full name style based on the character set used in the supplied name. If the phonetic name is also supplied, tries to differentiate between Chinese, Japanese and Korean based on the alphabet used for the phonetic name.

public int guessPhoneticNameStyle (String name)

public String join (NameSplitter.Name name, boolean givenNameFirst)

Concatenates components of a name according to the rules dictated by the name style.

Parameters
givenNameFirst is ignored for CJK display name styles

public String joinPhoneticName (NameSplitter.Name name)

Concatenates components of the phonetic name following the CJK tradition: family name + middle name + given name(s).

public void split (NameSplitter.Name name, String fullName)

Parses a full name and returns parsed components in the Name object.

public int tokenize (String[] tokens, String fullName)

Parses a full name and returns components as a list of tokens.