MCPcopy Create free account
hub / github.com/feiyu563/PrometheusAlert / arrayIndexOf

Function arrayIndexOf

static/plugins/pdfmake/pdfmake.js:4817–4877  ·  view source on GitHub ↗
(arr, val, byteOffset, encoding, dir)

Source from the content-addressed store, hash-verified

4815}
4816
4817function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
4818 var indexSize = 1;
4819 var arrLength = arr.length;
4820 var valLength = val.length;
4821
4822 if (encoding !== undefined) {
4823 encoding = String(encoding).toLowerCase();
4824
4825 if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') {
4826 if (arr.length < 2 || val.length < 2) {
4827 return -1;
4828 }
4829
4830 indexSize = 2;
4831 arrLength /= 2;
4832 valLength /= 2;
4833 byteOffset /= 2;
4834 }
4835 }
4836
4837 function read(buf, i) {
4838 if (indexSize === 1) {
4839 return buf[i];
4840 } else {
4841 return buf.readUInt16BE(i * indexSize);
4842 }
4843 }
4844
4845 var i;
4846
4847 if (dir) {
4848 var foundIndex = -1;
4849
4850 for (i = byteOffset; i < arrLength; i++) {
4851 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
4852 if (foundIndex === -1) foundIndex = i;
4853 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
4854 } else {
4855 if (foundIndex !== -1) i -= i - foundIndex;
4856 foundIndex = -1;
4857 }
4858 }
4859 } else {
4860 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
4861
4862 for (i = byteOffset; i >= 0; i--) {
4863 var found = true;
4864
4865 for (var j = 0; j < valLength; j++) {
4866 if (read(arr, i + j) !== read(val, j)) {
4867 found = false;
4868 break;
4869 }
4870 }
4871
4872 if (found) return i;
4873 }
4874 }

Callers 1

bidirectionalIndexOfFunction · 0.70

Calls 1

readFunction · 0.70

Tested by

no test coverage detected