summaryrefslogtreecommitdiff
path: root/node_modules/locutus/php/strings/strspn.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/locutus/php/strings/strspn.js')
-rw-r--r--node_modules/locutus/php/strings/strspn.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/node_modules/locutus/php/strings/strspn.js b/node_modules/locutus/php/strings/strspn.js
new file mode 100644
index 0000000..59e52c7
--- /dev/null
+++ b/node_modules/locutus/php/strings/strspn.js
@@ -0,0 +1,39 @@
+"use strict";
+
+module.exports = function strspn(str1, str2, start, lgth) {
+ // discuss at: http://locutus.io/php/strspn/
+ // original by: Valentina De Rosa
+ // improved by: Brett Zamir (http://brett-zamir.me)
+ // example 1: strspn('42 is the answer, what is the question ...', '1234567890')
+ // returns 1: 2
+ // example 2: strspn('foo', 'o', 1, 2)
+ // returns 2: 2
+
+ var found;
+ var stri;
+ var strj;
+ var j = 0;
+ var i = 0;
+
+ start = start ? start < 0 ? str1.length + start : start : 0;
+ lgth = lgth ? lgth < 0 ? str1.length + lgth - start : lgth : str1.length - start;
+ str1 = str1.substr(start, lgth);
+
+ for (i = 0; i < str1.length; i++) {
+ found = 0;
+ stri = str1.substring(i, i + 1);
+ for (j = 0; j <= str2.length; j++) {
+ strj = str2.substring(j, j + 1);
+ if (stri === strj) {
+ found = 1;
+ break;
+ }
+ }
+ if (found !== 1) {
+ return i;
+ }
+ }
+
+ return i;
+};
+//# sourceMappingURL=strspn.js.map \ No newline at end of file