Skip to content

Commit

Permalink
Handle some corner cases (empty \N, incorrect \\ escape handling) cor…
Browse files Browse the repository at this point in the history
…rectly. Parse backwards to implement the EasyRPG extensions \v[\v[N]] and \n[\v[N]]] again.

Fix EasyRPG#460
  • Loading branch information
Ghabry committed Sep 9, 2016
1 parent 2e441ad commit 80851cd
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/window_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,35 @@ void Window_Message::StartMessageProcessing() {
Game_Message::texts.clear();
item_max = min(4, Game_Message::choice_max);

text_index = text.begin();
text_index = text.end();
end = text.end();

// Apply commands that insert text
while (std::distance(text_index, end) > 1) {
if (*text_index++ == escape_char) {
switch (tolower(*text_index)) {
while (std::distance(text_index, text.begin()) <= -1) {
switch (tolower(*text_index--)) {
case 'n':
case 'v':
{
if (*text_index != escape_char) {
continue;
}
++text_index;

auto start_code = text_index - 1;
std::u32string command_result = Utils::DecodeUTF32(ParseCommandCode());
if (command_result.empty()) {
text_index = start_code + 2;
bool success;
std::u32string command_result = Utils::DecodeUTF32(ParseCommandCode(success));
if (!success) {
text_index = start_code - 2;
continue;
}
text.replace(start_code, text_index + 1, command_result);
// Start from the beginning, the inserted text might add new commands
text_index = text.begin();
text_index = text.end();
end = text.end();
break;
}
default:
if (*text_index == escape_char) {
// Do not replace this to avoid parsing \\v[1] as \v[1]
++text_index;
}
break;
}
}
}

Expand Down Expand Up @@ -529,10 +529,11 @@ int Window_Message::ParseParameter(bool& is_valid) {
return num;
}

std::string Window_Message::ParseCommandCode() {
std::string Window_Message::ParseCommandCode(bool& success) {
int parameter;
bool is_valid;
uint32_t cmd_char = *text_index;
success = true;

switch (tolower(cmd_char)) {
case 'n':
Expand Down Expand Up @@ -565,6 +566,7 @@ std::string Window_Message::ParseCommandCode() {
default:;
// When this happens text_index was not on a \ during calling
}
success = false;
return "";
}

Expand Down

0 comments on commit 80851cd

Please sign in to comment.