summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/YAMLTraits.cpp
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
commit106ededc4ed5a3f1cd899f13f3b7e7f1b200dd30 (patch)
tree6a2b1082a35e9469848713fc1bfa6e9f53b6d14b /llvm/lib/Support/YAMLTraits.cpp
parentaa76981400a6b0dee6e42b4d456f2b605140f090 (diff)
downloadbcm5719-llvm-106ededc4ed5a3f1cd899f13f3b7e7f1b200dd30.tar.gz
bcm5719-llvm-106ededc4ed5a3f1cd899f13f3b7e7f1b200dd30.zip
Re-submit r190469: YAMLIO: Fix string quoting logic.
llvm-svn: 190485
Diffstat (limited to 'llvm/lib/Support/YAMLTraits.cpp')
-rw-r--r--llvm/lib/Support/YAMLTraits.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index cf19509ee88..19eaed1ac7a 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/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;
}
OpenPOWER on IntegriCloud