mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add String.startsWith and String.endsWith
This commit is contained in:
parent
22987bea12
commit
c73d53f50a
@ -111,7 +111,7 @@ class Context(object):
|
||||
return this.replace(rtrim, '');
|
||||
};
|
||||
})();
|
||||
}
|
||||
};
|
||||
if (!String.prototype.trimLeft) {
|
||||
(function() {
|
||||
// Make sure we trim BOM and NBSP
|
||||
@ -120,7 +120,7 @@ class Context(object):
|
||||
return this.replace(rtrim, '');
|
||||
};
|
||||
})();
|
||||
}
|
||||
};
|
||||
if (!String.prototype.trimRight) {
|
||||
(function() {
|
||||
// Make sure we trim BOM and NBSP
|
||||
@ -129,6 +129,23 @@ class Context(object):
|
||||
return this.replace(rtrim, '');
|
||||
};
|
||||
})();
|
||||
};
|
||||
if (!String.prototype.startsWith) {
|
||||
String.prototype.startsWith = function(searchString, position) {
|
||||
position = position || 0;
|
||||
return this.indexOf(searchString, position) === position;
|
||||
};
|
||||
}
|
||||
if (!String.prototype.endsWith) {
|
||||
String.prototype.endsWith = function(searchString, position) {
|
||||
var subjectString = this.toString();
|
||||
if (position === undefined || position > subjectString.length) {
|
||||
position = subjectString.length;
|
||||
}
|
||||
position -= searchString.length;
|
||||
var lastIndex = subjectString.indexOf(searchString, position);
|
||||
return lastIndex !== -1 && lastIndex === position;
|
||||
};
|
||||
}
|
||||
Duktape.readfile = function(path, encoding) {
|
||||
var x = Duktape.pyreadfile(path, encoding);
|
||||
|
Loading…
x
Reference in New Issue
Block a user