|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.kde.koala.KStringHandler
public class KStringHandler
This class contains utility functions for handling strings. This class is not a substitute for the String 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(String, String ) and remword(String, 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; String 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.
KShell
Constructor Summary | |
---|---|
|
KStringHandler()
|
protected |
KStringHandler(java.lang.Class dummy)
|
Method Summary | |
---|---|
static java.lang.String |
capwords(java.lang.String text)
Capitalizes each word in the string "hello there" becomes "Hello There" (string) |
static java.util.ArrayList |
capwords(java.lang.String[] list)
Capitalizes each word in the list [hello, there] becomes [Hello, There] (list) |
static java.lang.String |
cEmSqueeze(java.lang.String name,
org.kde.qt.QFontMetrics fontMetrics)
|
static java.lang.String |
cEmSqueeze(java.lang.String name,
org.kde.qt.QFontMetrics fontMetrics,
int maxlen)
Substitute characters in the middle of a string by "...". |
static java.lang.String |
center(java.lang.String text,
int width)
Centers a string and returns a string at least 'width' characters wide. |
static java.lang.String |
cPixelSqueeze(java.lang.String name,
org.kde.qt.QFontMetrics fontMetrics,
int maxPixels)
Substitute characters in the middle of a string by "...". |
static java.lang.String |
csqueeze(java.lang.String str)
|
static java.lang.String |
csqueeze(java.lang.String str,
int maxlen)
Substitute characters at the middle of a string by "...". |
void |
dispose()
Delete the wrapped C++ instance ahead of finalize() |
protected void |
finalize()
Deletes the wrapped C++ instance |
static java.lang.String |
from8Bit(java.lang.String str)
Construct String from a c string, guessing whether it is UTF8- or Local8Bit-encoded. |
static java.lang.String |
insword(java.lang.String text,
java.lang.String word,
int pos)
Inserts a word into the string, and returns a new string with the word included. |
boolean |
isDisposed()
Has the wrapped C++ instance been deleted? |
static boolean |
isUtf8(java.lang.String str)
Guess whether a string is UTF8 encoded. |
static java.lang.String |
lEmSqueeze(java.lang.String name,
org.kde.qt.QFontMetrics fontMetrics)
|
static java.lang.String |
lEmSqueeze(java.lang.String name,
org.kde.qt.QFontMetrics fontMetrics,
int maxlen)
Substitute characters at the beginning of a string by "...". |
static java.lang.String |
lPixelSqueeze(java.lang.String name,
org.kde.qt.QFontMetrics fontMetrics,
int maxPixels)
Substitute characters at the beginning of a string by "...". |
static java.lang.String |
lsqueeze(java.lang.String str)
|
static java.lang.String |
lsqueeze(java.lang.String str,
int maxlen)
Substitute characters at the beginning of a string by "...". |
static boolean |
matchFileName(java.lang.String filename,
java.lang.String pattern)
Match a filename. |
static java.lang.String |
obscure(java.lang.String str)
Obscure string by using a simple symmetric encryption. |
static java.util.ArrayList |
perlSplit(char sep,
java.lang.String s)
|
static java.util.ArrayList |
perlSplit(char sep,
java.lang.String s,
int max)
Split a String into an ArrayList in a similar fashion to the static ArrayList function in Qt, except you can specify a maximum number of tokens. |
static java.util.ArrayList |
perlSplit(org.kde.qt.QRegExp sep,
java.lang.String s)
|
static java.util.ArrayList |
perlSplit(org.kde.qt.QRegExp sep,
java.lang.String s,
int max)
Split a String into an ArrayList in a similar fashion to the static ArrayList function in Qt, except you can specify a maximum number of tokens. |
static java.util.ArrayList |
perlSplit(java.lang.String sep,
java.lang.String s)
|
static java.util.ArrayList |
perlSplit(java.lang.String sep,
java.lang.String s,
int max)
Split a String into an ArrayList in a similar fashion to the static ArrayList function in Qt, except you can specify a maximum number of tokens. |
static java.lang.String |
remrange(java.lang.String text,
java.lang.String range)
Removes a word or ranges of words from the string, and returns a new string. |
static java.lang.String |
rEmSqueeze(java.lang.String name,
org.kde.qt.QFontMetrics fontMetrics)
|
static java.lang.String |
rEmSqueeze(java.lang.String name,
org.kde.qt.QFontMetrics fontMetrics,
int maxlen)
Substitute characters at the end of a string by "...". |
static java.lang.String |
remword(java.lang.String text,
int pos)
Removes a word at the given index, and returns a new string. |
static java.lang.String |
remword(java.lang.String text,
java.lang.String word)
Removes a matching word from the string, and returns a new string. |
static java.lang.String |
reverse(java.lang.String text)
Reverses the order of the words in a string "hello there" becomes "there hello" (string) |
static java.util.ArrayList |
reverse(java.lang.String[] list)
Reverses the order of the words in a list [hello, there] becomes [there, hello] (list) |
static java.lang.String |
rPixelSqueeze(java.lang.String name,
org.kde.qt.QFontMetrics fontMetrics,
int maxPixels)
Substitute characters at the end of a string by "...". |
static java.lang.String |
rsqueeze(java.lang.String str)
|
static java.lang.String |
rsqueeze(java.lang.String str,
int maxlen)
Substitute characters at the end of a string by "...". |
static java.lang.String |
setword(java.lang.String text,
java.lang.String word,
int pos)
Replaces a word in the string, and returns a new string with the word included. |
static java.lang.String |
tagURLs(java.lang.String 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. |
static java.lang.String |
word(java.lang.String text,
java.lang.String range)
Returns a range of words from that string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected KStringHandler(java.lang.Class dummy)
public KStringHandler()
Method Detail |
---|
public static java.lang.String word(java.lang.String text, java.lang.String range)
text
- the string to search for the wordsrange
- the words to return (see description)
public static java.lang.String insword(java.lang.String text, java.lang.String word, int pos)
pos
words in the original
string, the new word will be appended to the end.
text
- the original textword
- the word to insertpos
- the position (in words) for the new word
public static java.lang.String setword(java.lang.String text, java.lang.String word, int pos)
pos
words in the original
string, the new word will be appended to the end.
text
- the original textword
- the word to insertpos
- the position (in words) for the new word
public static java.lang.String remrange(java.lang.String text, java.lang.String range)
text
- the original textrange
- the words to remove (see description)
public static java.lang.String remword(java.lang.String text, int pos)
text
- the original textpos
- the position (in words) of thw word to delete
public static java.lang.String remword(java.lang.String text, java.lang.String word)
text
- the original textword
- the word to remove
public static java.lang.String capwords(java.lang.String text)
text
- the text to capitalize
public static java.util.ArrayList capwords(java.lang.String[] list)
list
- the list to capitalize
public static java.lang.String reverse(java.lang.String text)
text
- the text to reverse
public static java.util.ArrayList reverse(java.lang.String[] list)
list
- the list to reverse
public static java.lang.String center(java.lang.String text, int width)
width
, the original
string is returned. It is never truncated.
text
- the text to justifywidth
- the desired width of the new string
public static java.lang.String lsqueeze(java.lang.String str, int maxlen)
str
- is the string to modifymaxlen
- is the maximum length the modified string will have
If the original string is shorter than "maxlen", it is returned verbatim
public static java.lang.String lsqueeze(java.lang.String str)
public static java.lang.String lEmSqueeze(java.lang.String name, org.kde.qt.QFontMetrics fontMetrics, int maxlen)
name
- is the string to modifyfontMetrics
- is the font metrics to use to calculate character sizesmaxlen
- is the maximum length in ems the modified string will have
If the original string is shorter than "maxlen", it is returned verbatim
public static java.lang.String lEmSqueeze(java.lang.String name, org.kde.qt.QFontMetrics fontMetrics)
public static java.lang.String lPixelSqueeze(java.lang.String name, org.kde.qt.QFontMetrics fontMetrics, int maxPixels)
name
- is the string to modifyfontMetrics
- is the font metrics to use to calculate character sizesmaxPixels
- is the maximum pixel length the modified string will have
If the original string is shorter than "maxlen", it is returned verbatim
public static java.lang.String csqueeze(java.lang.String str, int maxlen)
str
- is the string to modifymaxlen
- is the maximum length the modified string will have
If the original string is shorter than "maxlen", it is returned verbatim
public static java.lang.String csqueeze(java.lang.String str)
public static java.lang.String cEmSqueeze(java.lang.String name, org.kde.qt.QFontMetrics fontMetrics, int maxlen)
name
- is the string to modifyfontMetrics
- is the font metrics to use to calculate character sizesmaxlen
- is the maximum length in ems the modified string will have
If the original string is shorter than "maxlen", it is returned verbatim
public static java.lang.String cEmSqueeze(java.lang.String name, org.kde.qt.QFontMetrics fontMetrics)
public static java.lang.String cPixelSqueeze(java.lang.String name, org.kde.qt.QFontMetrics fontMetrics, int maxPixels)
name
- is the string to modifyfontMetrics
- is the font metrics to use to calculate character sizesmaxPixels
- is the maximum pixel length the modified string will have
If the original string is shorter than "maxlen", it is returned verbatim
public static java.lang.String rsqueeze(java.lang.String str, int maxlen)
str
- is the string to modifymaxlen
- is the maximum length the modified string will have
If the original string is shorter than "maxlen", it is returned verbatim
public static java.lang.String rsqueeze(java.lang.String str)
public static java.lang.String rEmSqueeze(java.lang.String name, org.kde.qt.QFontMetrics fontMetrics, int maxlen)
name
- is the string to modifyfontMetrics
- is the font metrics to use to calculate character sizesmaxlen
- is the maximum length in ems the modified string will have
If the original string is shorter than "maxlen", it is returned verbatim
public static java.lang.String rEmSqueeze(java.lang.String name, org.kde.qt.QFontMetrics fontMetrics)
public static java.lang.String rPixelSqueeze(java.lang.String name, org.kde.qt.QFontMetrics fontMetrics, int maxPixels)
name
- is the string to modifyfontMetrics
- is the font metrics to use to calculate character sizesmaxPixels
- is the maximum pixel length the modified string will have
If the original string is shorter than "maxlen", it is returned verbatim
public static boolean matchFileName(java.lang.String filename, java.lang.String pattern)
filename
- is the real decoded filename (or dirname
without trailing '/').pattern
- is a pattern like .txt, .tar.gz, Makefile., README, etc.
Patterns with two asterisks like "*.pk" are not supported.
public static java.util.ArrayList perlSplit(java.lang.String sep, java.lang.String s, int max)
perlSplit("__", "some__string__for__you__here", 4) ArrayList contains: "some", "string", "for", "you__here"
sep
- is the string to use to delimit s.s
- is the input stringmax
- is the maximum number of extractions to perform, or 0.
public static java.util.ArrayList perlSplit(java.lang.String sep, java.lang.String s)
public static java.util.ArrayList perlSplit(char sep, java.lang.String s, int max)
perlSplit(' ', "kparts reaches the parts other parts can't", 3) ArrayList contains: "kparts", "reaches", "the parts other parts can't"
sep
- is the character to use to delimit s.s
- is the input stringmax
- is the maximum number of extractions to perform, or 0.
public static java.util.ArrayList perlSplit(char sep, java.lang.String s)
public static java.util.ArrayList perlSplit(org.kde.qt.QRegExp sep, java.lang.String s, int max)
perlSplit(QRegExp("[! ]", "Split me up ! I'm bored ! OK ?", 3) ArrayList contains: "Split", "me", "up ! I'm bored, OK ?"
sep
- is the regular expression to use to delimit s.s
- is the input stringmax
- is the maximum number of extractions to perform, or 0.
public static java.util.ArrayList perlSplit(org.kde.qt.QRegExp sep, java.lang.String s)
public static java.lang.String tagURLs(java.lang.String text)
text
- the string which may contain URLs
public static java.lang.String obscure(java.lang.String str)
str
- string to be obscured
public static boolean isUtf8(java.lang.String str)
str
- the string to check
public static java.lang.String from8Bit(java.lang.String str)
str
- the input string
str
protected void finalize() throws java.lang.InternalError
finalize
in class java.lang.Object
java.lang.InternalError
public void dispose()
public boolean isDisposed()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |