Add StringRef::front (with some small tweaks while I was in the area).
authorDaniel Dunbar <daniel@zuster.org>
Thu, 13 Aug 2009 02:03:30 +0000 (02:03 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 13 Aug 2009 02:03:30 +0000 (02:03 +0000)
 - Patch by Erick Tryzelaar

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78883 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringRef.h

index b239e3b886bf7126bfa128ca91bc966e0fca53d9..40689a98870a186b742516a1b9ee167928ef3caf 100644 (file)
@@ -76,14 +76,21 @@ namespace llvm {
 
     /// size - Get the string size.
     size_t size() const { return Length; }
+
+    /// front - Get the first character in the string.
+    char front() const {
+      assert(!empty());
+      return Data[0];
+    }
     
+    /// back - Get the last character in the string.
     char back() const {
       assert(!empty());
       return Data[Length-1];
     }
 
     /// equals - Check for string equality, this is more efficient than
-    /// compare() in when the relative ordering of inequal strings isn't needed.
+    /// compare() when the relative ordering of inequal strings isn't needed.
     bool equals(const StringRef &RHS) const {
       return (Length == RHS.Length && 
               memcmp(Data, RHS.Data, RHS.Length) == 0);