Skip to content

Commit

Permalink
Fixup, implementation did not consider nested quotes
Browse files Browse the repository at this point in the history
Would have broken if it encounterd an odd number of nested quotes within a string.
  • Loading branch information
Robadob committed Sep 22, 2024
1 parent 289ff23 commit 236e312
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/flamegpu/io/JSONStateWriter.cu
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ void JSONStateWriter::endWrite() {
std::string t_buffer = buffer.GetString();
// Replace all spaces outside of quotes with \n
bool in_string = false;
for (auto it = t_buffer.begin(); it != t_buffer.end(); ++it) {
if (*it == '"') in_string = !in_string;
auto it = t_buffer.begin();
++it; // First char in generated JSON will never be a quote or space
for (; it != t_buffer.end(); ++it) {
if (*it == '"' && *(it-1) != '\\') in_string = !in_string; // Catch string begin/end, ignore nested quotes
if (*it == ' ' && !in_string) *it = '\n';
}
// Remove newlines
Expand Down

0 comments on commit 236e312

Please sign in to comment.