// parseStrings.js
(function() {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Parser.prototype;
/**
* Look for "strings", meaning arbitrary
* quote delimited substrings that aren't meant
* to be parsed, and replace with the GlobalString
* placeholder class.
* <br><br>
* Example:<br>
* type "foo" on keyboard<br>
* Becomes:<br>
* type global_string on keyboard<br>
* @memberOf adventurejs.Parser
* @method adventurejs.Parser#parseStrings
* @param {String} input Player input.
* @returns {String}
*/
p.parseStrings = function Parser_parseStrings( input )
{
//this.game.log( "log", "medium", "parseStrings receive: " + input , 'Parser' );
this.game.world.global_string.set({'values':[]});
// originally only searched for double quotes
//var re = /"(.*?)"/g;
// now search for both double and single quotes
var re1 = /"(.*?)"/g; // search for double quotes
var re2 = /'(.*?)'/g; // search for single quotes
var reS = [ re1, re2 ];
for( var i = 0; i < reS.length; i++ )
{
var current;
var counter = 0;
//while (current = re.exec(input))
while (current = reS[i].exec(input))
{
this.game.log( "log", "high", "parseStrings > found quoted substring " + counter + ": " + current[0], 'Parser' );
input = input.replace( current[0], "global_string" );
this.game.getInput().strings.push( current[0] );
this.game.world.global_string.values.push( current[0] );
counter++;
}
}
this.game.log( "log", "high", "parseInput.js > parseStrings return: " + input, 'Parser' );
return input;
}
}());