diff options
author | Rui Ueyama <ruiu@google.com> | 2013-09-11 00:45:48 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2013-09-11 00:45:48 +0000 |
commit | 9a40ae8935a163c632d2669093e554465927cb8a (patch) | |
tree | c70247359456c42e7ce6f95f276844daf45854c5 /llvm/lib/Support/YAMLTraits.cpp | |
parent | d99f387f5e8a219f215e5e7a49b6030b5a307e5b (diff) | |
download | bcm5719-llvm-9a40ae8935a163c632d2669093e554465927cb8a.tar.gz bcm5719-llvm-9a40ae8935a163c632d2669093e554465927cb8a.zip |
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.
llvm-svn: 190469
Diffstat (limited to 'llvm/lib/Support/YAMLTraits.cpp')
-rw-r--r-- | llvm/lib/Support/YAMLTraits.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp index ae7f7dcb0d0..1a6adbf559b 100644 --- a/llvm/lib/Support/YAMLTraits.cpp +++ b/llvm/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; } |