KStringHandler Class Reference
This class is not a substitute for the QString class. Class for manipulating words and sentences in strings. More...
#include <kstringhandler.h>
Static Public Methods | |
QString | word (const QString &text, uint pos) |
Returns the nth word in the string if found Returns a EMPTY (not null) string otherwise. | |
QString | word (const QString &text, const char *range) |
Returns a range of words from that string. | |
QString | insword (const QString &text, const QString &word, uint pos) |
Inserts a word into the string, and returns a new string with the word included. | |
QString | setword (const QString &text, const QString &word, uint pos) |
Replaces a word in the string, and returns a new string with the word included. | |
QString | remrange (const QString &text, const char *range) |
Removes a word or ranges of words from the string, and returns a new string. | |
QString | remword (const QString &text, uint pos) |
Removes a word at the given index, and returns a new string. | |
QString | remword (const QString &text, const QString &word) |
Removes a matching word from the string, and returns a new string. | |
QString | capwords (const QString &text) |
Capitalizes each word in the string "hello there" becomes "Hello There" (string). | |
QStringList | capwords (const QStringList &list) |
Capitalizes each word in the list [hello, there] becomes [Hello, There] (list). | |
QString | reverse (const QString &text) |
Reverses the order of the words in a string "hello there" becomes "there hello" (string). | |
QStringList | reverse (const QStringList &list) |
Reverses the order of the words in a list [hello, there] becomes [there, hello] (list). | |
QString | ljust (const QString &text, uint width) |
Left-justifies a string and returns a string at least 'width' characters wide. | |
QString | rjust (const QString &text, uint width) |
Right-justifies a string and returns a string at least 'width' characters wide. | |
QString | center (const QString &text, uint width) |
Centers a string and returns a string at least 'width' characters wide. | |
QString | lsqueeze (const QString &str, uint maxlen=40) |
Substitute characters at the beginning of a string by "...". | |
QString | csqueeze (const QString &str, uint maxlen=40) |
Substitute characters at the middle of a string by "...". | |
QString | rsqueeze (const QString &str, uint maxlen=40) |
Substitute characters at the end of a string by "...". | |
bool | matchFileName (const QString &filename, const QString &pattern) |
Match a filename. | |
QStringList | perlSplit (const QString &sep, const QString &s, uint max=0) |
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. | |
QStringList | perlSplit (const QChar &sep, const QString &s, uint max=0) |
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. | |
QStringList | perlSplit (const QRegExp &sep, const QString &s, uint max=0) |
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. | |
QString | tagURLs (const QString &text) |
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. | |
bool | matchFilename (const QString &filename, const QString &pattern) |
Detailed Description
This class is not a substitute for the QString class. Class for manipulating words and sentences in strings.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:
KStringHandler kstr; QString line = "This is a test of the strings"; cout << "1> " << kstr.word( line , "4:" ) << "
"; cout << "2> " << kstr.remrange( line , "2:5" ) << "
"; cout << "2> " << kstr.reverse( line ) << "
"; cout << "2> " << kstr.center( kstr.word( line , 4 ) , 15 ) << "
";
and so forth.
- Author:
- Ian Zepp <icszepp@islc.net>
Definition at line 66 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 26 of file kstringhandler.cpp. References QStringList::split(). Referenced by capwords(). |
|
Returns a range of words from that string. Ie:
Definition at line 36 of file kstringhandler.cpp. References QString::ascii(), QString::find(), QString::isEmpty(), QString::left(), QString::remove(), QStringList::split(), and QString::stripWhiteSpace(). |
|
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 104 of file kstringhandler.cpp. References QString::isEmpty(), QStringList::join(), and QStringList::split(). |
|
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 124 of file kstringhandler.cpp. References QString::isEmpty(), QStringList::join(), and QStringList::split(). |
|
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 146 of file kstringhandler.cpp. References QString::ascii(), QString::find(), QString::isEmpty(), QStringList::join(), QString::left(), QString::remove(), and QStringList::split(). |
|
Removes a word at the given index, and returns a new string. The first index is zero (0).
Definition at line 207 of file kstringhandler.cpp. References QString::isEmpty(), QStringList::join(), and QStringList::split(). |
|
Removes a matching word from the string, and returns a new string. Note that only ONE match is removed.
Definition at line 224 of file kstringhandler.cpp. References QString::isEmpty(), QStringList::join(), and QStringList::split(). |
|
Capitalizes each word in the string "hello there" becomes "Hello There" (string).
Definition at line 249 of file kstringhandler.cpp. References QString::isEmpty(), and QStringList::split(). |
|
Capitalizes each word in the list [hello, there] becomes [Hello, There] (list).
Definition at line 261 of file kstringhandler.cpp. References QString::left(), QString::remove(), and word(). |
|
Reverses the order of the words in a string "hello there" becomes "there hello" (string).
Definition at line 285 of file kstringhandler.cpp. References QString::isEmpty(), QStringList::join(), and QStringList::split(). |
|
Reverses the order of the words in a list [hello, there] becomes [there, hello] (list).
Definition at line 299 of file kstringhandler.cpp. |
|
Left-justifies a string and returns a string at least 'width' characters wide.
If the string is longer than the
Definition at line 317 of file kstringhandler.cpp. References QString::append(), QString::length(), and QString::stripWhiteSpace(). |
|
Right-justifies a string and returns a string at least 'width' characters wide.
If the string is longer than the
Definition at line 331 of file kstringhandler.cpp. References QString::length(), QString::prepend(), and QString::stripWhiteSpace(). |
|
Centers a string and returns a string at least 'width' characters wide.
If the string is longer than the
Definition at line 345 of file kstringhandler.cpp. References QString::append(), QString::length(), QString::prepend(), and QString::stripWhiteSpace(). |
|
Substitute characters at the beginning of a string by "...".
Definition at line 373 of file kstringhandler.cpp. References QString::length(), and QString::right(). |
|
Substitute characters at the middle of a string by "...".
Definition at line 382 of file kstringhandler.cpp. References QString::left(), QString::length(), and QString::right(). |
|
Substitute characters at the end of a string by "...".
Definition at line 391 of file kstringhandler.cpp. References QString::left(), and QString::length(). |
|
Match a filename.
Definition at line 402 of file kstringhandler.cpp. References QString::length(), 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: perlSplit("__", "some__string__for__you__here", 4) QStringList contains: "some", "string", "for", "you__here"
Definition at line 436 of file kstringhandler.cpp. References QString::find(), QString::length(), and QString::mid(). |
|
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: perlSplit(' ', "kparts reaches the parts other parts can't", 3) QStringList contains: "kparts", "reaches", "the pats other parts can't"
Definition at line 462 of file kstringhandler.cpp. References QString::find(), QString::length(), and QString::mid(). |
|
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: perlSplit(QRegExp("[! ]", "Split me up ! I'm bored ! OK ?", 3) QStringList contains: "Split", "me", "up ! I'm bored, OK ?"
Definition at line 488 of file kstringhandler.cpp. References QString::length(), QRegExp::matchedLength(), QString::mid(), 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 515 of file kstringhandler.cpp. References QString::length(), QRegExp::matchedLength(), QString::mid(), QString::replace(), and QRegExp::search(). |
|
Definition at line 310 of file kstringhandler.h. References matchFileName(). |
The documentation for this class was generated from the following files: