3 ms·
I would try utf-8, and otherwise just panic ("invalid input: string is not utf-8 encoded"). Obviously it depends on the context, but I think parsers should be
by protomikron 10y ago
I would try utf-8, and otherwise just panic ("invalid input: string is not utf-8 encoded").
Obviously it depends on the context, but I think parsers should be strict, otherwise ambiguities leak into your system.
- icebraining 10y agoI'm not saying "try multiple encodings till you get something". I'm asking about the API when the encoding is not static, but provided at runtime, like in XML files, eg: <?xml version="1.0" encoding="ISO-8859-1"?>
- majewsky 10y agoYou would have the QByteArray first (e.g. read from a file or socket), parse the <?xml?>, thus find the encoding, convert the rest to QString with that, and parse the rest from the QString.
- icebraining 10y agoMy question is how does one "convert the rest to QString with that", in terms of actual code?