mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Switched the stream << for c-strings to take a templated array param (since we never stream user-built c-strings, only string literals). For this, refactored the escape character display
This commit is contained in:
@@ -25,9 +25,9 @@ namespace YAML
|
|||||||
|
|
||||||
const char *str() const {
|
const char *str() const {
|
||||||
if(m_pStream) {
|
if(m_pStream) {
|
||||||
return NULL;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
m_buffer[m_pos] = NULL;
|
m_buffer[m_pos] = '\0';
|
||||||
return &m_buffer[0];
|
return &m_buffer[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,8 +49,9 @@ namespace YAML
|
|||||||
bool m_comment;
|
bool m_comment;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline ostream_wrapper& operator << (ostream_wrapper& stream, const char *str) {
|
template<std::size_t N>
|
||||||
stream.write(str, std::strlen(str));
|
inline ostream_wrapper& operator << (ostream_wrapper& stream, const char (&str)[N]) {
|
||||||
|
stream.write(str, N-1);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -188,24 +188,22 @@ namespace YAML
|
|||||||
void WriteDoubleQuoteEscapeSequence(ostream_wrapper& out, int codePoint) {
|
void WriteDoubleQuoteEscapeSequence(ostream_wrapper& out, int codePoint) {
|
||||||
static const char hexDigits[] = "0123456789abcdef";
|
static const char hexDigits[] = "0123456789abcdef";
|
||||||
|
|
||||||
char escSeq[] = "\\U00000000";
|
out << "\\";
|
||||||
int digits = 8;
|
int digits = 8;
|
||||||
if (codePoint < 0xFF) {
|
if(codePoint < 0xFF) {
|
||||||
escSeq[1] = 'x';
|
out << "x";
|
||||||
digits = 2;
|
digits = 2;
|
||||||
} else if (codePoint < 0xFFFF) {
|
} else if(codePoint < 0xFFFF) {
|
||||||
escSeq[1] = 'u';
|
out << "u";
|
||||||
digits = 4;
|
digits = 4;
|
||||||
}
|
} else {
|
||||||
|
out << "U";
|
||||||
|
digits = 8;
|
||||||
|
}
|
||||||
|
|
||||||
// Write digits into the escape sequence
|
// Write digits into the escape sequence
|
||||||
int i = 2;
|
for (; digits > 0; --digits)
|
||||||
for (; digits > 0; --digits, ++i) {
|
out << hexDigits[(codePoint >> (4 * (digits - 1))) & 0xF];
|
||||||
escSeq[i] = hexDigits[(codePoint >> (4 * (digits - 1))) & 0xF];
|
|
||||||
}
|
|
||||||
|
|
||||||
escSeq[i] = 0; // terminate with NUL character
|
|
||||||
out << escSeq;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
|
bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
|
||||||
|
Reference in New Issue
Block a user