public/rot.js/rot.js
function(str, maxWidth) {
		var result = [];

		/* first tokenization pass - split texts and color formatting commands */
		var offset = 0;
		str.replace(this.RE_COLORS, function(match, type, name, index) {
			/* string before */
			var part = str.substring(offset, index);
			if (part.length) {
				result.push({
					type: ROT.Text.TYPE_TEXT,
					value: part
				});
			}

			/* color command */
			result.push({
				type: (type == "c" ? ROT.Text.TYPE_FG : ROT.Text.TYPE_BG),
				value: name.trim()
			});

			offset = index + match.length;
			return "";
		});

		/* last remaining part */
		var part = str.substring(offset);
		if (part.length) {
			result.push({
				type: ROT.Text.TYPE_TEXT,
				value: part
			});
		}

		return this._breakLines(result, maxWidth);
	}
function(str, maxWidth) {
		var result = [];

		/* first tokenization pass - split texts and color formatting commands */
		var offset = 0;
		str.replace(this.RE_COLORS, function(match, type, name, index) {
			/* string before */
			var part = str.substring(offset, index);
			if (part.length) {
				result.push({
					type: ROT.Text.TYPE_TEXT,
					value: part
				});
			}

			/* color command */
			result.push({
				type: (type == "c" ? ROT.Text.TYPE_FG : ROT.Text.TYPE_BG),
				value: name.trim()
			});

			offset = index + match.length;
			return "";
		});

		/* last remaining part */
		var part = str.substring(offset);
		if (part.length) {
			result.push({
				type: ROT.Text.TYPE_TEXT,
				value: part
			});
		}

		return this._breakLines(result, maxWidth);
	}
function ( str , maxWidth ) { var result = [ ] ; /* first tokenization pass - split texts and color formatting commands */ var offset = 0 ; str . replace ( this . RE_COLORS , function ( match , type , name , index ) { /* string before */ var part = str . substring ( offset , index ) ; if ( part . length ) { result . push ( { type : ROT . Text . TYPE_TEXT , value : part } ) ; } /* color command */ result . push ( { type : ( type == "c" ? ROT . Text . TYPE_FG : ROT . Text . TYPE_BG ) , value : name . trim ( ) } ) ; offset = index + match . length ; return "" ; } ) ; /* last remaining part */ var part = str . substring ( offset ) ; if ( part . length ) { result . push ( { type : ROT . Text . TYPE_TEXT , value : part } ) ; } return this . _breakLines ( result , maxWidth ) ; }
Convert string to a series of a formatting commands
Convert string to a series of a formatting commands