[libc-commits] [PATCH] D129618: Add support for two more string_view functions

Guillaume Chatelet via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jul 13 01:33:41 PDT 2022


gchatelet added inline comments.


================
Comment at: libc/src/__support/CPP/StringView.h:127-130
     while (!Copy.empty() && Copy.front() == C)
       Copy = Copy.drop_front();
     while (!Copy.empty() && Copy.back() == C)
       Copy = Copy.drop_back();
----------------
once we have `starts_with` and `ends_with` this can be rewritten as:
```
    while (Copy.starts_with(C))
      Copy = Copy.drop_front();
    while (Copy.ends_with(C))
      Copy = Copy.drop_back();
```


================
Comment at: libc/src/__support/CPP/StringView.h:140-143
+  // Check if this string starts with the given Prefix.
+  bool starts_with(const char Prefix) const {
+    return Len >= 1 && Data[0] == Prefix;
+  }
----------------
Let's express this as `!empty() && front() == Prefix`


================
Comment at: libc/src/__support/CPP/StringView.h:150
   }
 
   // Return a reference to the substring from [Start, Start + N).
----------------
Do you want to add the `ends_with` function for symmetry?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129618/new/

https://reviews.llvm.org/D129618



More information about the libc-commits mailing list