JakeChampion commented on code in PR #12544:
URL: https://github.com/apache/trafficserver/pull/12544#discussion_r2425907435


##########
plugins/compress/configuration.cc:
##########
@@ -23,87 +23,44 @@
 
 #include "tscore/ink_config.h"
 #include "configuration.h"
-#include <fstream>
 #include <algorithm>
+#include <unordered_map>
 #include <vector>
 #include <fnmatch.h>
+#include <system_error>
+#include <stdexcept>
 
+#include "swoc/swoc_file.h"
 #include "swoc/TextView.h"
+#include "swoc/Lexicon.h"
 
 #include "debug_macros.h"
 
 #include <cctype>
 
 namespace Gzip
 {
-using namespace std;
-
-void
-ltrim_if(string &s, int (*fp)(int))
+inline auto
+make_char_predicate(int (*fp)(int))
 {
-  for (size_t i = 0; i < s.size();) {
-    if (fp(s[i])) {
-      s.erase(i, 1);
-    } else {
-      break;
-    }
-  }
+  return [fp](char c) -> bool { return fp(static_cast<unsigned char>(c)) != 0; 
};
 }
 
-void
-rtrim_if(string &s, int (*fp)(int))
+swoc::TextView
+extractFirstToken(swoc::TextView &view, int (*fp)(int))
 {
-  for (ssize_t i = static_cast<ssize_t>(s.size()) - 1; i >= 0; i--) {
-    if (fp(s[i])) {
-      s.erase(i, 1);
-    } else {
-      break;
-    }
-  }
-}
-
-void
-trim_if(string &s, int (*fp)(int))
-{
-  ltrim_if(s, fp);
-  rtrim_if(s, fp);
-}
-
-string
-extractFirstToken(string &s, int (*fp)(int))
-{
-  int startTok{-1}, endTok{-1}, idx{0};
-
-  for (;; ++idx) {
-    if (idx == int(s.length())) {
-      if (endTok < 0) {
-        endTok = idx;
-      }
-      break;
-    } else if (fp(s[idx])) {
-      if ((startTok >= 0) and (endTok < 0)) {
-        endTok = idx;
-      }
-    } else if (endTok > 0) {
-      break;
-    } else if (startTok < 0) {
-      startTok = idx;
-    }
-  }
+  auto predicate = make_char_predicate(fp);

Review Comment:
   good point, i've done that in [`e158212` 
(#12544)](https://github.com/apache/trafficserver/pull/12544/commits/e1582123b7958ca2e2abad782d08a7c86b337704)



-- 
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]

Reply via email to