Switched YAML::Binary interface to use unsigned chars, not chars

This commit is contained in:
Jesse Beder
2011-09-06 00:39:31 -05:00
parent fadca5a89d
commit dd1eb715c4
4 changed files with 8 additions and 8 deletions

View File

@@ -127,12 +127,12 @@ namespace YAML
} }
struct _Binary { struct _Binary {
_Binary(const char *data_, std::size_t size_): data(data_), size(size_) {} _Binary(const unsigned char *data_, std::size_t size_): data(data_), size(size_) {}
const char *data; const unsigned char *data;
std::size_t size; std::size_t size;
}; };
inline _Binary Binary(const char *data, std::size_t size) { inline _Binary Binary(const unsigned char *data, std::size_t size) {
return _Binary(data, size); return _Binary(data, size);
} }
} }

View File

@@ -347,7 +347,7 @@ namespace YAML
return true; return true;
} }
bool WriteBinary(ostream& out, const char *data, std::size_t size) bool WriteBinary(ostream& out, const unsigned char *data, std::size_t size)
{ {
static const char encoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char encoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const char PAD = '='; const char PAD = '=';

View File

@@ -22,7 +22,7 @@ namespace YAML
bool WriteAnchor(ostream& out, const std::string& str); bool WriteAnchor(ostream& out, const std::string& str);
bool WriteTag(ostream& out, const std::string& str, bool verbatim); bool WriteTag(ostream& out, const std::string& str, bool verbatim);
bool WriteTagWithPrefix(ostream& out, const std::string& prefix, const std::string& tag); bool WriteTagWithPrefix(ostream& out, const std::string& prefix, const std::string& tag);
bool WriteBinary(ostream& out, const char *data, std::size_t size); bool WriteBinary(ostream& out, const unsigned char *data, std::size_t size);
} }
} }

View File

@@ -759,19 +759,19 @@ namespace Test
void Binary(YAML::Emitter& out, std::string& desiredOutput) void Binary(YAML::Emitter& out, std::string& desiredOutput)
{ {
out << YAML::Binary("Hello, World!", 13); out << YAML::Binary(reinterpret_cast<const unsigned char*>("Hello, World!"), 13);
desiredOutput = "!!binary \"SGVsbG8sIFdvcmxkIQ==\""; desiredOutput = "!!binary \"SGVsbG8sIFdvcmxkIQ==\"";
} }
void LongBinary(YAML::Emitter& out, std::string& desiredOutput) void LongBinary(YAML::Emitter& out, std::string& desiredOutput)
{ {
out << YAML::Binary("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.\n", 270); out << YAML::Binary(reinterpret_cast<const unsigned char*>("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.\n"), 270);
desiredOutput = "!!binary \"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4K\""; desiredOutput = "!!binary \"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4K\"";
} }
void EmptyBinary(YAML::Emitter& out, std::string& desiredOutput) void EmptyBinary(YAML::Emitter& out, std::string& desiredOutput)
{ {
out << YAML::Binary("", 0); out << YAML::Binary(reinterpret_cast<const unsigned char *>(""), 0);
desiredOutput = "!!binary \"\""; desiredOutput = "!!binary \"\"";
} }