mirror of
https://github.com/mitb-archive/filebot
synced 2024-08-13 17:03:45 -04:00
Refactor
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:
parent
9f9ec0dc99
commit
242c342b7c
@ -183,7 +183,7 @@ public class ExpressionFormat extends Format {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String normalizeResult(CharSequence value) {
|
protected String normalizeResult(CharSequence value) {
|
||||||
return replaceSpace(NEWLINE.matcher(value).replaceAll(""), " ").trim();
|
return replaceSpace(value, " ").trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleException(ScriptException exception) {
|
protected void handleException(ScriptException exception) {
|
||||||
|
@ -30,7 +30,7 @@ public class Normalization {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String trimTrailingPunctuation(String name) {
|
public static String trimTrailingPunctuation(CharSequence name) {
|
||||||
return TRAILING_PUNCTUATION.matcher(name).replaceAll("").trim();
|
return TRAILING_PUNCTUATION.matcher(name).replaceAll("").trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,22 +46,22 @@ public class Normalization {
|
|||||||
for (Pattern it : brackets) {
|
for (Pattern it : brackets) {
|
||||||
name = it.matcher(name).replaceAll(" ");
|
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);
|
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);
|
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);
|
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);
|
Matcher m = EMBEDDED_CHECKSUM.matcher(name);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
return m.group(1);
|
return m.group(1);
|
||||||
@ -69,12 +69,12 @@ public class Normalization {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String removeEmbeddedChecksum(String name) {
|
public static String removeEmbeddedChecksum(CharSequence name) {
|
||||||
// match embedded checksum and surrounding brackets
|
// match embedded checksum and surrounding brackets
|
||||||
return EMBEDDED_CHECKSUM.matcher(name).replaceAll("");
|
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
|
// remove trailing braces, e.g. Doctor Who (2005) -> Doctor Who
|
||||||
return TRAILING_PARENTHESIS.matcher(name).replaceAll("").trim();
|
return TRAILING_PARENTHESIS.matcher(name).replaceAll("").trim();
|
||||||
}
|
}
|
||||||
|
@ -237,13 +237,8 @@ public class SeriesNameMatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String normalize(String name) {
|
protected String normalize(String name) {
|
||||||
// remove group names and checksums, any [...] or (...)
|
// remove group names and checksums, any [...] or (...) and remove/normalize special characters
|
||||||
name = normalizeBrackets(name);
|
return normalizePunctuation(normalizeBrackets(name));
|
||||||
|
|
||||||
// remove/normalize special characters
|
|
||||||
name = normalizePunctuation(name);
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> T[] firstCommonSequence(T[] seq1, T[] seq2, int maxStartIndex, Comparator<T> equalsComparator) {
|
protected <T> T[] firstCommonSequence(T[] seq1, T[] seq2, int maxStartIndex, Comparator<T> equalsComparator) {
|
||||||
|
Loading…
Reference in New Issue
Block a user