kdecore: remove unused and redundant KStringHandler::isUtf8() and KStringHandler::from8Bit() methods

use QTextCodec::codecForText() and QTextConverter instead

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-28 03:32:57 +03:00
parent 7145876ebd
commit 6c5b16e503
2 changed files with 19 additions and 136 deletions

View file

@ -27,8 +27,6 @@
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
//
// Capitalization routines
//
@ -178,103 +176,6 @@ QString KStringHandler::tagUrls(const QString &text)
return richText;
}
bool KStringHandler::isUtf8(const char *buf)
{
int i, n;
unsigned char c;
bool gotone = false;
if (!buf)
return true; // whatever, just don't crash
#define F 0 /* character never appears in text */
#define T 1 /* character appears in plain ASCII text */
#define I 2 /* character appears in ISO-8859 text */
#define X 3 /* character appears in non-ISO extended ASCII (Mac, IBM PC) */
static const unsigned char text_chars[256] = {
/* BEL BS HT LF FF CR */
F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F, /* 0x0X */
/* ESC */
F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F, /* 0x1X */
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x2X */
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x3X */
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x4X */
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x5X */
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x6X */
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, F, /* 0x7X */
/* NEL */
X, X, X, X, X, T, X, X, X, X, X, X, X, X, X, X, /* 0x8X */
X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, /* 0x9X */
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xaX */
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xbX */
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xcX */
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xdX */
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xeX */
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I /* 0xfX */
};
/* *ulen = 0; */
for (i = 0; (c = buf[i]); ++i) {
if ((c & 0x80) == 0) { /* 0xxxxxxx is plain ASCII */
/*
* Even if the whole file is valid UTF-8 sequences,
* still reject it if it uses weird control characters.
*/
if (text_chars[c] != T)
return false;
} else if ((c & 0x40) == 0) { /* 10xxxxxx never 1st byte */
return false;
} else { /* 11xxxxxx begins UTF-8 */
int following;
if ((c & 0x20) == 0) { /* 110xxxxx */
following = 1;
} else if ((c & 0x10) == 0) { /* 1110xxxx */
following = 2;
} else if ((c & 0x08) == 0) { /* 11110xxx */
following = 3;
} else if ((c & 0x04) == 0) { /* 111110xx */
following = 4;
} else if ((c & 0x02) == 0) { /* 1111110x */
following = 5;
} else {
return false;
}
for (n = 0; n < following; ++n) {
i++;
if (!(c = buf[i]))
goto done;
if ((c & 0x80) == 0 || (c & 0x40))
return false;
}
gotone = true;
}
}
done:
return gotone; /* don't claim it's UTF-8 if it's all 7-bit */
}
#undef F
#undef T
#undef I
#undef X
QString KStringHandler::from8Bit(const char *str)
{
if (!str || !*str) {
return QString();
}
if (KStringHandler::isUtf8(str)) {
return QString::fromUtf8(str);
}
return QString::fromLocal8Bit(str);
}
int KStringHandler::naturalCompare(const QString &_a, const QString &_b, Qt::CaseSensitivity caseSensitivity)
{
// This method chops the input a and b into pieces of

View file

@ -165,24 +165,6 @@ namespace KStringHandler
*/
KDECORE_EXPORT QString tagUrls(const QString &text);
/**
Guess whether a string is UTF8 encoded.
@param str the string to check
@return true if UTF8. If false, the string is probably in Local8Bit.
*/
KDECORE_EXPORT bool isUtf8( const char *str );
/**
Construct QString from a c string, guessing whether it is UTF8- or
Local8Bit-encoded.
@param str the input string
@return the (hopefully correctly guessed) QString representation of @p str
*/
KDECORE_EXPORT QString from8Bit( const char *str );
/**
Does a natural comparing of the strings. A negative value is returned if \a a
is smaller than \a b. A positive value is returned if \a a is greater than \a b. 0