PragmaTwice commented on code in PR #1841:
URL: https://github.com/apache/kvrocks/pull/1841#discussion_r1370218797
##########
src/types/json.h:
##########
@@ -106,6 +108,44 @@ struct JsonValue {
return Status::OK();
}
+ Status StrAppend(std::string_view path, const std::string &append_value,
std::vector<int64_t> &append_cnt) {
+ try {
+ auto append_trimmed = util::Trim(append_value, "\"");
+ jsoncons::jsonpath::json_replace(
+ value, path, [&append_trimmed, &append_cnt](const std::string &
/*path*/, jsoncons::json &origin) {
+ if (origin.is_string()) {
+ auto origin_trimmed = origin.as<std::string>();
+ append_cnt.push_back((int64_t)(origin_trimmed.length() +
append_trimmed.length()));
+ std::string new_value;
+
new_value.append("\"").append(origin_trimmed).append(append_trimmed).append("\"");
+ origin = jsoncons::json::parse(new_value);
+ } else {
+ append_cnt.push_back(-1);
+ }
+ });
Review Comment:
You do not need a `parse()`. You can check the document of jsoncons for more
details.
##########
src/types/json.h:
##########
@@ -106,6 +108,44 @@ struct JsonValue {
return Status::OK();
}
+ Status StrAppend(std::string_view path, const std::string &append_value,
std::vector<int64_t> &append_cnt) {
+ try {
+ auto append_trimmed = util::Trim(append_value, "\"");
+ jsoncons::jsonpath::json_replace(
+ value, path, [&append_trimmed, &append_cnt](const std::string &
/*path*/, jsoncons::json &origin) {
+ if (origin.is_string()) {
+ auto origin_trimmed = origin.as<std::string>();
+ append_cnt.push_back((int64_t)(origin_trimmed.length() +
append_trimmed.length()));
+ std::string new_value;
+
new_value.append("\"").append(origin_trimmed).append(append_trimmed).append("\"");
+ origin = jsoncons::json::parse(new_value);
+ } else {
+ append_cnt.push_back(-1);
+ }
+ });
Review Comment:
Here it do not need a `parse()`. You can check the document of jsoncons for
more details.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]