AP Vision import

Lubomir I. Ivanov neolit123 at gmail.com
Sun Apr 16 05:15:49 PDT 2017


On 16 April 2017 at 00:01, Linus Torvalds <torvalds at linux-foundation.org> wrote:
> On Sat, Apr 15, 2017 at 1:54 PM, Linus Torvalds
> <torvalds at linux-foundation.org> wrote:
>
> But as mentioned, the pain point isn't actually the "convert latin1 to
> utf8", but the whole "check whether it's well-formatted utf8 in the
> first place".
>
> That's not technically *hard* either, it's just a bother and not  as
> mindlessly trivial as the latin1 coversion.
>

as Robert mentioned we could use a Qt helper based on QTextCodec:

QTextCodec::ConverterState state;
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
const QString text = codec->toUnicode(byteArray.constData(),
byteArray.size(), &state);
if (state.invalidChars > 0)
    qDebug() << "Not a valid UTF-8 sequence.";

(source: http://stackoverflow.com/a/18228382)

this converts the string and checks for invalid chars in a single pass.
as the stackoverflow author explains, "invalidChars" is not document
but the Class and field are public.

lubomir
--


More information about the subsurface mailing list