summaryrefslogtreecommitdiff
path: root/src/mbgl/style/rapidjson_conversion.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/rapidjson_conversion.hpp')
-rw-r--r--src/mbgl/style/rapidjson_conversion.hpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/mbgl/style/rapidjson_conversion.hpp b/src/mbgl/style/rapidjson_conversion.hpp
index 93577ac8b2..1d9f88efa3 100644
--- a/src/mbgl/style/rapidjson_conversion.hpp
+++ b/src/mbgl/style/rapidjson_conversion.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/util/rapidjson.hpp>
+#include <mbgl/util/feature.hpp>
namespace mbgl {
namespace style {
@@ -50,6 +51,28 @@ inline optional<std::string> toString(const JSValue& value) {
return {{ value.GetString(), value.GetStringLength() }};
}
+inline optional<Value> toValue(const JSValue& value) {
+ switch (value.GetType()) {
+ case rapidjson::kNullType:
+ case rapidjson::kFalseType:
+ return { false };
+
+ case rapidjson::kTrueType:
+ return { true };
+
+ case rapidjson::kStringType:
+ return { std::string { value.GetString(), value.GetStringLength() } };
+
+ case rapidjson::kNumberType:
+ if (value.IsUint64()) return { value.GetUint64() };
+ if (value.IsInt64()) return { value.GetInt64() };
+ return { value.GetDouble() };
+
+ default:
+ return {};
+ }
+}
+
} // namespace conversion
} // namespace style
} // namespace mbgl