* removed intersect() from ExpressionFormat.global.js because it is not as nifty as i thought

This commit is contained in:
Reinhard Pointner 2009-07-25 10:02:14 +00:00
parent b109e54db4
commit 134eba228b
1 changed files with 29 additions and 47 deletions

View File

@ -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;
}