diff --git a/source/net/sourceforge/filebot/format/ExpressionFormat.global.js b/source/net/sourceforge/filebot/format/ExpressionFormat.global.js index ff4f6a09..d7c4a9dc 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormat.global.js +++ b/source/net/sourceforge/filebot/format/ExpressionFormat.global.js @@ -4,9 +4,6 @@ importPackage(java.lang); // Collection, Scanner, Random, UUID, etc. importPackage(java.util); -// SeriesNameMatcher -importClass(net.sourceforge.filebot.similarity.SeriesNameMatcher); - /** * Convenience methods for String.toLowerCase() and String.toUpperCase(). @@ -44,6 +41,34 @@ String.prototype.space = function(replacement) { } +/** + * Upper-case all initials. + * + * e.g. "The Day a new Demon was born" -> "The Day A New Demon Was Born" + */ +String.prototype.upperInitial = function() { + return this.replace(/\b[a-z]/g, function(letter) { return letter.toUpperCase() }); +} + + +/** + * Lower-case all letters that are not initials. + * + * e.g. "Gundam SEED" -> "Gundam Seed" + */ +String.prototype.lowerTrail = function() { + return this.replace(/\b([a-z])([a-z]+)\b/gi, function(match, initial, trail) { return initial + trail.toLowerCase() }); +} + + +/** + * Remove leading and trailing whitespace. + */ +String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ""); +} + + /** * Return substring before the given delimiter. */ @@ -76,14 +101,6 @@ String.prototype.after = function(delimiter) { } -/** - * Remove leading and trailing whitespace. - */ -String.prototype.trim = function() { - return this.replace(/^\s+|\s+$/g, ""); -} - - /** * Replace trailing parenthesis including any leading whitespace. * @@ -109,6 +126,7 @@ String.prototype.replacePart = function (replacement) { // handle '(n)', '(Part n)' and ': Part n' like syntax var pattern = [/\s*[(](\w+)[)]$/i, /\W*Part (\w+)\W*$/i]; + for (var i = 0; i < pattern.length; i++) { if (pattern[i].test(this)) { return this.replace(pattern[i], r); @@ -118,39 +136,3 @@ String.prototype.replacePart = function (replacement) { // no pattern matches, nothing to replace return this; } - - -/** - * Upper-case all initials. - * - * e.g. "The Day a new Demon was born" -> "The Day A New Demon Was Born" - */ -String.prototype.upperInitial = function() { - return this.replace(/\b[a-z]/g, function(letter) { return letter.toUpperCase() }); -} - - -/** - * Lower-case all letters that are not initials. - * - * e.g. "Gundam SEED" -> "Gundam Seed" - */ -String.prototype.lowerTrail = function() { - return this.replace(/\b([a-z])([a-z]+)\b/gi, function(match, initial, trail) { return initial + trail.toLowerCase() }); -} - - -/** - * Return first common word sequence. - * - * e.g. "Kidou Senshi Gundam Seed" intersect "Mobile Suite Gundam Seed") -> "Gundam Seed" - */ -String.prototype.intersect = function (other) { - var matcher = new SeriesNameMatcher(); - - // find common word sequence - var common = matcher.matchByFirstCommonWordSequence(this, other); - - // return common word sequence, if there is one - return common != null ? common : this; -}