You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "mapleFU (via GitHub)" <gi...@apache.org> on 2023/05/29 11:24:55 UTC

[GitHub] [incubator-kvrocks] mapleFU commented on a diff in pull request #1476: fix bad case in the format of monitor response and improve performance

mapleFU commented on code in PR #1476:
URL: https://github.com/apache/incubator-kvrocks/pull/1476#discussion_r1209216112


##########
src/common/string_util.cc:
##########
@@ -312,4 +314,47 @@ std::vector<std::string> TokenizeRedisProtocol(const std::string &value) {
   return tokens;
 }
 
+/* convert string to an escaped representation where
+ * all the non-printable characters (tested with isprint()) are turned into
+ * escapes in the form "\n\r\a...." or "\x<hex-number>". */
+std::string StringRepr(const std::string &s) {
+  std::string str;
+  str.reserve(s.size());
+
+  for (auto ch : s) {
+    switch (ch) {
+      case '\\':
+      case '"':
+        str += "\\";

Review Comment:
   Would '\' become "\\\"?



##########
src/common/string_util.cc:
##########
@@ -312,4 +314,47 @@ std::vector<std::string> TokenizeRedisProtocol(const std::string &value) {
   return tokens;
 }
 
+/* convert string to an escaped representation where
+ * all the non-printable characters (tested with isprint()) are turned into
+ * escapes in the form "\n\r\a...." or "\x<hex-number>". */
+std::string StringRepr(const std::string &s) {
+  std::string str;
+  str.reserve(s.size());
+
+  for (auto ch : s) {
+    switch (ch) {
+      case '\\':
+      case '"':
+        str += "\\";

Review Comment:
   Would `'\'` become `"\\\"`?



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org