diff options
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript')
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp | 20 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp | 20 |
2 files changed, 38 insertions, 2 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 35d9c4b..05d37d4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -28,6 +28,8 @@ #include "uscxml/util/DOM.h" #include <easylogging++.h> +#include <boost/algorithm/string.hpp> + #define EVENT_STRING_OR_UNDEF(field, cond) \ JSStringRef field##Name = JSStringCreateWithUTF8CString( #field ); \ JSStringRef field##Val = JSStringCreateWithUTF8CString(event.field.c_str()); \ @@ -399,7 +401,23 @@ Data JSCDataModel::evalAsData(const std::string& content) { Data JSCDataModel::getAsData(const std::string& content) { // parse as JSON test 578 - return Data::fromJSON(content); + Data d = Data::fromJSON(content); + if (!d.empty()) + return d; + + std::string trimmed = boost::trim_copy(content); + if (trimmed.length() > 0) { + if (isNumeric(trimmed.c_str(), 10)) { + d = Data(trimmed, Data::INTERPRETED); + } else if (trimmed.length() >= 2 && + ((trimmed[0] == '"' && trimmed[trimmed.length() - 1] == '"') || + (trimmed[0] == '\'' && trimmed[trimmed.length() - 1] == '\''))) { + d = Data(trimmed.substr(1, trimmed.length() - 2), Data::VERBATIM); + } else { + d = Data(trimmed, Data::INTERPRETED); + } + } + return d; } JSValueRef JSCDataModel::getDataAsValue(const Data& data) { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 1db4f45..db65ebf 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -33,6 +33,8 @@ #include "uscxml/util/DOM.h" #include <easylogging++.h> +#include <boost/algorithm/string.hpp> + using namespace XERCESC_NS; static v8::Local<v8::Value> XMLString2JS(const XMLCh* input) { @@ -421,7 +423,23 @@ void V8DataModel::setEvent(const Event& event) { } Data V8DataModel::getAsData(const std::string& content) { - return Data::fromJSON(content); + Data d = Data::fromJSON(content); + if (!d.empty()) + return d; + + std::string trimmed = boost::trim_copy(content); + if (trimmed.length() > 0) { + if (isNumeric(trimmed.c_str(), 10)) { + d = Data(trimmed, Data::INTERPRETED); + } else if (trimmed.length() >= 2 && + ((trimmed[0] == '"' && trimmed[trimmed.length() - 1] == '"') || + (trimmed[0] == '\'' && trimmed[trimmed.length() - 1] == '\''))) { + d = Data(trimmed.substr(1, trimmed.length() - 2), Data::VERBATIM); + } else { + d = Data(trimmed, Data::INTERPRETED); + } + } + return d; } Data V8DataModel::evalAsData(const std::string& content) { |