• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

KStringHandler Namespace Reference


Detailed Description

This namespace contains utility functions for handling strings.

The functions here are intended to provide an easy way to cut/slice/splice words inside sentences in whatever order desired. While the main focus of KStringHandler is words (ie characters separated by spaces/tabs), the two core functions here (split() and join()) will allow you to use any character as a separator This will make it easy to redefine what a 'word' means in the future if needed.

The function names and calling styles are based on python and mIRC's scripting support.

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.

The methods here are completely stateless. All strings are cut on the fly and returned as new qstrings/qstringlists.

Namespace for manipulating words and sentences in strings

Author:
Ian Zepp <icszepp@islc.net>
See also:
KShell


Functions

QStringList capwords (const QStringList &list)
QString capwords (const QString &text)
QString csqueeze (const QString &str, int maxlen=40)
QString from8Bit (const char *str)
bool isUtf8 (const char *str)
QString lsqueeze (const QString &str, int maxlen=40)
int naturalCompare (const QString &a, const QString &b, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
QString obscure (const QString &str)
QStringList perlSplit (const QRegExp &sep, const QString &s, int max=0)
QStringList perlSplit (const QChar &sep, const QString &s, int max=0)
QStringList perlSplit (const QString &sep, const QString &s, int max=0)
QString rsqueeze (const QString &str, int maxlen=40)
QString tagUrls (const QString &text)

Function Documentation

QStringList KStringHandler::capwords ( const QStringList &  list  ) 

Capitalizes each word in the list [hello, there] becomes [Hello, There] (list).

Parameters:
list the list to capitalize
Returns:
the resulting list

Definition at line 52 of file kstringhandler.cpp.

QString KStringHandler::capwords ( const QString &  text  ) 

Capitalizes each word in the string "hello there" becomes "Hello There" (string).

Parameters:
text the text to capitalize
Returns:
the resulting string

Definition at line 37 of file kstringhandler.cpp.

QString KStringHandler::csqueeze ( const QString &  str,
int  maxlen = 40 
)

Substitute characters at the middle of a string by "...".

Parameters:
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

Definition at line 71 of file kstringhandler.cpp.

QString KStringHandler::from8Bit ( const char *  str  ) 

Construct QString from a c string, guessing whether it is UTF8- or Local8Bit-encoded.

Parameters:
str the input string
Returns:
the (hopefully correctly guessed) QString representation of str
See also:
KEncodingDetector

Definition at line 287 of file kstringhandler.cpp.

bool KStringHandler::isUtf8 ( const char *  str  ) 

Guess whether a string is UTF8 encoded.

Parameters:
str the string to check
Returns:
true if UTF8. If false, the string is probably in Local8Bit.

Definition at line 202 of file kstringhandler.cpp.

QString KStringHandler::lsqueeze ( const QString &  str,
int  maxlen = 40 
)

Substitute characters at the beginning of a string by "...".

Parameters:
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

Definition at line 62 of file kstringhandler.cpp.

int KStringHandler::naturalCompare ( const QString &  a,
const QString &  b,
Qt::CaseSensitivity  caseSensitivity = Qt::CaseSensitive 
)

Does a natural comparing of the strings.

A negative value is returned if a is smaller than b. A positive value is returned if a is greater than b. 0 is returned if both values are equal.

Parameters:
a first string to compare
b second string to compare
caseSensitivity whether to use case sensitive compare or not
Since:
4.1

Definition at line 300 of file kstringhandler.cpp.

QString KStringHandler::obscure ( const QString &  str  ) 

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.

Parameters:
str string to be obscured
Returns:
obscured string

Definition at line 190 of file kstringhandler.cpp.

QStringList KStringHandler::perlSplit ( const QRegExp &  sep,
const QString &  s,
int  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.

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 ?"

Parameters:
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.

Definition at line 139 of file kstringhandler.cpp.

QStringList KStringHandler::perlSplit ( const QChar &  sep,
const QString &  s,
int  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.

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"

Parameters:
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.

Definition at line 114 of file kstringhandler.cpp.

QStringList KStringHandler::perlSplit ( const QString &  sep,
const QString &  s,
int  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.

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"

Parameters:
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.

Definition at line 89 of file kstringhandler.cpp.

QString KStringHandler::rsqueeze ( const QString &  str,
int  maxlen = 40 
)

Substitute characters at the end of a string by "...".

Parameters:
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

Definition at line 80 of file kstringhandler.cpp.

QString KStringHandler::tagUrls ( const QString &  text  ) 

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.

Parameters:
text the string which may contain URLs
Returns:
the resulting text

Definition at line 165 of file kstringhandler.cpp.

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal