Skip to content

Commit

Permalink
CharsetConverter: remove outdated "isValidUtf8()"
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlson2k committed Dec 2, 2013
1 parent 543d3e8 commit dd621b9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 70 deletions.
66 changes: 0 additions & 66 deletions xbmc/utils/CharsetConverter.cpp
Expand Up @@ -863,72 +863,6 @@ bool CCharsetConverter::utf8ToSystem(std::string& stringSrcDst, bool failOnBadCh
return CInnerConverter::stdConvert(Utf8ToSystem, strSrc, stringSrcDst, failOnBadChar);
}

// Taken from RFC2640
bool CCharsetConverter::isValidUtf8(const char* buf, unsigned int len)
{
const unsigned char* endbuf = (unsigned char*)buf + len;
unsigned char byte2mask=0x00, c;
int trailing=0; // trailing (continuation) bytes to follow

while ((unsigned char*)buf != endbuf)
{
c = *buf++;
if (trailing)
if ((c & 0xc0) == 0x80) // does trailing byte follow UTF-8 format ?
{
if (byte2mask) // need to check 2nd byte for proper range
{
if (c & byte2mask) // are appropriate bits set ?
byte2mask = 0x00;
else
return false;
}
trailing--;
}
else
return 0;
else
if ((c & 0x80) == 0x00) continue; // valid 1-byte UTF-8
else if ((c & 0xe0) == 0xc0) // valid 2-byte UTF-8
if (c & 0x1e) //is UTF-8 byte in proper range ?
trailing = 1;
else
return false;
else if ((c & 0xf0) == 0xe0) // valid 3-byte UTF-8
{
if (!(c & 0x0f)) // is UTF-8 byte in proper range ?
byte2mask = 0x20; // if not set mask
trailing = 2; // to check next byte
}
else if ((c & 0xf8) == 0xf0) // valid 4-byte UTF-8
{
if (!(c & 0x07)) // is UTF-8 byte in proper range ?
byte2mask = 0x30; // if not set mask
trailing = 3; // to check next byte
}
else if ((c & 0xfc) == 0xf8) // valid 5-byte UTF-8
{
if (!(c & 0x03)) // is UTF-8 byte in proper range ?
byte2mask = 0x38; // if not set mask
trailing = 4; // to check next byte
}
else if ((c & 0xfe) == 0xfc) // valid 6-byte UTF-8
{
if (!(c & 0x01)) // is UTF-8 byte in proper range ?
byte2mask = 0x3c; // if not set mask
trailing = 5; // to check next byte
}
else
return false;
}
return trailing == 0;
}

bool CCharsetConverter::isValidUtf8(const std::string& str)
{
return isValidUtf8(str.c_str(), str.size());
}

bool CCharsetConverter::utf8logicalToVisualBiDi(const std::string& utf8StringSrc, std::string& utf8StringDst, bool failOnBadString /*= false*/)
{
utf8StringDst.clear();
Expand Down
4 changes: 0 additions & 4 deletions xbmc/utils/CharsetConverter.h
Expand Up @@ -144,10 +144,6 @@ class CCharsetConverter : public ISettingCallback

static bool ToUtf8(const std::string& strSourceCharset, const std::string& stringSrc, std::string& utf8StringDst);

static bool isValidUtf8(const std::string& str);

static bool isValidUtf8(const char* buf, unsigned int len);

static bool wToUTF8(const std::wstring& wStringSrc, std::string& utf8StringDst, bool failOnBadChar = false);
static bool utf16BEtoUTF8(const std::u16string& utf16StringSrc, std::string& utf8StringDst);
static bool utf16LEtoUTF8(const std::u16string& utf16StringSrc, std::string& utf8StringDst);
Expand Down

0 comments on commit dd621b9

Please sign in to comment.