1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

* allow RegExp delimiter parameter in before() and after()

This commit is contained in:
Reinhard Pointner 2009-07-10 19:42:55 +00:00
parent b4578e9cdf
commit b8fceccb14

View File

@ -38,7 +38,7 @@ String.prototype.space = function(replacement) {
* Return substring before the given delimiter.
*/
String.prototype.before = function(delimiter) {
var endIndex = this.indexOf(delimiter);
var endIndex = delimiter instanceof RegExp ? this.search(delimiter) : this.indexOf(delimiter);
// delimiter was found, return leading substring, else return original value
return endIndex >= 0 ? this.substring(0, endIndex) : this;
@ -49,6 +49,16 @@ String.prototype.before = function(delimiter) {
* Return substring after the given delimiter.
*/
String.prototype.after = function(delimiter) {
if (delimiter instanceof RegExp) {
var match = this.match(delimiter);
if (match == null)
return this;
// use pattern match as delimiter
delimiter = match[0];
}
var startIndex = this.indexOf(delimiter);
// delimiter was found, return trailing substring, else return original value
@ -56,6 +66,14 @@ 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.
*