MCPcopy Create free account
hub / github.com/microsoft/SandDance / slowToString

Function slowToString

docs/app/js/sanddance-app.js:113153–113195  ·  view source on GitHub ↗
(encoding, start, end)

Source from the content-addressed store, hash-verified

113151}
113152Buffer.byteLength = byteLength;
113153function slowToString(encoding, start, end) {
113154 var loweredCase = false;
113155 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
113156 // property of a typed array.
113157 // This behaves neither like String nor Uint8Array in that we set start/end
113158 // to their upper/lower bounds if the value passed is out of range.
113159 // undefined is handled specially as per ECMA-262 6th Edition,
113160 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
113161 if (start === undefined || start < 0) start = 0;
113162 // Return early if start > this.length. Done here to prevent potential uint32
113163 // coercion fail below.
113164 if (start > this.length) return "";
113165 if (end === undefined || end > this.length) end = this.length;
113166 if (end <= 0) return "";
113167 // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
113168 end >>>= 0;
113169 start >>>= 0;
113170 if (end <= start) return "";
113171 if (!encoding) encoding = "utf8";
113172 while(true)switch(encoding){
113173 case "hex":
113174 return hexSlice(this, start, end);
113175 case "utf8":
113176 case "utf-8":
113177 return utf8Slice(this, start, end);
113178 case "ascii":
113179 return asciiSlice(this, start, end);
113180 case "latin1":
113181 case "binary":
113182 return latin1Slice(this, start, end);
113183 case "base64":
113184 return base64Slice(this, start, end);
113185 case "ucs2":
113186 case "ucs-2":
113187 case "utf16le":
113188 case "utf-16le":
113189 return utf16leSlice(this, start, end);
113190 default:
113191 if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
113192 encoding = (encoding + "").toLowerCase();
113193 loweredCase = true;
113194 }
113195}
113196// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
113197// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
113198// reliably in a browserify context because there could be multiple different

Callers

nothing calls this directly

Calls 6

hexSliceFunction · 0.70
utf8SliceFunction · 0.70
asciiSliceFunction · 0.70
latin1SliceFunction · 0.70
base64SliceFunction · 0.70
utf16leSliceFunction · 0.70

Tested by

no test coverage detected