1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-22 15:58:52 -05:00

Add String.initialName() for "James Cameron" ➔ "J. Cameron"

This commit is contained in:
Reinhard Pointner 2019-02-22 18:57:52 +07:00
parent f8e3c3460d
commit 8c8e1045fb

View File

@ -8,6 +8,7 @@ import static net.filebot.WebServices.*;
import static net.filebot.format.ExpressionFormatFunctions.*;
import static net.filebot.media.MediaDetection.*;
import static net.filebot.util.RegularExpressions.*;
import static net.filebot.util.StringUtilities.*;
import java.io.File;
import java.io.IOException;
@ -227,6 +228,14 @@ public class ExpressionFormatMethods {
return compile("^(The|A|An)\\s(.+)", CASE_INSENSITIVE | UNICODE_CHARACTER_CLASS).matcher(self).replaceFirst(replacement).trim();
}
public static String initialName(String self) {
String[] words = SPACE.split(self);
for (int i = 0; i < words.length - 1; i++) {
words[i] = words[i].charAt(0) + ".";
}
return join(words, " ");
}
public static String sortInitial(String self) {
// use primary initial, ignore The XY, A XY, etc
char c = ascii(sortName(self)).charAt(0);