]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Replace skip_last_empty with IncludeDelimiter (#1046)
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>
Tue, 12 Apr 2022 19:09:57 +0000 (22:09 +0300)
committerGitHub <noreply@github.com>
Tue, 12 Apr 2022 19:09:57 +0000 (21:09 +0200)
src/Depfile.cpp
src/Util.cpp
src/util/Tokenizer.cpp
src/util/Tokenizer.hpp
unittest/test_util_Tokenizer.cpp

index 5a13cc220b4ec50e0fa1725891697682e55455d5..3fcc0bcd73df7c1050eaaef8578fa9f4672c4458 100644 (file)
@@ -72,8 +72,11 @@ rewrite_paths(const Context& ctx, const std::string& file_content)
   adjusted_file_content.reserve(file_content.size());
 
   bool content_rewritten = false;
-  for (const auto line : util::Tokenizer(
-         file_content, "\n", util::Tokenizer::Mode::skip_last_empty)) {
+  using util::Tokenizer;
+  for (const auto line : Tokenizer(file_content,
+                                   "\n",
+                                   Tokenizer::Mode::include_empty,
+                                   Tokenizer::IncludeDelimiter::yes)) {
     const auto tokens = Util::split_into_views(line, " \t");
     for (size_t i = 0; i < tokens.size(); ++i) {
       DEBUG_ASSERT(!line.empty()); // line.empty() -> no tokens
@@ -96,7 +99,6 @@ rewrite_paths(const Context& ctx, const std::string& file_content)
         adjusted_file_content.append(token.begin(), token.end());
       }
     }
-    adjusted_file_content.push_back('\n');
   }
 
   if (content_rewritten) {
index e68ef79f3e63079199d2ee2d45cc0038664d409e..870a2ae183413e7e5f9c55c8fa1e56bfe2dcb920 100644 (file)
@@ -178,8 +178,11 @@ rewrite_stderr_to_absolute_paths(string_view text)
   static const std::string in_file_included_from = "In file included from ";
 
   std::string result;
-  for (auto line :
-       util::Tokenizer(text, "\n", util::Tokenizer::Mode::skip_last_empty)) {
+  using util::Tokenizer;
+  for (auto line : Tokenizer(text,
+                             "\n",
+                             Tokenizer::Mode::include_empty,
+                             Tokenizer::IncludeDelimiter::yes)) {
     // Rewrite <path> to <absolute path> in the following two cases, where X may
     // be optional ANSI CSI sequences:
     //
@@ -208,7 +211,6 @@ rewrite_stderr_to_absolute_paths(string_view text)
         result.append(line.data(), line.length());
       }
     }
-    result += '\n';
   }
   return result;
 }
index b1d3e7e8eed88154e78531761bc10881fcc0c78e..6300cd5ce750874d39065457e3eeaad272971985 100644 (file)
@@ -44,10 +44,6 @@ Tokenizer::Iterator::advance(bool initial)
       m_right = delim_pos == npos ? string.length() : delim_pos;
     }
   } while (mode == Mode::skip_empty && m_left == m_right);
-
-  if (mode == Mode::skip_last_empty && m_left == string.length()) {
-    m_left = npos;
-  }
 }
 
 nonstd::sv_lite::string_view
index e57d4c2c7c29cecadf8cea8978dc5a32493b9760..d139832e68b4553a3a38382319d06451224bfe15 100644 (file)
@@ -32,9 +32,8 @@ class Tokenizer
 {
 public:
   enum class Mode {
-    include_empty,   // Include empty tokens.
-    skip_empty,      // Skip empty tokens.
-    skip_last_empty, // Include empty tokens except the last one.
+    include_empty, // Include empty tokens.
+    skip_empty,    // Skip empty tokens.
   };
 
   enum class IncludeDelimiter { no, yes };
index 2fa516f65afe70e0d14950186412022cfad7585b..c2fa94e2a1bf4c6906a6bf5424af0e8c1060a826 100644 (file)
@@ -76,17 +76,6 @@ TEST_CASE("util::Tokenizer")
           {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"});
   }
 
-  SUBCASE("skip last empty token")
-  {
-    SplitTest split(Mode::skip_last_empty);
-    split("", "/", {});
-    split("/", "/", {""});
-    split("a/", "/", {"a"});
-    split("/b", "/", {"", "b"});
-    split("a/b", "/", {"a", "b"});
-    split("/a:", "/:", {"", "a"});
-  }
-
   SUBCASE("include empty and delimiter")
   {
     SplitTest split(Mode::include_empty, IncludeDelimiter::yes);
@@ -113,15 +102,4 @@ TEST_CASE("util::Tokenizer")
           "/:.+_abcdef",
           {"0.", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9."});
   }
-
-  SUBCASE("skip last empty and include delimiter")
-  {
-    SplitTest split(Mode::skip_last_empty, IncludeDelimiter::yes);
-    split("", "/", {});
-    split("/", "/", {"/"});
-    split("a/", "/", {"a/"});
-    split("/b", "/", {"/", "b"});
-    split("a/b", "/", {"a/", "b"});
-    split("/a:", "/:", {"/", "a:"});
-  }
 }