PragmaTwice commented on code in PR #1841:
URL: https://github.com/apache/kvrocks/pull/1841#discussion_r1367656620
##########
src/types/json.h:
##########
@@ -65,6 +66,47 @@ struct JsonValue {
return Status::OK();
}
+ Status StrAppend(std::string_view path, const std::string &append_value,
std::vector<uint64_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_str = origin.to_string();
+ // need trim "
+ auto origin_trimmed = util::Trim(origin_str, "\"");
+ append_cnt.push_back(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(0);
+ }
Review Comment:
IMHO it is not the correct way to process the string object in the JSON
document.
You are expected to use `as<string>`, rather than `to_string`.
`to_string` is to re-serialize the object, not to retrieve the value.
--
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]