mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-25 17:20:48 +00:00
YAMLIO: Allow scalars to dictate quotation rules
Introduce ScalarTraits::mustQuote which determines whether or not a StringRef needs quoting before it is acceptable to output. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205955 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -285,7 +285,7 @@ void Input::endBitSetScalar() {
|
||||
}
|
||||
}
|
||||
|
||||
void Input::scalarString(StringRef &S) {
|
||||
void Input::scalarString(StringRef &S, bool) {
|
||||
if (ScalarHNode *SN = dyn_cast<ScalarHNode>(CurrentNode)) {
|
||||
S = SN->value();
|
||||
} else {
|
||||
@@ -541,10 +541,7 @@ void Output::endBitSetScalar() {
|
||||
this->outputUpToEndOfLine(" ]");
|
||||
}
|
||||
|
||||
void Output::scalarString(StringRef &S) {
|
||||
const char ScalarSafeChars[] = "abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-/^., \t";
|
||||
|
||||
void Output::scalarString(StringRef &S, bool MustQuote) {
|
||||
this->newLineCheck();
|
||||
if (S.empty()) {
|
||||
// Print '' for the empty string because leaving the field empty is not
|
||||
@@ -552,11 +549,8 @@ void Output::scalarString(StringRef &S) {
|
||||
this->outputUpToEndOfLine("''");
|
||||
return;
|
||||
}
|
||||
bool isOctalString = S.front() == '0' && S.size() > 2 && !S.startswith("0x");
|
||||
if (S.find_first_not_of(ScalarSafeChars) == StringRef::npos &&
|
||||
!isspace(S.front()) && !isspace(S.back()) && !isOctalString) {
|
||||
// If the string consists only of safe characters, print it out without
|
||||
// quotes.
|
||||
if (!MustQuote) {
|
||||
// Only quote if we must.
|
||||
this->outputUpToEndOfLine(S);
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user