SCC: Doxygen-ize comments, NFC
[oota-llvm.git] / include / llvm / ADT / StringRef.h
index fd5b28e8fc14fd8d3e202853f948f18f55d38205..1f413e80553f089158f18d73a4fdd4d55632b723 100644 (file)
@@ -10,7 +10,6 @@
 #ifndef LLVM_ADT_STRINGREF_H
 #define LLVM_ADT_STRINGREF_H
 
-#include "llvm/Support/type_traits.h"
 #include <algorithm>
 #include <cassert>
 #include <cstring>
@@ -70,7 +69,7 @@ namespace llvm {
     /// @{
 
     /// Construct an empty string ref.
-    /*implicit*/ StringRef() : Data(0), Length(0) {}
+    /*implicit*/ StringRef() : Data(nullptr), Length(0) {}
 
     /// Construct a string ref from a cstring.
     /*implicit*/ StringRef(const char *Str)
@@ -124,6 +123,13 @@ namespace llvm {
       return Data[Length-1];
     }
 
+    // copy - Allocate copy in Allocator and return StringRef to it.
+    template <typename Allocator> StringRef copy(Allocator &A) {
+      char *S = A.template Allocate<char>(Length);
+      std::copy(begin(), end(), S);
+      return StringRef(S, Length);
+    }
+
     /// equals - Check for string equality, this is more efficient than
     /// compare() when the relative ordering of inequal strings isn't needed.
     bool equals(StringRef RHS) const {
@@ -179,7 +185,7 @@ namespace llvm {
 
     /// str - Get the contents as an std::string.
     std::string str() const {
-      if (Data == 0) return std::string();
+      if (!Data) return std::string();
       return std::string(Data, Length);
     }
 
@@ -210,12 +216,18 @@ namespace llvm {
              compareMemory(Data, Prefix.Data, Prefix.Length) == 0;
     }
 
+    /// Check if this string starts with the given \p Prefix, ignoring case.
+    bool startswith_lower(StringRef Prefix) const;
+
     /// Check if this string ends with the given \p Suffix.
     bool endswith(StringRef Suffix) const {
       return Length >= Suffix.Length &&
         compareMemory(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
     }
 
+    /// Check if this string ends with the given \p Suffix, ignoring case.
+    bool endswith_lower(StringRef Suffix) const;
+
     /// @}
     /// @name String Searching
     /// @{
@@ -327,7 +339,7 @@ namespace llvm {
     /// this returns true to signify the error.  The string is considered
     /// erroneous if empty or if it overflows T.
     template <typename T>
-    typename enable_if_c<std::numeric_limits<T>::is_signed, bool>::type
+    typename std::enable_if<std::numeric_limits<T>::is_signed, bool>::type
     getAsInteger(unsigned Radix, T &Result) const {
       long long LLVal;
       if (getAsSignedInteger(*this, Radix, LLVal) ||
@@ -338,7 +350,7 @@ namespace llvm {
     }
 
     template <typename T>
-    typename enable_if_c<!std::numeric_limits<T>::is_signed, bool>::type
+    typename std::enable_if<!std::numeric_limits<T>::is_signed, bool>::type
     getAsInteger(unsigned Radix, T &Result) const {
       unsigned long long ULLVal;
       if (getAsUnsignedInteger(*this, Radix, ULLVal) ||
@@ -547,11 +559,6 @@ namespace llvm {
   // StringRefs can be treated like a POD type.
   template <typename T> struct isPodLike;
   template <> struct isPodLike<StringRef> { static const bool value = true; };
-
-  /// Construct a string ref from a boolean.
-  inline StringRef toStringRef(bool B) {
-    return StringRef(B ? "true" : "false");
-  }
 }
 
 #endif