Example usage for org.apache.commons.lang3.text WordUtils initials

List of usage examples for org.apache.commons.lang3.text WordUtils initials

Introduction

In this page you can find the example usage for org.apache.commons.lang3.text WordUtils initials.

Prototype

public static String initials(final String str, final char... delimiters) 

Source Link

Document

Extracts the initial letters from each word in the String.

The first letter of the string and all first letters after the defined delimiters are returned as a new string.

Usage

From source file:org.dmu.expertiserecognition.doiResults.java

public static String standardizeAuthorName(String name) {
    String newName = name.trim();
    newName = deAccent(newName);//ww w . ja  va  2 s  .c o m
    newName = WordUtils.capitalizeFully(newName, new char[] { '.', ' ', '-', '\'' });
    newName = newName.replaceAll("([A-Za-z0-9-']+)\\.([A-Za-z0-9-']+)", "$1. $2");
    newName = newName.replaceAll("[ ]{2,}", " ");
    newName = newName.replaceAll("^(.*)([^\\.]) ([A-Z]\\.)$", "$3 $1$2");
    String surname;
    String authInitials;
    if (Pattern.matches("^.*\\.$", newName)) {
        surname = newName.replaceAll("^([^ ]+) (.*)$", "$1");
        authInitials = newName.replaceAll("^([^ ]+) (.*)$", "$2");
    } else {
        surname = newName.replaceAll("^(.*) ([^ ]+)$", "$2");
        authInitials = newName.replaceAll("^(.*) ([^ ]+)$", "$1");
    }
    authInitials = WordUtils.initials(authInitials, new char[] { '.', ' ' });
    byte[] authInitialsBytes = authInitials.getBytes();
    int i;
    StringBuilder sb = new StringBuilder();
    for (i = 0; i < authInitialsBytes.length; i++) {
        sb.append((char) authInitialsBytes[i]);
        sb.append(". ");
    }
    sb.append(surname);
    newName = sb.toString();
    return newName;
}