QCString tries to behave like a more convenient \fCconst char *\fR. The price of doing this is that some algorithms will perform badly. For example, append() is O(length()) since it scans for a null terminator. Although you might use QCString for text that is never exposed to the user, for most purposes, and especially for user-visible text, you should use TQString. TQString provides implicit sharing, Unicode and other internationalization support, and is well optimized.
Note that for the QCString methods that take a \fCconst char *\fR parameter the \fCconst char *\fR must either be 0 (null) or not-null and '\0' (NUL byte) terminated; otherwise the results are undefined.
.PP
A QCString that has not been assigned to anything is \fInull\fR, i.e. both the length and the data pointer is 0. A QCString that references the empty string ("", a single '\0' char) is \fIempty\fR. Both null and empty QCStrings are legal parameters to the methods. Assigning \fCconst char *\fR 0 to QCString produces a null QCString.
.PP
The length() function returns the length of the string; resize() resizes the string and truncate() truncates the string. A string can be filled with a character using fill(). Strings can be left or right padded with characters using leftJustify() and rightJustify(). Characters, strings and regular expressions can be searched for using find() and findRev(), and counted using contains().
.PP
Strings and characters can be inserted with insert() and appended with append(). A string can be prepended with prepend(). Characters can be removed from the string with remove() and replaced with replace().
.PP
Portions of a string can be extracted using left(), right() and mid(). Whitespace can be removed using stripWhiteSpace() and simplifyWhiteSpace(). Strings can be converted to uppercase or lowercase with upper() and lower() respectively.
.PP
Strings that contain numbers can be converted to numbers with toShort(), toInt(), toLong(), toULong(), toFloat() and toDouble(). Numbers can be converted to strings with setNum().
.PP
Many operators are overloaded to work with QCStrings. QCString also supports some more obscure functions, e.g. sprintf(), setStr() and setExpand().
.PP
<blockquote><p align="center">\fB Note on Character Comparisons \fR
.PP
In QCString the notion of uppercase and lowercase and of which character is greater than or less than another character is locale dependent. This affects functions which support a case insensitive option or which compare or lowercase or uppercase their arguments. Case insensitive operations and comparisons will be accurate if both strings contain only ASCII characters. (If \fC$LC_CTYPE\fR is set, most Unix systems do "the right thing".) Functions that this affects include contains(), find(), findRev(), operator<(), operator<=(), operator>(), operator>=(), lower() and upper().
Performance note: The QCString methods for QRegExp searching are implemented by converting the QCString to a TQString and performing the search on that. This implies a deep copy of the QCString data. If you are going to perform many QRegExp searches on a large QCString, you will get better performance by converting the QCString to a TQString yourself, and then searching in the TQString.
Constructs a string that is a deep copy of \fIstr\fR. The copy will be at most \fImaxsize\fR bytes long including the '\0'-terminator.
.PP
Example:
.PP
.nf
.br
QCString str( "helloworld", 6 ); // assigns "hello" to str
.br
.fi
.PP
If \fIstr\fR contains a 0 byte within the first \fImaxsize\fR bytes, the resulting QCString will be terminated by this 0. If \fIstr\fR is 0 a null string is created.
\fBWarning:\fR If you want to apply this function repeatedly to the same string it is more efficient to convert the string to a TQString and apply the function to that.
\fBWarning:\fR If you want to apply this function repeatedly to the same string it is more efficient to convert the string to a TQString and apply the function to that.
\fBWarning:\fR If you want to apply this function repeatedly to the same string it is more efficient to convert the string to a TQString and apply the function to that.
Returns a string of length \fIwidth\fR (plus one for the terminating '\0') that contains this string padded with the \fIfill\fR character.
.PP
If the length of the string exceeds \fIwidth\fR and \fItruncate\fR is FALSE (the default), then the returned string is a copy of the string. If the length of the string exceeds \fIwidth\fR and \fItruncate\fR is TRUE, then the returned string is a left(\fIwidth\fR).
.PP
Example:
.PP
.nf
.br
QCString s("apple");
.br
QCString t = s.leftJustify(8, '.'); // t == "apple..."
.br
.fi
.PP
See also rightJustify().
.SH "uint QCString::length () const"
Returns the length of the string, excluding the '\0'-terminator. Equivalent to calling \fCstrlen(data())\fR.
.PP
Null strings and empty strings have zero length.
.PP
See also size(), isNull(), and isEmpty().
.PP
Example: network/networkprotocol/nntp.cpp.
.SH "QCString QCString::lower () const"
Returns a new string that is a copy of this string converted to lower case.
.PP
Example:
.PP
.nf
.br
QCString s("Credit");
.br
QCString t = s.lower(); // t == "credit"
.br
.fi
.PP
See also upper() and Note on character comparisons.
Returns a substring that contains at most \fIlen\fR characters from this string, starting at position \fIindex\fR.
.PP
Returns a null string if the string is empty or if \fIindex\fR is out of range. Returns the whole string from \fIindex\fR if \fIindex+len\fR exceeds the length of the string.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Assigns a deep copy of \fIstr\fR to this string and returns a reference to this string.
.PP
If \fIstr\fR is 0 a null string is created.
.PP
See also isNull().
.SH "QCString & QCString::prepend ( const char * s )"
Prepend \fIs\fR to the string. Equivalent to insert(0, s).
.PP
See also insert().
.SH "QCString & QCString::remove ( uint index, uint len )"
Removes \fIlen\fR characters from the string, starting at position \fIindex\fR, and returns a reference to the string.
.PP
If \fIindex\fR is out of range, nothing happens. If \fIindex\fR is valid, but \fIindex\fR + \fIlen\fR is larger than the length of the string, the string is truncated at position \fIindex\fR.
Replaces \fIlen\fR characters from the string, starting at position \fIindex\fR, with \fIstr\fR, and returns a reference to the string.
.PP
If \fIindex\fR is out of range, nothing is removed and \fIstr\fR is appended at the end of the string. If \fIindex\fR is valid, but \fIindex\fR + \fIlen\fR is larger than the length of the string, \fIstr\fR replaces the rest of the string from position \fIindex\fR.
\fBWarning:\fR If you want to apply this function repeatedly to the same string it is more efficient to convert the string to a TQString and apply the function to that.
Returns a string of length \fIwidth\fR (plus one for the terminating '\0') that contains zero or more of the \fIfill\fR character followed by this string.
.PP
If the length of the string exceeds \fIwidth\fR and \fItruncate\fR is FALSE (the default), then the returned string is a copy of the string. If the length of the string exceeds \fIwidth\fR and \fItruncate\fR is TRUE, then the returned string is a left(\fIwidth\fR).
.PP
Example:
.PP
.nf
.br
QCString s("pie");
.br
QCString t = s.rightJustify(8, '.'); // t == ".....pie"
.br
.fi
.PP
See also leftJustify().
.SH "bool QCString::setExpand ( uint index, char c )"
Sets the character at position \fIindex\fR to \fIc\fR and expands the string if necessary, padding with spaces.
.PP
Returns FALSE if \fIindex\fR was out of range and the string could not be expanded; otherwise returns TRUE.
.SH "QCString & QCString::setNum ( double n, char f = 'g', int prec = 6 )"
Sets the string to the string representation of the number \fIn\fR and returns a reference to the string.
.PP
The format of the string representation is specified by the format character \fIf\fR, and the precision (number of digits after the decimal point) is specified with \fIprec\fR.
Returns a new string that has white space removed from the start and the end, plus any sequence of internal white space replaced with a single space (ASCII 32).
.PP
White space means the decimal ASCII codes 9, 10, 11, 12, 13 and 32.
.PP
.nf
.br
QCString s = " lots\\t of\\nwhite space ";
.br
QCString t = s.simplifyWhiteSpace(); // t == "lots of white space"
Implemented as a call to the native vsprintf() (see the manual for your C library).
.PP
If the 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 actual length before sprintf() returns.
\fBWarning:\fR All vsprintf() implementations will write past the end of the target string (*this) if the \fIformat\fR 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.
.PP
Giving user-supplied arguments to sprintf() is risky: Sooner or later someone will paste a huge line into your application.
.SH "QCString QCString::stripWhiteSpace () const"
Returns a new string that has white space removed from the start and the end.
.PP
White space means the decimal ASCII codes 9, 10, 11, 12, 13 and 32.
Returns the string converted to a \fCshort\fR value.
.PP
If \fIok\fR is not 0: \fI*ok\fR is set to FALSE if the string is not a number, is out of range, or if it has trailing garbage; otherwise \fI*ok\fR is set to TRUE.
Returns the string converted to an \fCunsigned short\fR value.
.PP
If \fIok\fR is not 0: \fI*ok\fR is set to FALSE if the string is not a number, is out of range, or if it has trailing garbage; otherwise \fI*ok\fR is set to TRUE.
.SH "bool QCString::truncate ( uint pos )"
Truncates the string at position \fIpos\fR.
.PP
Equivalent to calling \fCresize(pos+1)\fR.
.PP
Example:
.PP
.nf
.br
QCString s = "truncate this string";
.br
s.truncate( 5 ); // s == "trunc"
.br
.fi
.PP
See also resize().
.SH "QCString QCString::upper () const"
Returns a new string that is a copy of this string converted to upper case.
.PP
Example:
.PP
.nf
.br
QCString s( "Debit" );
.br
QCString t = s.upper(); // t == "DEBIT"
.br
.fi
.PP
See also lower() and Note on character comparisons.
Compares \fIstr1\fR and \fIstr2\fR. Returns a negative value if \fIstr1\fR is less than \fIstr2\fR, 0 if \fIstr1\fR is equal to \fIstr2\fR or a positive value if \fIstr1\fR is greater than \fIstr2\fR.
.PP
Special case I: Returns 0 if \fIstr1\fR and \fIstr2\fR are both 0.
.PP
Special case II: Returns a random nonzero value if \fIstr1\fR is 0 or \fIstr2\fR is 0 (but not both).
Compares \fIstr1\fR and \fIstr2\fR ignoring the case.
.PP
Returns a negative value if \fIstr1\fR is less than \fIstr2\fR, 0 if \fIstr1\fR is equal to \fIstr2\fR or a positive value if \fIstr1\fR is greater than \fIstr2\fR.
.PP
Special case I: Returns 0 if \fIstr1\fR and \fIstr2\fR are both 0.
.PP
Special case II: Returns a random nonzero value if \fIstr1\fR is 0 or \fIstr2\fR is 0 (but not both).
Compares at most \fIlen\fR bytes of \fIstr1\fR and \fIstr2\fR.
.PP
Returns a negative value if \fIstr1\fR is less than \fIstr2\fR, 0 if \fIstr1\fR is equal to \fIstr2\fR or a positive value if \fIstr1\fR is greater than \fIstr2\fR.
.PP
Special case I: Returns 0 if \fIstr1\fR and \fIstr2\fR are both 0.
.PP
Special case II: Returns a random nonzero value if \fIstr1\fR is 0 or \fIstr2\fR is 0 (but not both).
Copies at most \fIlen\fR bytes from \fIsrc\fR (stopping at \fIlen\fR or the terminating '\0' whichever comes first) into \fIdst\fR and returns a pointer to \fIdst\fR. Guarantees that \fIdst\fR is '\0'-terminated. If \fIsrc\fR or \fIdst\fR is 0, returns 0 immediately.
Compares at most \fIlen\fR bytes of \fIstr1\fR and \fIstr2\fR ignoring the case.
.PP
Returns a negative value if \fIstr1\fR is less than \fIstr2\fR, 0 if \fIstr1\fR is equal to \fIstr2\fR or a positive value if \fIstr1\fR is greater than \fIstr2\fR.
.PP
Special case I: Returns 0 if \fIstr1\fR and \fIstr2\fR are both 0.
.PP
Special case II: Returns a random nonzero value if \fIstr1\fR is 0 or \fIstr2\fR is 0 (but not both).