parseAttributes method

Map<String, String> parseAttributes()

Parse a series of Dingo-style attributes starting at position.

Implementation

Map<String, String> parseAttributes() {
	var result = <String, String>{}, tagFinished = false;

	while (inBounds) {
		// check for end-of-tag
		if (tagFinished = matches("/>")) {
			seek(2);
			break;
		} else if (tagFinished = matches(">")) {
			seek();
			break;
		}
		// read name
		var name = parseName(NameScannerMode.attribute);
		// get value
		var value = "";
		// explicit value
		if (matches("=")) {
			// skip past =
			seek();
			skipWhitespace();

			var ch = peek();
			// check if value is quoted
			if (quoteChars.contains(ch)) {
				// if it is, get content
				value = matchBrackets(ch, ch);
			} else {
				// otherwise, get unquoted content
				value = parseName(NameScannerMode.value);
			}
		}
		// implicit value
		else {
			value = name;
		}

		result[name] = value;
		skipWhitespace();
	}
	if (!tagFinished) {
		throw "unclosed tag";
	}

	return result;
}