[flang-commits] [flang] [flang][Parser] Make CharBlock inherit from llvm::StringRef (PR #228482)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Fri Oct 2 10:02:41 PDT 2026


================
@@ -82,107 +70,26 @@ class CharBlock {
     return result;
   }
 
-  std::size_t CountLeadingBlanks() const {
-    std::size_t n{size()};
-    std::size_t j{0};
-    for (; j < n; ++j) {
-      char ch{(*this)[j]};
-      if (ch != ' ' && ch != '\t') {
-        break;
-      }
-    }
-    return j;
+  size_t CountLeadingBlanks() const {
+    size_t idx{LocateFirstNonBlank()};
+    return idx != npos ? idx : size();
   }
 
-  bool IsBlank() const { return FirstNonBlank() == ' '; }
+  bool IsBlank() const { return LocateFirstNonBlank() == npos; }
 
-  std::string ToString() const {
-    return std::string{interval_.start(), interval_.size()};
-  }
+  std::string ToString() const { return str(); }
 
   // Convert to string, stopping early at any embedded '\0'.
   std::string NULTerminatedToString() const {
-    return std::string{interval_.start(),
-        /*not in std::*/ strnlen(interval_.start(), interval_.size())};
+    return std::string{begin(), strnlen(begin(), size())};
   }
 
-  bool operator<(const CharBlock &that) const { return Compare(that) < 0; }
-  bool operator<=(const CharBlock &that) const { return Compare(that) <= 0; }
-  bool operator==(const CharBlock &that) const { return Compare(that) == 0; }
-  bool operator!=(const CharBlock &that) const { return Compare(that) != 0; }
-  bool operator>=(const CharBlock &that) const { return Compare(that) >= 0; }
-  bool operator>(const CharBlock &that) const { return Compare(that) > 0; }
-
-  bool operator<(const char *that) const { return Compare(that) < 0; }
-  bool operator<=(const char *that) const { return Compare(that) <= 0; }
-  bool operator==(const char *that) const { return Compare(that) == 0; }
-  bool operator!=(const char *that) const { return Compare(that) != 0; }
-  bool operator>=(const char *that) const { return Compare(that) >= 0; }
-  bool operator>(const char *that) const { return Compare(that) > 0; }
-
-  friend bool operator<(const char *, const CharBlock &);
-  friend bool operator<=(const char *, const CharBlock &);
-  friend bool operator==(const char *, const CharBlock &);
-  friend bool operator!=(const char *, const CharBlock &);
-  friend bool operator>=(const char *, const CharBlock &);
-  friend bool operator>(const char *, const CharBlock &);
----------------
eugeneepshteyn wrote:

Are we sure that CharBlock objects compared exactly the same way as StringRef does? For example, how do empty strings compare?

https://github.com/llvm/llvm-project/pull/228482


More information about the flang-commits mailing list