src/vs/base/common/strings.ts/decodeUTF8
export function decodeUTF8(buffer: Uint8Array): string {
	// https://en.wikipedia.org/wiki/UTF-8

	const len = buffer.byteLength;
	const result: string[] = [];
	let offset = 0;
	while (offset < len) {
		const v0 = buffer[offset];
		let codePoint: number;
		if (v0 >= 0b11110000 && offset + 3 < len) {
			// 4 bytes
			codePoint = (
				(((buffer[offset++] & 0b00000111) << 18) >>> 0)
				| (((buffer[offset++] & 0b00111111) << 12) >>> 0)
				| (((buffer[offset++] & 0b00111111) << 6) >>> 0)
				| (((buffer[offset++] & 0b00111111) << 0) >>> 0)
			);
		} else if (v0 >= 0b11100000 && offset + 2 < len) {
			// 3 bytes
			codePoint = (
				(((buffer[offset++] & 0b00001111) << 12) >>> 0)
				| (((buffer[offset++] & 0b00111111) << 6) >>> 0)
				| (((buffer[offset++] & 0b00111111) << 0) >>> 0)
			);
		} else if (v0 >= 0b11000000 && offset + 1 < len) {
			// 2 bytes
			codePoint = (
				(((buffer[offset++] & 0b00011111) << 6) >>> 0)
				| (((buffer[offset++] & 0b00111111) << 0) >>> 0)
			);
		} else {
			// 1 byte
			codePoint = buffer[offset++];
		}

		if ((codePoint >= 0 && codePoint <= 0xD7FF) || (codePoint >= 0xE000 && codePoint <= 0xFFFF)) {
			// Basic Multilingual Plane
			result.push(String.fromCharCode(codePoint));
		} else if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
			// Supplementary Planes
			const uPrime = codePoint - 0x10000;
			const w1 = 0xD800 + ((uPrime & 0b11111111110000000000) >>> 10);
			const w2 = 0xDC00 + ((uPrime & 0b00000000001111111111) >>> 0);
			result.push(String.fromCharCode(w1));
			result.push(String.fromCharCode(w2));
		} else {
			// illegal code point
			result.push(String.fromCharCode(0xFFFD));
		}
	}

	return result.join('');
}