fgerlits commented on code in PR #1753:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1753#discussion_r1560966829


##########
libminifi/src/utils/StringUtils.cpp:
##########
@@ -538,6 +538,56 @@ nonstd::expected<std::optional<char>, ParseError> 
parseCharacter(std::string_vie
   return nonstd::make_unexpected(ParseError{});
 }
 
+std::string replaceEscapedCharacters(std::string_view input) {
+  std::stringstream result;
+  for (size_t i = 0; i < input.size(); ++i) {
+    char input_char = input[i];
+    if (input_char != '\\' || i == input.size() - 1) {
+      result << input_char;
+      continue;
+    }
+    char next_char = input[i+1];
+    switch (next_char) {
+      case '0':
+        result << '\0';  // Null
+        ++i;
+        break;
+      case 'a':
+        result << '\a';  // Bell
+        ++i;
+        break;
+      case 'b':
+        result << '\b';  // Backspace
+        ++i;
+        break;
+      case 't':
+        result << '\t';  // Horizontal Tab
+        ++i;
+        break;
+      case 'n':
+        result << '\n';  // Line Feed
+        ++i;
+        break;
+      case 'v':
+        result << '\v';  // Vertical Tab
+        ++i;
+        break;
+      case 'f':
+        result << '\f';  // Form Feed
+        ++i;
+        break;
+      case 'r':
+        result << '\r';  // Carriage Return
+        ++i;
+        break;
+      default:
+        result << '\\';

Review Comment:
   This is an interesting question: should `"\s"` expand to `"s"` or `"\s"`?  
The old `parseCharacter` function does the first, here you do the second. I 
think it's a bit confusing that they are different, but I can be persuaded 
either way.



##########
libminifi/test/unit/StringUtilsTests.cpp:
##########
@@ -615,6 +615,16 @@ TEST_CASE("string::parseCharacter tests") {
   CHECK(string::parseCharacter("") == std::nullopt);
 }
 
+TEST_CASE("string::replaceEscapedCharacters tests") {
+  CHECK(string::replaceEscapedCharacters("a") == "a");
+  CHECK(string::replaceEscapedCharacters(R"(\n)") == "\n");
+  CHECK(string::replaceEscapedCharacters(R"(\t)") == "\t");
+  CHECK(string::replaceEscapedCharacters(R"(\r)") == "\r");
+  CHECK(string::replaceEscapedCharacters(R"(\\s)") == "\\\\s");

Review Comment:
   I would add
   ```
   CHECK(string::replaceEscapedCharacters(R"(\s)") == "\\s");
   ```
   (or
   ```
   CHECK(string::replaceEscapedCharacters(R"(\s)") == "s");
   ```
   if we decide to change it)



-- 
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-unsubscr...@nifi.apache.org

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

Reply via email to