The QCString class provides an abstraction of the classic C zero-terminated char array (char *).
.PP
QCString inherits QByteArray, which is defined as QMemArray<char>. Since QCString is a QMemArray, it uses explicit sharing with a reference count.
.PP
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 QString. QString provides implicit sharing, Unicode and other internationalization support, and is well optimized.
.PP
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().
.PP
This issue does not apply to QStrings since they represent characters using Unicode. </blockquote>
.PP
Performance note: The QCString methods for QRegExp searching are implemented by converting the QCString to a QString 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 QString yourself, and then searching in the QString.
.PP
See also Collection Classes, Implicitly and Explicitly Shared Classes, Text Related Classes, and Non-GUI Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QCString::QCString ()"
Constructs a null string.
.PP
See also isNull().
.SH "QCString::QCString ( int size )"
Constructs a string with room for \fIsize\fR characters, including the '\0'-terminator. Makes a null string if \fIsize\fR == 0.
.PP
If \fIsize\fR > 0, then the first and last characters in the string are initialized to '\0'. All other characters are uninitialized.
.PP
See also resize() and isNull().
.SH "QCString::QCString ( const QCString & s )"
Constructs a shallow copy \fIs\fR.
.PP
See also assign().
.SH "QCString::QCString ( const char * str )"
Constructs a string that is a deep copy of \fIstr\fR.
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.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Counts the number of overlapping occurrences of \fIrx\fR in the string.
.PP
Example:
.PP
.nf
.br
QString s = "banana and panama";
.br
QRegExp r = QRegExp( "a[nm]a", TRUE, FALSE );
.br
s.contains( r ); // 4 matches
.br
.fi
.PP
See also find() and findRev().
.PP
\fBWarning:\fR If you want to apply this function repeatedly to the same string it is more efficient to convert the string to a QString and apply the function to that.
.SH "QCString QCString::copy () const"
Returns a deep copy of this string.
.PP
See also detach().
.SH "bool QCString::fill ( char c, int len = -1 )"
Fills the string with \fIlen\fR bytes of character \fIc\fR, followed by a '\0'-terminator.
.PP
If \fIlen\fR is negative, then the current string length is used.
.PP
Returns FALSE is \fIlen\fR is nonnegative and there is not enough memory to resize the string; otherwise returns TRUE.
.SH "int QCString::find ( char c, int index = 0, bool cs = TRUE ) const"
Finds the first occurrence of the character \fIc\fR, starting at position \fIindex\fR.
.PP
The search is case sensitive if \fIcs\fR is TRUE, or case insensitive if \fIcs\fR is FALSE.
.PP
Returns the position of \fIc\fR, or -1 if \fIc\fR could not be found.
.PP
See also Note on character comparisons.
.PP
Example: network/networkprotocol/nntp.cpp.
.SH "int QCString::find ( const char * str, int index = 0, bool cs = TRUE ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Finds the first occurrence of the string \fIstr\fR, starting at position \fIindex\fR.
.PP
The search is case sensitive if \fIcs\fR is TRUE, or case insensitive if \fIcs\fR is FALSE.
.PP
Returns the position of \fIstr\fR, or -1 if \fIstr\fR could not be found.
.PP
See also Note on character comparisons.
.SH "int QCString::find ( const QRegExp & rx, int index = 0 ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Finds the first occurrence of the regular expression \fIrx\fR, starting at position \fIindex\fR.
.PP
Returns the position of the next match, or -1 if \fIrx\fR was not found.
.PP
\fBWarning:\fR If you want to apply this function repeatedly to the same string it is more efficient to convert the string to a QString and apply the function to that.
.SH "int QCString::findRev ( char c, int index = -1, bool cs = TRUE ) const"
Finds the first occurrence of the character \fIc\fR, starting at position \fIindex\fR and searching backwards.
.PP
The search is case sensitive if \fIcs\fR is TRUE, or case insensitive if \fIcs\fR is FALSE.
.PP
Returns the position of \fIc\fR, or -1 if \fIc\fR could not be found.
.PP
See also Note on character comparisons.
.SH "int QCString::findRev ( const char * str, int index = -1, bool cs = TRUE ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Finds the first occurrence of the string \fIstr\fR, starting at position \fIindex\fR and searching backwards.
.PP
The search is case sensitive if \fIcs\fR is TRUE, or case insensitive if \fIcs\fR is FALSE.
.PP
Returns the position of \fIstr\fR, or -1 if \fIstr\fR could not be found.
.PP
See also Note on character comparisons.
.SH "int QCString::findRev ( const QRegExp & rx, int index = -1 ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Finds the first occurrence of the regular expression \fIrx\fR, starting at position \fIindex\fR and searching backwards.
.PP
Returns the position of the next match (backwards), or -1 if \fIrx\fR was not found.
.PP
\fBWarning:\fR If you want to apply this function repeatedly to the same string it is more efficient to convert the string to a QString and apply the function to that.
.SH "QCString & QCString::insert ( uint index, char c )"
Inserts character \fIc\fR into the string at position \fIindex\fR and returns a reference to the string.
.PP
If \fIindex\fR is beyond the end of the string, the string is padded with spaces (ASCII 32) to length \fIindex\fR and then \fIc\fR is appended.
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 QString 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.
.PP
The valid formats for \fIf\fR are 'e', 'E', 'f', 'g' and 'G'. The formats are the same as for sprintf(); they are explained in QString::arg().
.SH "QCString & QCString::setNum ( short n )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Sets the string to the string representation of the number \fIn\fR and returns a reference to the string.
.SH "QCString & QCString::setNum ( ushort n )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Sets the string to the string representation of the number \fIn\fR and returns a reference to the string.
.SH "QCString & QCString::setNum ( int n )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Sets the string to the string representation of the number \fIn\fR and returns a reference to the string.
.SH "QCString & QCString::setNum ( uint n )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Sets the string to the string representation of the number \fIn\fR and returns a reference to the string.
.SH "QCString & QCString::setNum ( long n )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Sets the string to the string representation of the number \fIn\fR and returns a reference to the string.
.SH "QCString & QCString::setNum ( ulong n )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Sets the string to the string representation of the number \fIn\fR and returns a reference to the string.
.SH "QCString & QCString::setNum ( float n, char f = 'g', int prec = 6 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
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).