src/vs/base/common/iconLabels.ts/doParseLabelWithIcons
function doParseLabelWithIcons(text: string, firstIconIndex: number): IParsedLabelWithIcons {
	const iconOffsets: number[] = [];
	let textWithoutIcons: string = '';

	function appendChars(chars: string) {
		if (chars) {
			textWithoutIcons += chars;

			for (const _ of chars) {
				iconOffsets.push(iconsOffset); // make sure to fill in icon offsets
			}
		}
	}

	let currentIconStart = -1;
	let currentIconValue: string = '';
	let iconsOffset = 0;

	let char: string;
	let nextChar: string;

	let offset = firstIconIndex;
	const length = text.length;

	// Append all characters until the first icon
	appendChars(text.substr(0, firstIconIndex));

	// example: $(file-symlink-file) my cool $(other-icon) entry
	while (offset < length) {
		char = text[offset];
		nextChar = text[offset + 1];

		// beginning of icon: some value $( <--
		if (char === iconStartMarker[0] && nextChar === iconStartMarker[1]) {
			currentIconStart = offset;

			// if we had a previous potential icon value without
			// the closing ')', it was actually not an icon and
			// so we have to add it to the actual value
			appendChars(currentIconValue);

			currentIconValue = iconStartMarker;

			offset++; // jump over '('
		}

		// end of icon: some value $(some-icon) <--
		else if (char === ')' && currentIconStart !== -1) {
			const currentIconLength = offset - currentIconStart + 1; // +1 to include the closing ')'
			iconsOffset += currentIconLength;
			currentIconStart = -1;
			currentIconValue = '';
		}

		// within icon
		else if (currentIconStart !== -1) {
			// Make sure this is a real icon name
			if (/^[a-z0-9\-]$/i.test(char)) {
				currentIconValue += char;
			} else {
				// This is not a real icon, treat it as text
				appendChars(currentIconValue);

				currentIconStart = -1;
				currentIconValue = '';
			}
		}

		// any value outside of icon
		else {
			appendChars(char);
		}

		offset++;
	}

	// if we had a previous potential icon value without
	// the closing ')', it was actually not an icon and
	// so we have to add it to the actual value
	appendChars(currentIconValue);

	return { text: textWithoutIcons, iconOffsets };
}