mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
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:
parent
7145876ebd
commit
6c5b16e503
2 changed files with 19 additions and 136 deletions
|
@ -27,8 +27,6 @@
|
|||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qstringlist.h>
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Capitalization routines
|
||||
//
|
||||
|
@ -69,7 +67,7 @@ QString KStringHandler::lsqueeze(const QString &str, int maxlen)
|
|||
QString KStringHandler::csqueeze(const QString &str, int maxlen)
|
||||
{
|
||||
if (str.length() > maxlen && maxlen > 3) {
|
||||
const int part = ((maxlen - 3 ) / 2);
|
||||
const int part = ((maxlen - 3) / 2);
|
||||
return str.left(part) + QLatin1String("...") + str.right(part);
|
||||
}
|
||||
return str;
|
||||
|
@ -78,7 +76,7 @@ QString KStringHandler::csqueeze(const QString &str, int maxlen)
|
|||
QString KStringHandler::rsqueeze(const QString &str, int maxlen)
|
||||
{
|
||||
if (str.length() > maxlen) {
|
||||
const int part = maxlen-3;
|
||||
const int part = maxlen - 3;
|
||||
return str.left(part) + QLatin1String("...");
|
||||
}
|
||||
return str;
|
||||
|
@ -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
|
||||
|
|
|
@ -61,14 +61,14 @@ namespace KStringHandler
|
|||
* @param text the text to capitalize
|
||||
* @return the resulting string
|
||||
*/
|
||||
KDECORE_EXPORT QString capwords( const QString &text );
|
||||
KDECORE_EXPORT QString capwords(const QString &text);
|
||||
|
||||
/** Capitalizes each word in the list
|
||||
* [hello, there] becomes [Hello, There] (list)
|
||||
* @param list the list to capitalize
|
||||
* @return the resulting list
|
||||
*/
|
||||
KDECORE_EXPORT QStringList capwords( const QStringList &list );
|
||||
KDECORE_EXPORT QStringList capwords(const QStringList &list);
|
||||
|
||||
/** Substitute characters at the beginning of a string by "...".
|
||||
* @param str is the string to modify
|
||||
|
@ -76,7 +76,7 @@ namespace KStringHandler
|
|||
* If the original string is shorter than "maxlen", it is returned verbatim
|
||||
* @return the modified string
|
||||
*/
|
||||
KDECORE_EXPORT QString lsqueeze( const QString & str, int maxlen = 40 );
|
||||
KDECORE_EXPORT QString lsqueeze( const QString & str, int maxlen = 40);
|
||||
|
||||
/** Substitute characters at the middle of a string by "...".
|
||||
* @param str is the string to modify
|
||||
|
@ -84,7 +84,7 @@ namespace KStringHandler
|
|||
* If the original string is shorter than "maxlen", it is returned verbatim
|
||||
* @return the modified string
|
||||
*/
|
||||
KDECORE_EXPORT QString csqueeze( const QString & str, int maxlen = 40 );
|
||||
KDECORE_EXPORT QString csqueeze(const QString &str, int maxlen = 40);
|
||||
|
||||
/** Substitute characters at the end of a string by "...".
|
||||
* @param str is the string to modify
|
||||
|
@ -92,7 +92,7 @@ namespace KStringHandler
|
|||
* If the original string is shorter than "maxlen", it is returned verbatim
|
||||
* @return the modified string
|
||||
*/
|
||||
KDECORE_EXPORT QString rsqueeze( const QString & str, int maxlen = 40 );
|
||||
KDECORE_EXPORT QString rsqueeze(const QString &str, int maxlen = 40);
|
||||
|
||||
/**
|
||||
* Split a QString into a QStringList in a similar fashion to the static
|
||||
|
@ -111,9 +111,9 @@ namespace KStringHandler
|
|||
* @param max is the maximum number of extractions to perform, or 0.
|
||||
* @return A QStringList containing tokens extracted from s.
|
||||
*/
|
||||
KDECORE_EXPORT QStringList perlSplit( const QString & sep,
|
||||
const QString & s,
|
||||
int max = 0 );
|
||||
KDECORE_EXPORT QStringList perlSplit(const QString &sep,
|
||||
const QString &s,
|
||||
int max = 0);
|
||||
|
||||
/**
|
||||
* Split a QString into a QStringList in a similar fashion to the static
|
||||
|
@ -132,9 +132,9 @@ namespace KStringHandler
|
|||
* @param max is the maximum number of extractions to perform, or 0.
|
||||
* @return A QStringList containing tokens extracted from s.
|
||||
*/
|
||||
KDECORE_EXPORT QStringList perlSplit( const QChar & sep,
|
||||
const QString & s,
|
||||
int max = 0 );
|
||||
KDECORE_EXPORT QStringList perlSplit(const QChar &sep,
|
||||
const QString &s,
|
||||
int max = 0);
|
||||
|
||||
/**
|
||||
* Split a QString into a QStringList in a similar fashion to the static
|
||||
|
@ -153,9 +153,9 @@ namespace KStringHandler
|
|||
* @param max is the maximum number of extractions to perform, or 0.
|
||||
* @return A QStringList containing tokens extracted from s.
|
||||
*/
|
||||
KDECORE_EXPORT QStringList perlSplit( const QRegExp & sep,
|
||||
const QString & s,
|
||||
int max = 0);
|
||||
KDECORE_EXPORT QStringList perlSplit(const QRegExp &sep,
|
||||
const QString &s,
|
||||
int max = 0);
|
||||
|
||||
/**
|
||||
* This method auto-detects URLs in strings, and adds HTML markup to them
|
||||
|
@ -163,25 +163,7 @@ namespace KStringHandler
|
|||
* @param text the string which may contain URLs
|
||||
* @return the resulting text
|
||||
*/
|
||||
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 );
|
||||
KDECORE_EXPORT QString tagUrls(const QString &text);
|
||||
|
||||
/**
|
||||
Does a natural comparing of the strings. A negative value is returned if \a a
|
||||
|
@ -194,7 +176,7 @@ namespace KStringHandler
|
|||
|
||||
@since 4.1
|
||||
*/
|
||||
KDECORE_EXPORT int naturalCompare( const QString& a, const QString& b, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive );
|
||||
KDECORE_EXPORT int naturalCompare(const QString &a, const QString &b, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive);
|
||||
|
||||
/**
|
||||
Preprocesses the given string in order to provide additional line breaking
|
||||
|
@ -209,6 +191,6 @@ namespace KStringHandler
|
|||
|
||||
@since 4.4
|
||||
*/
|
||||
KDECORE_EXPORT QString preProcessWrap( const QString& text );
|
||||
KDECORE_EXPORT QString preProcessWrap(const QString &text);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue