Note: replaceSpace will get rid of NEWLINE as well and trim() will get rid of any leading/trailing spaces in the result
This commit is contained in:
Reinhard Pointner 2016-10-20 15:14:13 +08:00
parent 9f9ec0dc99
commit 242c342b7c
3 changed files with 11 additions and 16 deletions

View File

@ -183,7 +183,7 @@ public class ExpressionFormat extends Format {
}
protected String normalizeResult(CharSequence value) {
return replaceSpace(NEWLINE.matcher(value).replaceAll(""), " ").trim();
return replaceSpace(value, " ").trim();
}
protected void handleException(ScriptException exception) {

View File

@ -30,7 +30,7 @@ public class Normalization {
return name;
}
public static String trimTrailingPunctuation(String name) {
public static String trimTrailingPunctuation(CharSequence name) {
return TRAILING_PUNCTUATION.matcher(name).replaceAll("").trim();
}
@ -46,22 +46,22 @@ public class Normalization {
for (Pattern it : brackets) {
name = it.matcher(name).replaceAll(" ");
}
return name;
return name.trim();
}
public static String normalizeSpace(String name, String replacement) {
public static String normalizeSpace(CharSequence name, String replacement) {
return replaceSpace(WORD_SEPARATOR_PUNCTUATION.matcher(name).replaceAll(" ").trim(), replacement);
}
public static String replaceSpace(String name, String replacement) {
public static String replaceSpace(CharSequence name, String replacement) {
return SPACE.matcher(name).replaceAll(replacement);
}
public static String replaceColon(String name, String ratio, String colon) {
public static String replaceColon(CharSequence name, String ratio, String colon) {
return COLON.matcher(RATIO.matcher(name).replaceAll(ratio)).replaceAll(colon);
}
public static String getEmbeddedChecksum(String name) {
public static String getEmbeddedChecksum(CharSequence name) {
Matcher m = EMBEDDED_CHECKSUM.matcher(name);
if (m.find()) {
return m.group(1);
@ -69,12 +69,12 @@ public class Normalization {
return null;
}
public static String removeEmbeddedChecksum(String name) {
public static String removeEmbeddedChecksum(CharSequence name) {
// match embedded checksum and surrounding brackets
return EMBEDDED_CHECKSUM.matcher(name).replaceAll("");
}
public static String removeTrailingBrackets(String name) {
public static String removeTrailingBrackets(CharSequence name) {
// remove trailing braces, e.g. Doctor Who (2005) -> Doctor Who
return TRAILING_PARENTHESIS.matcher(name).replaceAll("").trim();
}

View File

@ -237,13 +237,8 @@ public class SeriesNameMatcher {
}
protected String normalize(String name) {
// remove group names and checksums, any [...] or (...)
name = normalizeBrackets(name);
// remove/normalize special characters
name = normalizePunctuation(name);
return name;
// remove group names and checksums, any [...] or (...) and remove/normalize special characters
return normalizePunctuation(normalizeBrackets(name));
}
protected <T> T[] firstCommonSequence(T[] seq1, T[] seq2, int maxStartIndex, Comparator<T> equalsComparator) {