PragmaTwice commented on code in PR #1841:
URL: https://github.com/apache/kvrocks/pull/1841#discussion_r1367651675
##########
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);
+ }
+ });
+ } catch (const jsoncons::jsonpath::jsonpath_error &e) {
+ return {Status::NotOK, e.what()};
+ }
+
+ return Status::OK();
+ }
+
+ Status StrLen(std::string_view path, std::vector<uint64_t> &str_lens) const {
+ try {
+ jsoncons::jsonpath::json_query(value, path,
+ [&str_lens](const std::string & /*path*/,
const jsoncons::json &origin) {
+ if (origin.is_string()) {
+ // need subtraction "
+
str_lens.push_back(origin.to_string().length() - 2);
+ } else {
+ str_lens.push_back(0);
Review Comment:
How can you distinguish between zero-sized array and non-array here?
--
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]