I had implemented app on some device which was dealing with sending receiving data from server. Data from server would usually come in this form:
"1;username;someInteger;"
Parsing was easy, and I was using strtok as you can imagine to retrieve individual values from that string such as: 1, username, and someInteger.
But now a situation may occur when the server will send me unicode string as username.
I think good idea is to use the username encoded as a UTF-8 string (am I right?). What do you recommend - how should I parse it from above string? What symbol to use as a separator for example (e.g., instead of ";"), or which functions to use to extract the username from above string?
as this is some embedded device I want to avoid installing some third party libraries there (which might not be even possible) so more "pure" ways would be more desirable.
strtok. It’s not thread-safe. Useboost::splitinstead.boostfor a simple substitution ofstrtok(). It's too big. Usestrtok_r()instead.strtoksource code, or binary code generated for it? is it "small" comparing to "boost::split"?strtok(), and here isiter_split()thatboost::algorithm::string::split()uses. Altogether,strtok()is fewer SLOC than the boost thingy, but it has the advantage that it's 1. standard, 2. doesn't require inclusion of huge headers, 3. it works in C too.