Use the testcase from PR2791.
[oota-llvm.git] / lib / Support / StringExtras.cpp
index 8a276b56c21f1dd3fe5e671f00130d3ec77dcdd8..1618086e602ea0b424488f5b2f89f98ff2d3bd73 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ADT/StringExtras.h"
+#include <cstring>
 using namespace llvm;
 
 /// getToken - This function extracts one token from source, ignoring any
@@ -21,7 +22,7 @@ using namespace llvm;
 /// The Source source string is updated in place to remove the returned string
 /// and any delimiter prefix from it.
 std::string llvm::getToken(std::string &Source, const char *Delimiters) {
-  unsigned NumDelimiters = std::strlen(Delimiters);
+  size_t NumDelimiters = std::strlen(Delimiters);
 
   // Figure out where the token starts.
   std::string::size_type Start =
@@ -76,6 +77,7 @@ void llvm::UnescapeString(std::string &Str) {
       case 'r': Str[i] = '\r'; break;
       case 't': Str[i] = '\t'; break;
       case 'v': Str[i] = '\v'; break;
+      case '"': Str[i] = '\"'; break;
       case '\'': Str[i] = '\''; break;
       case '\\': Str[i] = '\\'; break;
       }
@@ -95,6 +97,8 @@ void llvm::EscapeString(std::string &Str) {
     } else if (Str[i] == '\t') {
       Str[i++] = '\\';
       Str.insert(Str.begin()+i, 't');
+    } else if (Str[i] == '"') {
+      Str.insert(Str.begin()+i++, '\\');
     } else if (Str[i] == '\n') {
       Str[i++] = '\\';
       Str.insert(Str.begin()+i, 'n');