From 2ae7f64aa1c47bc12d816e0a2304d12f63f6f8e1 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Wed, 16 Jul 2014 11:53:18 +0100 Subject: [PATCH] Fixed YAML -> JSON for non-string basic types. --- src/backend/json.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/backend/json.h b/src/backend/json.h index b7252d02..1d3bd107 100644 --- a/src/backend/json.h +++ b/src/backend/json.h @@ -28,6 +28,8 @@ along with LOOT. If not, see #include +#include + namespace loot { // Handy class for turning YAML objects into JSON and vice-versa. @@ -55,6 +57,15 @@ namespace loot { // There's also a bit of weirdness where there are some \x escapes and some \u escapes. // They should all be \u, so transform them. boost::replace_all(json, "\\x", "\\u00"); + // yaml-cpp also emits booleans as "true" and "false" strings, whereas JSON expects the same unquoted basic values. The same happens for null and numbers. + boost::replace_all(json, ": \"true\"", ": true"); + boost::replace_all(json, ": \"false\"", ": false"); + boost::replace_all(json, ": \"null\"", ": null"); + + // Using the definition at . + std::regex numbers(": \"(-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)\"", std::regex::ECMAScript); + + json = std::regex_replace(json, numbers, ": $1"); return json; }