// Current version: 2005-09-07

function DOMTokenString() {
	var SEPARATOR = " ";

	this.has = function(token) {
		token = token || "";
		if (!token.match(/^(\S+)$/)) throw {code:12}; // DOMException.SYNTAX_ERR = 12
		var re = new RegExp("(^|\\s+)" + token + "(\\s+|$)", "g");
		return re.test(this);
	}
	this.add = function(token) {
		if (!this.has(token)) {
			return this + SEPARATOR + token;
		} else {
			return this;
		}
	}

	this.remove = function(token) {
		var s = this;
		var re = new RegExp("(^|\\s+)" + token + "(\\s+|$)", "g");
		if (this.has(token)) {
			 s = this.replace(re, "$1$2");
		}
		return s;
	}
}
DOMTokenString.apply(String.prototype);

/*
Old version: 2005-09-06

function DOMTokenString(string) {
	const separator = " ";
	var tokens = string.split(/\s/);
	var self = new String(tokens.join(separator));

	self.has = function(token) {
		return (tokens.indexOf(token) >= 0);
	}

	self.add = function(token) {
		return new DOMTokenString(self + separator + token);
	}

	self.remove = function(token) {
		var t = tokens.filter(
			function(element, index, array) {
				return !(element == token);
			}
		);
		return new DOMTokenString(t.join(separator));
	}
	return self;
}
*/
