std::string filterStr;
if (filter) {
- Json::FastWriter fw;
- fw.omitEndingLineFeed();
- filterStr = fw.write(filter->jfilter);
+ Json::StreamWriterBuilder builder;
+ filterStr = Json::writeString(builder, filter->jfilter);
}
int err = _ctx_history_query(data_type_str.c_str(), filterStr.c_str(), &((*list)->cursor));
int64_t value;
IF_FAIL_RETURN_TAG(record->tuple->getAt(index, &value), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid data");
- *val = value;
+ (value < 0) ? (*val = 0) : (*val = value);
return CONTEXT_HISTORY_ERROR_NONE;
}
* limitations under the License.
*/
+#include <memory>
#include <map>
#include <vector>
#include <algorithm>
Json::Value jCtx;
try {
- Json::Reader reader;
- if (!reader.parse(serialized, jCtx)) {
- _E("Parsing failed");
+ std::string error;
+ Json::CharReaderBuilder builder;
+ std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+ if (!reader->parse(serialized, (serialized+strlen(serialized)), &jCtx, &error)) {
+ _E("Parsing failed - error[%s]", error.c_str());
return false;
}
} catch (const Json::Exception& e) {
* limitations under the License.
*/
+#include <memory>
#include <regex>
#include <context_trigger.h>
#include "CustomTemplate.h"
int CustomTemplate::match(const std::string& fact)
{
// true if the given fact is valid w.r.t. the template
- Json::Reader reader;
Json::Value factJson;
+ std::string error;
+ Json::CharReaderBuilder builder;
+ std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+
// Error: Invalid Json
- if (!reader.parse(fact, factJson)) {
- _E("Fact: invalid json");
+ if (!reader->parse(fact.c_str(), (fact.c_str()+fact.size()), &factJson, &error)) {
+ _E("Fact: invalid json, error [%s]", error.c_str());
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
}
static std::regex nameRegex(R"~(^[\w-\._\/]+$)~", std::regex::optimize);
IF_FAIL_RETURN_TAG(std::regex_match(name, nameRegex), CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER, _E, "Invalid name");
- Json::Reader reader;
Json::Value tmplJson;
+ std::string error;
+ Json::CharReaderBuilder builder;
+ std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+
// Error: Invalid Json
- if (!reader.parse(attrTmpl, tmplJson)) {
- _E("Template: invalid json");
+ if (!reader->parse(attrTmpl.c_str(), \
+ (attrTmpl.c_str()+attrTmpl.size()), &tmplJson, &error)) {
+ _E("Template: invalid json, error [%s]", error.c_str());
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
}