N
Niko Korhonen
I'm currently in the process of programming a multimedia tagging library
in standard C++. However, I've stumbled across one or two unclear issues
while working with the library.
First of all, is it safe to store binary data in std::string? This
question rose from my implementation with APEv2 tags. An APEv2 tag's field
value can contain either UTF encoded text or binary data. I've decided to
use std::string to represent the field value. This value will be plain
text in 99% of the cases, but there still is an offside chance that
someone will shove binary data into these tags.
Is there anything I should know about strings with binary data, do they
perform some automatic formatting or something like that? Something that
can possibly be dangerous to the data?
I considered using std::vector<char> to represent the field value, but it
was extremely inconvinient. I had to convert the vector to a string or
char* all over the place, because after all, strings and char*'s are the
most common use case.
Greets,
Niko Korhonen
in standard C++. However, I've stumbled across one or two unclear issues
while working with the library.
First of all, is it safe to store binary data in std::string? This
question rose from my implementation with APEv2 tags. An APEv2 tag's field
value can contain either UTF encoded text or binary data. I've decided to
use std::string to represent the field value. This value will be plain
text in 99% of the cases, but there still is an offside chance that
someone will shove binary data into these tags.
Is there anything I should know about strings with binary data, do they
perform some automatic formatting or something like that? Something that
can possibly be dangerous to the data?
I considered using std::vector<char> to represent the field value, but it
was extremely inconvinient. I had to convert the vector to a string or
char* all over the place, because after all, strings and char*'s are the
most common use case.
Greets,
Niko Korhonen