MythTV  master
codecutil.cpp
Go to the documentation of this file.
1 
2 #include "codecutil.h"
3 
4 #include <QTextCodec>
5 
6 bool CodecUtil::isValidUTF8(const QByteArray& data)
7 {
8  // NOTE: If you have a better way to determine this, then please update this
9  // Any chosen method MUST be able to identify UTF-8 encoded text without
10  // using the BOM Byte-Order Mark as that will probably not be present.
11  QTextCodec::ConverterState state;
12  QTextCodec *codec = QTextCodec::codecForName("UTF-8");
13  const QString text = codec->toUnicode(data.constData(), data.size(), &state);
14  if (state.invalidChars > 0)
15  return false;
16 
17  Q_UNUSED(text);
18  return true;
19 }
CodecUtil::isValidUTF8
static bool isValidUTF8(const QByteArray &data)
Definition: codecutil.cpp:6
codecutil.h