summaryrefslogtreecommitdiff
path: root/lib/Support/YAMLTraits.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-09-11 00:45:48 +0000
committerRui Ueyama <ruiu@google.com>2013-09-11 00:45:48 +0000
commit7eb8b0fd84474f6a77ffa6211c0c753ed3142277 (patch)
treea2a49ebbcc7613248cef49b5d978dae7bf59cd8a /lib/Support/YAMLTraits.cpp
parentf532d448307215c9ddc1dbdea42afa74757c5e00 (diff)
downloadllvm-7eb8b0fd84474f6a77ffa6211c0c753ed3142277.tar.gz
llvm-7eb8b0fd84474f6a77ffa6211c0c753ed3142277.tar.bz2
llvm-7eb8b0fd84474f6a77ffa6211c0c753ed3142277.tar.xz
YAMLIO: Fix string quoting logic.
YAMLIO printed a string as is without quotes unless it contains a newline character. That did not suffice. We also need to quote a string if it starts with a backquote, quote, double quote or atsign, or it's the empty string. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190469 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/YAMLTraits.cpp')
-rw-r--r--lib/Support/YAMLTraits.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Support/YAMLTraits.cpp b/lib/Support/YAMLTraits.cpp
index ae7f7dcb0d..1a6adbf559 100644
--- a/lib/Support/YAMLTraits.cpp
+++ b/lib/Support/YAMLTraits.cpp
@@ -510,8 +510,16 @@ void Output::endBitSetScalar() {
void Output::scalarString(StringRef &S) {
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 (!strchr("'`@\"", S.front()) && S.find('\n') == StringRef::npos) {
+ // Plain string cannot start with double quote or single quote. Backquote
+ // and atsign are reserved characters. Newline is not allowed.
this->outputUpToEndOfLine(S);
return;
}