Namespace KStringHandler |
|
This class contains utility functions for handling 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.
Namespace for manipulating words and sentences in strings
Author Ian Zepp See also KShell |
|
Capitalizes each word in the string
"hello there" becomes "Hello There" (string)
text - the text to capitalize Returns the resulting string |
|
Capitalizes each word in the list
[hello, there] becomes [Hello, There] (list)
list - the list to capitalize Returns the resulting list |
|
Substitute characters at the middle of a string by "...".
str - is the string to modify maxlen - is the maximum length the modified string will have If the original string is shorter than "maxlen", it is returned verbatim Returns the modified string |
|
Construct QString from a c string, guessing whether it is UTF8- or
Local8Bit-encoded.
str - the input string Returns the (hopefully correctly guessed) QString representation of str See also KEncodingDetector |
|
Guess whether a string is UTF8 encoded.
str - the string to check Returns true if UTF8. If false, the string is probably in Local8Bit. |
|
Substitute characters at the beginning of a string by "...".
str - is the string to modify maxlen - is the maximum length the modified string will have If the original string is shorter than "maxlen", it is returned verbatim Returns the modified string |
|
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. str - string to be obscured Returns obscured string |
|
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" sep - is the string to use to delimit s. s - is the input string max - is the maximum number of extractions to perform, or 0. Returns A QStringList containing tokens extracted from s. |
|
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" sep - is the character to use to delimit s. s - is the input string max - is the maximum number of extractions to perform, or 0. Returns A QStringList containing tokens extracted from s. |
|
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 ?" sep - is the regular expression to use to delimit s. s - is the input string max - is the maximum number of extractions to perform, or 0. Returns A QStringList containing tokens extracted from s. |
|
Substitute characters at the end of a string by "...".
str - is the string to modify maxlen - is the maximum length the modified string will have If the original string is shorter than "maxlen", it is returned verbatim Returns the modified string |
|
This method auto-detects URLs in strings, and adds HTML markup to them
so that richtext or HTML-enabled widgets will display the URL correctly.
text - the string which may contain URLs Returns the resulting text |