Add StringLiteral::getString -> StringRef.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82514 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 7b60c00..39a23a1 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -20,6 +20,7 @@
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 #include <vector>
 
 namespace clang {
@@ -583,18 +584,23 @@
   /// \brief Construct an empty string literal.
   static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
 
+  llvm::StringRef getString() const {
+    return llvm::StringRef(StrData, ByteLength);
+  }
+  // FIXME: These are deprecated, replace with StringRef.
   const char *getStrData() const { return StrData; }
   unsigned getByteLength() const { return ByteLength; }
 
   /// \brief Sets the string data to the given string data.
-  void setStrData(ASTContext &C, const char *Str, unsigned Len);
+  void setString(ASTContext &C, llvm::StringRef Str);
 
   bool isWide() const { return IsWide; }
   void setWide(bool W) { IsWide = W; }
 
   bool containsNonAsciiOrNull() const {
-    for (unsigned i = 0; i < getByteLength(); ++i)
-      if (!isascii(getStrData()[i]) || !getStrData()[i])
+    llvm::StringRef Str = getString();
+    for (unsigned i = 0, e = Str.size(); i != e; ++i)
+      if (!isascii(Str[i]) || !Str[i])
         return true;
     return false;
   }
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 6e46c4f..9d2d46f 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -159,14 +159,14 @@
   Expr::DoDestroy(C);
 }
 
-void StringLiteral::setStrData(ASTContext &C, const char *Str, unsigned Len) {
+void StringLiteral::setString(ASTContext &C, llvm::StringRef Str) {
   if (StrData)
     C.Deallocate(const_cast<char*>(StrData));
 
-  char *AStrData = new (C, 1) char[Len];
-  memcpy(AStrData, Str, Len);
+  char *AStrData = new (C, 1) char[Str.size()];
+  memcpy(AStrData, Str.data(), Str.size());
   StrData = AStrData;
-  ByteLength = Len;
+  ByteLength = Str.size();
 }
 
 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp
index 67b7c1f..4b9496e 100644
--- a/lib/Frontend/PCHReaderStmt.cpp
+++ b/lib/Frontend/PCHReaderStmt.cpp
@@ -380,8 +380,8 @@
   E->setWide(Record[Idx++]);
 
   // Read string data
-  llvm::SmallVector<char, 16> Str(&Record[Idx], &Record[Idx] + Len);
-  E->setStrData(*Reader.getContext(), Str.data(), Len);
+  llvm::SmallString<16> Str(&Record[Idx], &Record[Idx] + Len);
+  E->setString(*Reader.getContext(), Str.str());
   Idx += Len;
 
   // Read source locations