summaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-09-11 04:00:08 +0000
committerRui Ueyama <ruiu@google.com>2013-09-11 04:00:08 +0000
commit2e942d5402ddfadb04853a6f9dab2128af7a1d5e (patch)
tree09d6c36c75afd8a4405c3c64720c74c405058678 /lib/Support
parent90c782a9ca9bc9325e9a1f075890311c15dfeb0e (diff)
downloadllvm-2e942d5402ddfadb04853a6f9dab2128af7a1d5e.tar.gz
llvm-2e942d5402ddfadb04853a6f9dab2128af7a1d5e.tar.bz2
llvm-2e942d5402ddfadb04853a6f9dab2128af7a1d5e.tar.xz
Re-submit r190469: YAMLIO: Fix string quoting logic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190485 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/YAMLTraits.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/Support/YAMLTraits.cpp b/lib/Support/YAMLTraits.cpp
index cf19509ee8..19eaed1ac7 100644
--- a/lib/Support/YAMLTraits.cpp
+++ b/lib/Support/YAMLTraits.cpp
@@ -15,6 +15,7 @@
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/raw_ostream.h"
#include <cstring>
+#include <cctype>
using namespace llvm;
using namespace yaml;
@@ -508,9 +509,20 @@ void Output::endBitSetScalar() {
}
void Output::scalarString(StringRef &S) {
+ const char ScalarSafeChars[] = "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-/^., \t";
+
this->newLineCheck();
- if (S.find('\n') == StringRef::npos) {
- // No embedded new-line chars, just print string.
+ if (S.empty()) {
+ // Print '' for the empty string because leaving the field empty is not
+ // allowed.
+ this->outputUpToEndOfLine("''");
+ return;
+ }
+ if (S.find_first_not_of(ScalarSafeChars) == StringRef::npos &&
+ !isspace(S.front()) && !isspace(S.back())) {
+ // If the string consists only of safe characters, print it out without
+ // quotes.
this->outputUpToEndOfLine(S);
return;
}