Skip to content

Commit

Permalink
remove unused StringUtil::hasUtf8()
Browse files Browse the repository at this point in the history
If needed StringUtil::isValidUTF8() could replace it.
  • Loading branch information
ulmus-scott authored and linuxdude42 committed Apr 10, 2022
1 parent b7759e7 commit b7a6433
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 49 deletions.
47 changes: 0 additions & 47 deletions mythtv/libs/libmythbase/stringutil.cpp
Expand Up @@ -131,50 +131,3 @@ bool StringUtil::isValidUTF8(const QByteArray& data)

return true;
}

/**
* \brief Guess whether a string is UTF-8
*
* \note This does not attempt to \e validate the whole string.
* It just checks if it has any UTF-8 sequences in it.
*
* \todo FIXME? skips first byte, not sure the second to last if statement makes sense
*/

bool StringUtil::hasUtf8(const char *str)
{
const unsigned char *c = (unsigned char *) str;

while (*c++)
{
// ASCII is < 0x80.
// 0xC2..0xF4 is probably UTF-8.
// Anything else probably ISO-8859-1 (Latin-1, Unicode)

if (*c > 0xC1 && *c < 0xF5)
{
int bytesToCheck = 2; // Assume 0xC2-0xDF (2 byte sequence)

if (*c > 0xDF) // Maybe 0xE0-0xEF (3 byte sequence)
++bytesToCheck;
if (*c > 0xEF) // Matches 0xF0-0xF4 (4 byte sequence)
++bytesToCheck;

while (bytesToCheck--)
{
++c;

if (! *c) // String ended in middle
return false; // Not valid UTF-8

if (*c < 0x80 || *c > 0xBF) // Bad UTF-8 sequence
break; // Keep checking in outer loop
}

if (!bytesToCheck) // Have checked all the bytes in the sequence
return true; // Hooray! We found valid UTF-8!
}
}

return false;
}
2 changes: 0 additions & 2 deletions mythtv/libs/libmythbase/stringutil.h
Expand Up @@ -15,8 +15,6 @@ inline QString indentSpaces(unsigned int level, unsigned int size = 4)
return QString(level * size, QChar(' '));
}

MBASE_PUBLIC bool hasUtf8(const char *str); // unused

/**
This is equivalent to QVariant(bool).toString()
*/
Expand Down

0 comments on commit b7a6433

Please sign in to comment.