mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-17 23:05:03 -05:00
* allow RegExp delimiter parameter in before() and after()
This commit is contained in:
parent
b4578e9cdf
commit
b8fceccb14
@ -38,7 +38,7 @@ String.prototype.space = function(replacement) {
|
|||||||
* Return substring before the given delimiter.
|
* Return substring before the given delimiter.
|
||||||
*/
|
*/
|
||||||
String.prototype.before = function(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
|
// delimiter was found, return leading substring, else return original value
|
||||||
return endIndex >= 0 ? this.substring(0, endIndex) : this;
|
return endIndex >= 0 ? this.substring(0, endIndex) : this;
|
||||||
@ -49,6 +49,16 @@ String.prototype.before = function(delimiter) {
|
|||||||
* Return substring after the given delimiter.
|
* Return substring after the given delimiter.
|
||||||
*/
|
*/
|
||||||
String.prototype.after = function(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);
|
var startIndex = this.indexOf(delimiter);
|
||||||
|
|
||||||
// delimiter was found, return trailing substring, else return original value
|
// 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.
|
* Replace trailing parenthesis including any leading whitespace.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user