KStringHandler Class Reference
#include <kstringhandler.h>
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&, const char *) and remword(const QString&, uint) functions for more detail.
This class contains no data members of its 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:" ) << "\n"; cout << "2> " << kstr.remrange( line , "2:5" ) << "\n"; cout << "2> " << kstr.reverse( line ) << "\n"; cout << "2> " << kstr.center( kstr.word( line , 4 ) , 15 ) << "\n";
and so forth.
- Author:
- Ian Zepp <icszepp@islc.net>
- See also:
- KShell
Definition at line 69 of file kstringhandler.h.
Static Public Member Functions | |
static QString | word (const QString &text, uint pos) KDE_DEPRECATED |
static QString | word (const QString &text, const char *range) |
static QString | insword (const QString &text, const QString &word, uint pos) |
static QString | setword (const QString &text, const QString &word, uint pos) |
static QString | remrange (const QString &text, const char *range) |
static QString | remword (const QString &text, uint pos) |
static QString | remword (const QString &text, const QString &word) |
static QString | capwords (const QString &text) |
static QStringList | capwords (const QStringList &list) |
static QString | reverse (const QString &text) |
static QStringList | reverse (const QStringList &list) |
static QString | ljust (const QString &text, uint width) KDE_DEPRECATED |
static QString | rjust (const QString &text, uint width) KDE_DEPRECATED |
static QString | center (const QString &text, uint width) |
static QString | lsqueeze (const QString &str, uint maxlen=40) |
static QString | lEmSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxlen=30) |
static QString | lPixelSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxPixels) |
static QString | csqueeze (const QString &str, uint maxlen=40) |
static QString | cEmSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxlen=30) |
static QString | cPixelSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxPixels) |
static QString | rsqueeze (const QString &str, uint maxlen=40) |
static QString | rEmSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxlen=30) |
static QString | rPixelSqueeze (const QString &name, const QFontMetrics &fontMetrics, uint maxPixels) |
static bool | matchFileName (const QString &filename, const QString &pattern) |
static QStringList | perlSplit (const QString &sep, const QString &s, uint max=0) |
static QStringList | perlSplit (const QChar &sep, const QString &s, uint max=0) |
static QStringList | perlSplit (const QRegExp &sep, const QString &s, uint max=0) |
static QString | tagURLs (const QString &text) |
static QString | obscure (const QString &str) |
static bool | isUtf8 (const char *str) |
static QString | from8Bit (const char *str) |
static KDE_DEPRECATED bool | matchFilename (const QString &filename, const QString &pattern) |
Member Function Documentation
|
Capitalizes each word in the list [hello, there] becomes [Hello, There] (list).
Definition at line 207 of file kstringhandler.cpp. |
|
Capitalizes each word in the string "hello there" becomes "Hello There" (string).
Definition at line 193 of file kstringhandler.cpp. |
|
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 333 of file kstringhandler.cpp. |
|
Centers a string and returns a string at least 'width' characters wide.
If the string is longer than the
Definition at line 261 of file kstringhandler.cpp. |
|
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 338 of file kstringhandler.cpp. |
|
Substitute characters at the middle of a string by ". ..".
Definition at line 285 of file kstringhandler.cpp. |
|
Construct QString from a c string, guessing whether it is UTF8- or Local8Bit-encoded.
Definition at line 652 of file kstringhandler.cpp. |
|
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 80 of file kstringhandler.cpp. |
|
Guess whether a string is UTF8 encoded.
Definition at line 567 of file kstringhandler.cpp. |
|
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 303 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 251 of file kstringhandler.cpp. |
|
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 308 of file kstringhandler.cpp. |
|
Substitute characters at the beginning of a string by ". ..".
Definition at line 276 of file kstringhandler.cpp. |
|
Definition at line 435 of file kstringhandler.h. |
|
Match a filename.
Definition at line 413 of file kstringhandler.cpp. |
|
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 556 of file kstringhandler.cpp. |
|
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 504 of file kstringhandler.cpp. |
|
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 parts other parts can't"
Definition at line 478 of file kstringhandler.cpp. |
|
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 452 of file kstringhandler.cpp. |
|
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 122 of file kstringhandler.cpp. |
|
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 380 of file kstringhandler.cpp. |
|
Removes a matching word from the string, and returns a new string. Note that only ONE match is removed.
Definition at line 168 of file kstringhandler.cpp. |
|
Removes a word at the given index, and returns a new string. The first index is zero (0).
Definition at line 151 of file kstringhandler.cpp. |
|
Reverses the order of the words in a list [hello, there] becomes [there, hello] (list).
Definition at line 233 of file kstringhandler.cpp. |
|
Reverses the order of the words in a string "hello there" becomes "there hello" (string).
Definition at line 219 of file kstringhandler.cpp. |
|
Right-justifies a string and returns a string at least 'width' characters wide.
If the string is longer than the
Definition at line 256 of file kstringhandler.cpp. |
|
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 385 of file kstringhandler.cpp. |
|
Substitute characters at the end of a string by ". ..".
Definition at line 294 of file kstringhandler.cpp. |
|
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 100 of file kstringhandler.cpp. |
|
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 531 of file kstringhandler.cpp. |
|
Returns a range of words from that string. Ie:
Definition at line 44 of file kstringhandler.cpp. |
|
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 39 of file kstringhandler.cpp. |
The documentation for this class was generated from the following files: