KStringHandler Class Reference
This class contains utility functions for handling strings. Class for manipulating words and sentences in strings. More...
#include <kstringhandler.h>
Static Public Member Functions | |
QString | word (const QString &text, uint pos) KDE_DEPRECATED |
QString | word (const QString &text, const char *range) |
QString | insword (const QString &text, const QString &word, uint pos) |
QString | setword (const QString &text, const QString &word, uint pos) |
QString | remrange (const QString &text, const char *range) |
QString | remword (const QString &text, uint pos) |
QString | remword (const QString &text, const QString &word) |
QString | capwords (const QString &text) |
QStringList | capwords (const QStringList &list) |
QString | reverse (const QString &text) |
QStringList | reverse (const QStringList &list) |
QString | ljust (const QString &text, uint width) KDE_DEPRECATED |
QString | rjust (const QString &text, uint width) KDE_DEPRECATED |
QString | center (const QString &text, uint width) |
QString | lsqueeze (const QString &str, uint maxlen=40) |
QString | lEmSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxlen=30) |
QString | lPixelSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxPixels) |
QString | csqueeze (const QString &str, uint maxlen=40) |
QString | cEmSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxlen=30) |
QString | cPixelSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxPixels) |
QString | rsqueeze (const QString &str, uint maxlen=40) |
QString | rEmSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxlen=30) |
QString | rPixelSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxPixels) |
bool | matchFileName (const QString &filename, const QString &pattern) |
QStringList | perlSplit (const QString &sep, const QString &s, uint max=0) |
QStringList | perlSplit (const QChar &sep, const QString &s, uint max=0) |
QStringList | perlSplit (const QRegExp &sep, const QString &s, uint max=0) |
QString | tagURLs (const QString &text) |
QString | obscure (const QString &str) |
bool | isUtf8 (const char *str) |
QString | from8Bit (const char *str) |
KDE_DEPRECATED bool | matchFilename (const QString &filename, const QString &pattern) |
Detailed Description
This class contains utility functions for handling strings. Class for manipulating words and sentences in strings.This class is not a substitute for the QString class. What I tried to do with this class is provide an easy way to cut/slice/splice words inside sentences in whatever order desired. While the main focus of this class are words (ie characters separated by spaces/tabs), the two core functions here ( split() and join() ) will function given any char to use as a separator. This will make it easy to redefine what a 'word' means in the future if needed.
I freely stole some of the function names from python. I also think some of these were influenced by mIRC (yes, believe it if you will, I used to write a LOT of scripts in mIRC).
The ranges are a fairly powerful way of getting/stripping words from a string. These ranges function, for the large part, as they would in python. See the word(const QString&, int) and remword(const QString&, int) functions for more detail.
This class contains no data members of it own. All strings are cut on the fly and returned as new qstrings/qstringlists.
Quick example on how to use:
and so forth.
- Author:
- Ian Zepp <icszepp@islc.net>
- See also:
- KShell
Definition at line 70 of file kstringhandler.h.
Member Function Documentation
|
Returns the nth word in the string if found Returns a EMPTY (not null) string otherwise. Note that the FIRST index is 0.
Definition at line 43 of file kstringhandler.cpp. References QString::section(), and word(). Referenced by word(). |
|
Returns a range of words from that string. Ie:
Definition at line 48 of file kstringhandler.cpp. References QString::isEmpty(), QString::stripWhiteSpace(), and word(). |
|
Inserts a word into the string, and returns a new string with the word included.
the first index is zero (0). If there are not
Definition at line 84 of file kstringhandler.cpp. References insword(), QString::isEmpty(), and QStringList::join(). Referenced by insword(). |
|
Replaces a word in the string, and returns a new string with the word included.
the first index is zero (0). If there are not
Definition at line 104 of file kstringhandler.cpp. References QString::isEmpty(), QStringList::join(), and setword(). Referenced by setword(). |
|
Removes a word or ranges of words from the string, and returns a new string. The ranges definitions follow the definitions for the word() function.
Definition at line 126 of file kstringhandler.cpp. References QString::isEmpty(), QStringList::join(), and remrange(). Referenced by remrange(). |
|
Removes a word at the given index, and returns a new string. The first index is zero (0).
Definition at line 155 of file kstringhandler.cpp. References QString::isEmpty(), QStringList::join(), and remword(). Referenced by remword(). |
|
Removes a matching word from the string, and returns a new string. Note that only ONE match is removed.
Definition at line 172 of file kstringhandler.cpp. References QString::isEmpty(), QStringList::join(), and remword(). |
|
Capitalizes each word in the string "hello there" becomes "Hello There" (string).
Definition at line 197 of file kstringhandler.cpp. References capwords(), QString::isEmpty(), QStringList::join(), QString::replace(), and QString::stripWhiteSpace(). Referenced by capwords(). |
|
Capitalizes each word in the list [hello, there] becomes [Hello, There] (list).
Definition at line 211 of file kstringhandler.cpp. References capwords(). |
|
Reverses the order of the words in a string "hello there" becomes "there hello" (string).
Definition at line 223 of file kstringhandler.cpp. References QString::isEmpty(), QStringList::join(), and reverse(). Referenced by reverse(). |
|
Reverses the order of the words in a list [hello, there] becomes [there, hello] (list).
Definition at line 237 of file kstringhandler.cpp. References reverse(). |
|
Left-justifies a string and returns a string at least 'width' characters wide.
If the string is longer than the
Definition at line 255 of file kstringhandler.cpp. References ljust(), and QString::stripWhiteSpace(). Referenced by ljust(). |
|
Right-justifies a string and returns a string at least 'width' characters wide.
If the string is longer than the
Definition at line 260 of file kstringhandler.cpp. References rjust(), and QString::stripWhiteSpace(). Referenced by rjust(). |
|
Centers a string and returns a string at least 'width' characters wide.
If the string is longer than the
Definition at line 265 of file kstringhandler.cpp. References center(), QString::fill(), QString::leftJustify(), QString::length(), and QString::stripWhiteSpace(). Referenced by center(). |
|
Substitute characters at the beginning of a string by "...".
Definition at line 280 of file kstringhandler.cpp. References QString::length(), lsqueeze(), and QString::right(). Referenced by lsqueeze(). |
|
Substitute characters at the beginning of a string by "...". Similar to method above, except that it truncates based on pixel width rather than the number of characters
Definition at line 307 of file kstringhandler.cpp. References lEmSqueeze(), lPixelSqueeze(), and QFontMetrics::maxWidth(). Referenced by lEmSqueeze(). |
|
Substitute characters at the beginning of a string by "...". Similar to method above, except that maxlen is the width in pixels to truncate to
Definition at line 312 of file kstringhandler.cpp. References QString::isEmpty(), lPixelSqueeze(), QFontMetrics::maxWidth(), QString::remove(), and QFontMetrics::width(). Referenced by lEmSqueeze(), and lPixelSqueeze(). |
|
Substitute characters at the middle of a string by "...".
Definition at line 289 of file kstringhandler.cpp. References csqueeze(), QString::left(), QString::length(), and QString::right(). Referenced by csqueeze(). |
|
Substitute characters in the middle of a string by "...". Similar to method above, except that it truncates based on pixel width rather than the number of characters
Definition at line 337 of file kstringhandler.cpp. References cEmSqueeze(), cPixelSqueeze(), and QFontMetrics::maxWidth(). Referenced by cEmSqueeze(). |
|
Substitute characters in the middle of a string by "...". Similar to method above, except that maxlen is the width in pixels to truncate to
Definition at line 342 of file kstringhandler.cpp. References QFontMetrics::charWidth(), cPixelSqueeze(), QString::isEmpty(), QString::left(), QString::length(), QString::right(), and QFontMetrics::width(). Referenced by cEmSqueeze(), and cPixelSqueeze(). |
|
Substitute characters at the end of a string by "...".
Definition at line 298 of file kstringhandler.cpp. References QString::left(), QString::length(), and rsqueeze(). Referenced by rsqueeze(). |
|
Substitute characters at the end of a string by "...". Similar to method above, except that it truncates based on pixel width rather than the number of characters
Definition at line 384 of file kstringhandler.cpp. References QFontMetrics::maxWidth(), rEmSqueeze(), and rPixelSqueeze(). Referenced by rEmSqueeze(). |
|
Substitute characters at the end of a string by "...". Similar to method above, except that maxlen is the width in pixels to truncate to
Definition at line 389 of file kstringhandler.cpp. References QString::isEmpty(), QString::length(), QFontMetrics::maxWidth(), QString::remove(), rPixelSqueeze(), and QFontMetrics::width(). Referenced by rEmSqueeze(), and rPixelSqueeze(). |
|
Match a filename.
Definition at line 417 of file kstringhandler.cpp. References QString::find(), QString::length(), matchFileName(), QString::mid(), and QString::unicode(). Referenced by matchFileName(). |
|
Split a QString into a QStringList in a similar fashion to the static QStringList function in Qt, except you can specify a maximum number of tokens. If max is specified (!= 0) then only that number of tokens will be extracted. The final token will be the remainder of the string. Example:
Definition at line 456 of file kstringhandler.cpp. References QString::find(), QString::length(), QString::mid(), and perlSplit(). Referenced by perlSplit(). |
|
Split a QString into a QStringList in a similar fashion to the static QStringList function in Qt, except you can specify a maximum number of tokens. If max is specified (!= 0) then only that number of tokens will be extracted. The final token will be the remainder of the string. Example:
Definition at line 482 of file kstringhandler.cpp. References QString::find(), QString::length(), QString::mid(), and perlSplit(). |
|
Split a QString into a QStringList in a similar fashion to the static QStringList function in Qt, except you can specify a maximum number of tokens. If max is specified (!= 0) then only that number of tokens will be extracted. The final token will be the remainder of the string. Example:
Definition at line 508 of file kstringhandler.cpp. References QString::length(), QRegExp::matchedLength(), QString::mid(), perlSplit(), and QRegExp::search(). |
|
This method auto-detects URLs in strings, and adds HTML markup to them so that richtext or HTML-enabled widgets (such as KActiveLabel) will display the URL correctly.
Definition at line 535 of file kstringhandler.cpp. References QString::length(), QRegExp::matchedLength(), QString::mid(), QString::replace(), QRegExp::search(), and tagURLs(). Referenced by tagURLs(). |
|
Obscure string by using a simple symmetric encryption. Applying the function to a string obscured by this function will result in the original string. The function can be used to obscure passwords stored to configuration files. Note that this won't give you any more security than preventing that the password is directly copied and pasted.
Definition at line 560 of file kstringhandler.cpp. References QString::length(), obscure(), QChar::unicode(), and QString::unicode(). Referenced by obscure(). |
|
Guess whether a string is UTF8 encoded.
Definition at line 571 of file kstringhandler.cpp. References isUtf8(). Referenced by from8Bit(), and isUtf8(). |
|
Construct QString from a c string, guessing whether it is UTF8- or Local8Bit-encoded.
Definition at line 656 of file kstringhandler.cpp. References from8Bit(), and isUtf8(). Referenced by from8Bit(). |
|
Definition at line 436 of file kstringhandler.h. |
The documentation for this class was generated from the following files: