Qtopia Home - Classes - Hierachy - Annotated - Functions - Licenses - Reference |
|
The QCString class provides an abstraction of the classic C zero-terminated char array (char*). More...
#include <qcstring.h>
The QCString class provides an abstraction of the classic C zero-terminated char array (char*).
QCString inherits QByteArray, which is defined as QArray<char>.
Since QCString is a QArray, it uses explicit sharing with a reference count.
You might use QCString for text that is never exposed to the user, but for text the user sees, you should use QString (which provides implicit sharing, Unicode and other internationalization support).
Note that QCString is one of the weaker classes in Qt; its design is flawed (it tries to behave like a more convenient const char *) and as a result, algorithms that use QCString heavily all too often perform badly. For example, append() is O(length()) since it scans for a null terminator, which makes many algorithms that use QCString scale even worse.
Note that for the QCString methods that take a const char * parameter the results are undefined if the QCString is not zero-terminated. It is legal for the const char * parameter to be 0.
A QCString that has not been assigned to anything is null, i.e. both the length and data pointer is 0. A QCString that references the empty string ("", a single '\0' char) is empty. Both null and empty QCStrings are legal parameters to the methods. Assigning const char * 0 to QCString gives a null QCString.
See also Shared classes.
See also isNull().
If size > 0, then the first and last characters in the string are initialized to '\0'. All other characters are uninitialized.
See also resize() and isNull().
See also assign().
If str is 0 a null string is created.
See also isNull().
Example:
QCString str( "helloworld", 6 ); // Assigns "hello" to str.
If str contains a 0 byte within the first maxsize bytes, the resulting QCString will be terminated by the 0. If str is 0 a null string is created.
See also isNull().
The match is case sensitive if cs is TRUE, or case insensitive if cs if FALSE.
The match is case sensitive if cs is TRUE, or case insensitive if cs if FALSE.
This function counts overlapping substrings, for example, "banana" contains two occurrences of "ana".
See also findRev().
Example:
QString s = "banana and panama";
QRegExp r = QRegExp("a[nm]a", TRUE, FALSE);
s.contains( r ); // 4 matches
See also find() and findRev().
See also detach().
If len is negative, then the current string length is used.
Returns FALSE is len is nonnegative and there is no memory to resize the string, otherwise TRUE is returned.
The search is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.
Returns the position of c, or -1 if c could not be found.
The search is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.
Returns the position of str, or -1 if str could not be found.
Returns the position of the next match, or -1 if rx was not found.
The search is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.
Returns the position of c, or -1 if c could not be found.
The search is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.
Returns the position of str, or -1 if str could not be found.
The search will start from the end of the string if index is negative.
Returns the position of the next match (backwards), or -1 if rx was not found.
If index is beyond the end of the string, the string is extended with spaces (ASCII 32) to length index and s is then appended.
QCString s = "I like fish";
s.insert( 2, "don't "); // s == "I don't like fish"
s = "x";
s.insert( 3, "yz" ); // s == "x yz"
If index is beyond the end of the string, the string is extended with spaces (ASCII 32) to length index and c is then appended.
Example:
QCString s = "Yes";
s.insert( 3, '!'); // s == "Yes!"
See also remove() and replace().
Returns TRUE if the string is empty, i.e. if length() == 0. An empty string is not always a null string.
See example in isNull().
See also isNull(), length(), and size().
Example:
QCString a; // a.data() == 0, a.size() == 0, a.length() == 0
QCString b == ""; // b.data() == "", b.size() == 1, b.length() == 0
a.isNull(); // TRUE, because a.data() == 0
a.isEmpty(); // TRUE, because a.length() == 0
b.isNull(); // FALSE, because b.data() == ""
b.isEmpty(); // TRUE, because b.length() == 0
See also isEmpty(), length(), and size().
The whole string is returned if len exceeds the length of the string.
Example:
QCString s = "Pineapple";
QCString t = s.left( 4 ); // t == "Pine"
If the length of the string exceeds width and truncate is FALSE, then the returned string is a copy of the string. If the length of the string exceeds width and truncate is TRUE, then the returned string is a left(width).
Example:
QCString s("apple");
QCString t = s.leftJustify(8, '.'); // t == "apple..."
See also rightJustify().
Null strings and empty strings have zero length.
See also size(), isNull(), and isEmpty().
Presently it only handles 7-bit ASCII, or whatever tolower() handles (if $LC_CTYPE is set, most UNIX systems do the Right Thing).
Example:
QCString s("TeX");
QCString t = s.lower(); // t == "tex"
See also upper().
Returns a null string if the string is empty or index is out of range. Returns the whole string from index if index+len exceeds the length of the string.
Example:
QCString s = "Two pineapples";
QCString t = s.mid( 4, 4 ); // t == "pine"
If str is 0 a null string is created.
See also isNull().
Prepend s to the string. Equivalent to insert(0,s).
See also insert().
If index is too big, nothing happens. If index is valid, but len is too large, the rest of the string is removed.
QCString s = "Montreal";
s.remove( 1, 4 );
// s == "Meal"
See also insert() and replace().
If index is too big, nothing is deleted and s is inserted at the end of the string. If index is valid, but len is too large, str replaces the rest of the string.
QCString s = "Say yes!";
s.replace( 4, 3, "NO" ); // s == "Say NO!"
See also insert() and remove().
Example:
QString s = "banana";
s.replace( QRegExp("a.*a"), "" ); // becomes "b"
QString s = "banana";
s.replace( QRegExp("^[bn]a"), " " ); // becomes " nana"
QString s = "banana";
s.replace( QRegExp("^[bn]a"), "" ); // NOTE! becomes ""
A \0-terminator is set at position len - 1 unless
len == 0.
Example:
QCString s = "resize this string";
s.resize( 7 ); // s == "resize"
See also truncate().
The whole string is returned if len exceeds the length of the string.
Example:
QCString s = "Pineapple";
QCString t = s.right( 5 ); // t == "apple"
If the length of the string exceeds width and truncate is FALSE, then the returned string is a copy of the string. If the length of the string exceeds width and truncate is TRUE, then the returned string is a left(width).
Example:
QCString s("pie");
QCString t = s.rightJustify(8, '.'); // t == ".....pie"
See also leftJustify().
Returns FALSE if this index was out of range and the string could not be expanded, otherwise TRUE.
\arg f is the format specifier: 'f', 'F', 'e', 'E', 'g', 'G' (same as sprintf()). \arg prec is the precision.
Returns a reference to the string.
\arg f is the format specifier: 'f', 'F', 'e', 'E', 'g', 'G' (same as sprintf()). \arg prec is the precision.
Returns a reference to the string.
White space means any ASCII code 9, 10, 11, 12, 13 or 32.
QCString s = " lots\t of\nwhite space ";
QCString t = s.simplifyWhiteSpace(); // t == "lots of white space"
See also stripWhiteSpace().
If your string is shorter than 256 characters, this sprintf() calls resize(256) to decrease the chance of memory corruption. The string is resized back to its natural length before sprintf() returns.
Example:
QCString s;
s.sprintf( "%d - %s", 1, "first" ); // result < 256 chars
QCString big( 25000 ); // very long string
big.sprintf( "%d - %s", 2, longString ); // result < 25000 chars
Warning: All vsprintf() implementations will write past the end of the target string (*this) if the format specification and arguments happen to be longer than the target string, and some will also fail if the target string is longer than some arbitrary implementation limit.
Giving user-supplied arguments to sprintf() is begging for trouble. Sooner or later someone will paste a 3000-character line into your application.
White space means any ASCII code 9, 10, 11, 12, 13 or 32.
Example:
QCString s = " space ";
QCString t = s.stripWhiteSpace(); // t == "space"
See also simplifyWhiteSpace().
double value.
If ok is nonnull, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
float value.
If ok is nonnull, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
int value.
If ok is nonnull, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
long value.
If ok is nonnull, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
short value.
If ok is nonnull, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
unsigned int value.
If ok is nonnull, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
unsigned long
value.
If ok is nonnull, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
unsigned short value.
If ok is nonnull, *ok is set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Equivalent to calling resize(pos+1).
Example:
QCString s = "truncate this string";
s.truncate( 5 ); // s == "trunc"
See also resize().
Presently it only handles 7-bit ASCII, or whatever toupper() handles (if $LC_CTYPE is set, most UNIX systems do the Right Thing).
Example:
QCString s("TeX");
QCString t = s.upper(); // t == "TEX"
See also lower().
This function is normally part of the C library. Qt implements memmove() for platforms that do not have it.
memmove() copies len bytes from src into dst. The data is copied correctly even if src and dst overlap.
Equivalent to qstrcmp(s1,s2) != 0.
Equivalent to qstrcmp(s1,s2) != 0.
Equivalent to qstrcmp(s1,s2) != 0.
Equivalent to qstrcmp(s1,s2) < 0.
Equivalent to qstrcmp(s1,s2) < 0.
See also Format of the QDataStream operators.
Equivalent to qstrcmp(s1,s2) <= 0.
Equivalent to qstrcmp(s1,s2) <= 0.
Equivalent to qstrcmp(s1,s2) == 0.
Equivalent to qstrcmp(s1,s2) == 0.
Equivalent to qstrcmp(s1,s2) == 0.
Equivalent to qstrcmp(s1,s2) > 0.
Equivalent to qstrcmp(s1,s2) > 0.
Equivalent to qstrcmp(s1,s2) >= 0.
Equivalent to qstrcmp(s1,s2) >= 0.
See also Format of the QDataStream operators.
A safe strcmp() function.
Compares str1 and str2. Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.
Special case I: Returns 0 if str1 and str2 are both null.
Special case II: Returns a random nonzero value if str1 is null or str2 is null (but not both).
See also qstrncmp(), qstricmp(), and qstrnicmp().
Returns a duplicate string.
Allocates space for a copy of str (using new), copies it, and returns a pointer to the copy. If src is null, it immediately returns 0.
A safe stricmp() function.
Compares str1 and str2 ignoring the case.
Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.
Special case I: Returns 0 if str1 and str2 are both null.
Special case II: Returns a random nonzero value if str1 is null or str2 is null (but not both).
See also qstrcmp(), qstrncmp(), and qstrnicmp().
A safe strncmp() function.
Compares str1 and str2 up to len bytes.
Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.
Special case I: Returns 0 if str1 and str2 are both null.
Special case II: Returns a random nonzero value if str1 is null or str2 is null (but not both).
See also qstrcmp(), qstricmp(), and qstrnicmp().
A safe strncpy() function.
Copies all characters up to len bytes from str into dst and returns a pointer to dst. Guarantees that dst is \0-terminated. If src is null, it immediately returns 0.
See also qstrcpy().
A safe strnicmp() function.
Compares str1 and str2 up to len bytes ignoring the case.
Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.
Special case I: Returns 0 if str1 and str2 are both null.
Special case II: Returns a random nonzero value if str1 is null or str2 is null (but not both).
See also qstrcmp(), qstrncmp(), and qstricmp().
This file is part of the Qtopia platform, copyright © 1995-2005 Trolltech, all rights reserved.
| Copyright © 2005 Trolltech | Trademarks | Qtopia version 2.2.0
|