diff --git a/PerlRPG/Script.pm b/PerlRPG/Script.pm index b18b962..0f180b4 100644 --- a/PerlRPG/Script.pm +++ b/PerlRPG/Script.pm @@ -252,9 +252,26 @@ sub EvalString { #LogData(DEBUG, "Val is '$val'"); - # Tokenize - my @tokens = split(/\s+/,$val); + # Pretokenize quoted strings + my @pretokens; + $val=~s/\\"/\x01/g; + while(my($start,$quote,$left)=$val=~/^(.*?)(".*?")(.*)$/) { + push @pretokens, $start if($start); + push @pretokens, $quote; + $val = $left; + } + push @pretokens, $val if($val); + # Tokenize + my @tokens; + foreach my $token (@pretokens) { + $token=~s/\x01/\\"/g; + if(IsString($token)) { + push @tokens, $token; + } else { + push @tokens, split(/\s+/, $token); + } + } #for(my $i=0;$i<@tokens-0;$i++) { LogData(DEBUG, "Pass 1 Token [%i], '%s'", $i, $tokens[$i]); } diff --git a/Tests/Script.pl b/Tests/Script.pl index 1a46c33..c7640d3 100755 --- a/Tests/Script.pl +++ b/Tests/Script.pl @@ -26,5 +26,7 @@ ok( PerlRPG::Script::IsString(5)==0, "'5' is not a string"); ok( EvalString("\"[TestVar]\"") eq '3', "\"[TestVar]\" is 3"); ok( EvalString("3 + 3") == 6, "\"3 + 3\" == 6"); ok( EvalString("lc('FoO') . uc('FoO')") eq 'fooFOO', "String function test"); +SetGameVar("TestVar", "\"FoO\""); +ok( EvalString("uc(\" [TestVar] \")") eq ' FOO ', "Complex string function test"); done_testing();