QCString Class ReferenceThe QCString class provides an abstraction of the classic C zero-terminated char array (char *). More... All the functions in this class are reentrant when Qt is built with thread support. #include <qcstring.h> Inherits QByteArray. Public Members
Related Functions
Detailed DescriptionThe QCString class provides an abstraction of the classic C zero-terminated char array (char *).
QCString inherits QByteArray, which is defined as QMemArray<char>. Since QCString is a QMemArray, it uses explicit sharing with a reference count. QCString tries to behave like a more convenient const char *. 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. Note that for the QCString methods that take a const char * parameter the const char * must either be 0 (null) or not-null and '\0' (NUL byte) terminated; otherwise the results are undefined. A QCString that has not been assigned to anything is null, i.e. both the length and the 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 produces a null QCString. 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(). 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(). 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. 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(). Many operators are overloaded to work with QCStrings. QCString also supports some more obscure functions, e.g. sprintf(), setStr() and setExpand(). Note on Character Comparisons
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 $LC_CTYPE is
set, most Unix systems do "the right thing".) Functions that this
affects include contains(), find(), findRev(), operator<(), operator<=(), operator>(), operator>=(), lower() and
upper().
This issue does not apply to QStrings since they represent
characters using Unicode.
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.
See also Collection Classes, Implicitly and Explicitly Shared Classes, Text Related Classes, and Non-GUI Classes.
Constructs a null string.
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().
Constructs a shallow copy s.
See also assign().
If str is 0 a null string is created.
See also isNull().
Example:
If str contains a 0 byte within the first maxsize bytes, the
resulting QCString will be terminated by this 0. If str is 0 a
null string is created.
See also isNull().
Appends string str to the string and returns a reference to the
string. Equivalent to operator+=().
The match is case sensitive if cs is TRUE, or case insensitive
if cs if FALSE.
See also Note on character comparisons.
Returns the number of times str occurs in the string.
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() and Note on character comparisons.
Counts the number of overlapping occurrences of rx in the string.
Example:
See also find() and findRev().
Warning: 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 deep copy of this string.
See also detach().
If len is negative, then the current string length is used.
Returns FALSE is len is nonnegative and there is not enough
memory to resize the string; otherwise returns TRUE.
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.
See also Note on character comparisons.
Example: network/networkprotocol/nntp.cpp.
Finds the first occurrence of the string str, starting at
position index.
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.
See also Note on character comparisons.
Finds the first occurrence of the regular expression rx,
starting at position index.
Returns the position of the next match, or -1 if rx was not
found.
Warning: 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.
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.
See also Note on character comparisons.
Finds the first occurrence of the string str, starting at
position index and searching backwards.
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.
See also Note on character comparisons.
Finds the first occurrence of the regular expression rx,
starting at position index and searching backwards.
Returns the position of the next match (backwards), or -1 if rx
was not found.
Warning: 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.
If index is beyond the end of the string, the string is
padded with spaces (ASCII 32) to length index and then c
is appended.
Example:
See also remove() and replace().
Inserts string s into the string at position index.
If index is beyond the end of the string, the string is
padded with spaces (ASCII 32) to length index and then s
is appended.
Returns TRUE if the string is empty, i.e. if length() == 0;
otherwise returns FALSE. An empty string is not always a null
string.
See example in isNull().
See also isNull(), length(), and size().
Returns TRUE if the string is null, i.e. if data() == 0; otherwise
returns FALSE. A null string is also an empty string.
Example:
See also isEmpty(), length(), and size().
The whole string is returned if len exceeds the length of the
string.
Example:
Example: network/networkprotocol/nntp.cpp.
If the length of the string exceeds width and truncate is
FALSE (the default), 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:
See also rightJustify().
Returns the length of the string, excluding the '\0'-terminator.
Equivalent to calling strlen(data()).
Null strings and empty strings have zero length.
See also size(), isNull(), and isEmpty().
Example: network/networkprotocol/nntp.cpp.
Example:
See also upper() and Note on character comparisons.
Returns a null string if the string is empty or if index is out
of range. Returns the whole string from index if index+len
exceeds the length of the string.
Example:
Example: network/networkprotocol/nntp.cpp.
Returns the string data.
Appends character c to the string and returns a reference to the string.
Assigns a shallow copy of s to this string and returns a
reference to this string.
Assigns a deep copy of str to this string and returns a
reference to this string.
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 out of range, nothing happens. If index is
valid, but index + len is larger than the length of the
string, the string is truncated at position index.
See also insert() and replace().
Example: network/networkprotocol/nntp.cpp.
If index is out of range, nothing is removed and str is
appended at the end of the string. If index is valid, but index + len is larger than the length of the string, str
replaces the rest of the string from position index.
See also insert() and remove().
Replaces every occurrence of rx in the string with str.
Returns a reference to the string.
Example:
Warning: 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.
Replaces every occurrence of the character c in the string
with after. Returns a reference to the string.
Example:
Replaces every occurrence of the string before in the string
with the string after. Returns a reference to the string.
Example:
Replaces every occurrence of c1 with the char c2.
Returns a reference to the string.
A '\0'-terminator is set at position len - 1 unless
len == 0.
Example:
See also truncate().
Example: network/networkprotocol/nntp.cpp.
The whole string is returned if len exceeds the length of the
string.
Example:
Example: network/networkprotocol/nntp.cpp.
If the length of the string exceeds width and truncate is
FALSE (the default), 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:
See also leftJustify().
Returns FALSE if index was out of range and the string could
not be expanded; otherwise returns TRUE.
The format of the string representation is specified by the format
character f, and the precision (number of digits after the
decimal point) is specified with prec.
The valid formats for f are 'e', 'E', 'f', 'g' and 'G'. The
formats are the same as for sprintf(); they are explained in QString::arg().
Sets the string to the string representation of the number n
and returns a reference to the string.
Sets the string to the string representation of the number n
and returns a reference to the string.
Sets the string to the string representation of the number n
and returns a reference to the string.
Sets the string to the string representation of the number n
and returns a reference to the string.
Sets the string to the string representation of the number n
and returns a reference to the string.
Sets the string to the string representation of the number n
and returns a reference to the string.
White space means the decimal ASCII codes 9, 10, 11, 12, 13 and
32.
See also stripWhiteSpace().
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.
Example:
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 risky: Sooner or
later someone will paste a huge line into your application.
White space means the decimal ASCII codes 9, 10, 11, 12, 13 and
32.
Example:
See also simplifyWhiteSpace().
If ok is not 0: *ok is set to FALSE if the string is not a
number, or if it has trailing garbage; otherwise *ok is set to
TRUE.
If ok is not 0: *ok is set to FALSE if the string is not a
number, or if it has trailing garbage; otherwise *ok is set to
TRUE.
If ok is not 0: *ok is set to FALSE if the string is not a
number, or if it has trailing garbage; otherwise *ok is set to
TRUE.
If ok is not 0: *ok is set to FALSE if the string is not a
number, or if it has trailing garbage; otherwise *ok is set to
TRUE.
If ok is not 0: *ok is set to FALSE if the string is not a
number, is out of range, or if it has trailing garbage; otherwise
*ok is set to TRUE.
If ok is not 0: *ok is set to FALSE if the string is not a
number, or if it has trailing garbage; otherwise *ok is set to
TRUE.
If ok is not 0: *ok is set to FALSE if the string is not a
number, or if it has trailing garbage; otherwise *ok is set to
TRUE.
If ok is not 0: *ok is set to FALSE if the string is not a
number, is out of range, or if it has trailing garbage; otherwise
*ok is set to TRUE.
Truncates the string at position pos.
Equivalent to calling resize(pos+1).
Example:
See also resize().
Example:
See also lower() and Note on character comparisons.
Returns TRUE if s1 and s2 are different; otherwise returns FALSE.
Equivalent to qstrcmp(s1, s2) != 0.
Returns TRUE if s1 and s2 are different; otherwise returns FALSE.
Equivalent to qstrcmp(s1, s2) != 0.
Returns TRUE if s1 and s2 are different; otherwise returns FALSE.
Equivalent to qstrcmp(s1, s2) != 0.
Returns a string which consists of the concatenation of s1 and
s2.
Returns a string which consists of the concatenation of s1 and s2.
Returns a string which consists of the concatenation of s1 and s2.
Returns a string which consists of the concatenation of s and c.
Returns a string which consists of the concatenation of c and s.
Returns TRUE if s1 is less than s2; otherwise returns FALSE.
Equivalent to qstrcmp(s1, s2) < 0.
See also Note on character comparisons.
Returns TRUE if s1 is less than s2; otherwise returns FALSE.
Equivalent to qstrcmp(s1, s2) < 0.
See also Note on character comparisons.
Writes string str to the stream s.
See also Format of the QDataStream operators.
Returns TRUE if s1 is less than or equal to s2; otherwise
returns FALSE.
Equivalent to qstrcmp(s1, s2) <= 0.
See also Note on character comparisons.
Returns TRUE if s1 is less than or equal to s2; otherwise
returns FALSE.
Equivalent to qstrcmp(s1, s2) <= 0.
See also Note on character comparisons.
Returns TRUE if s1 and s2 are equal; otherwise returns FALSE.
Equivalent to qstrcmp(s1, s2) == 0.
Returns TRUE if s1 and s2 are equal; otherwise returns FALSE.
Equivalent to qstrcmp(s1, s2) == 0.
Returns TRUE if s1 and s2 are equal; otherwise returns FALSE.
Equivalent to qstrcmp(s1, s2) == 0.
Returns TRUE if s1 is greater than s2; otherwise returns FALSE.
Equivalent to qstrcmp(s1, s2) > 0.
See also Note on character comparisons.
Returns TRUE if s1 is greater than s2; otherwise returns FALSE.
Equivalent to qstrcmp(s1, s2) > 0.
See also Note on character comparisons.
Returns TRUE if s1 is greater than or equal to s2; otherwise
returns FALSE.
Equivalent to qstrcmp(s1, s2) >= 0.
See also Note on character comparisons.
Returns TRUE if s1 is greater than or equal to s2; otherwise
returns FALSE.
Equivalent to qstrcmp(s1, s2) >= 0.
See also Note on character comparisons.
Reads a string into str from the stream s.
See also Format of the QDataStream operators.
This function is normally part of the C library. Qt implements
memmove() for platforms that do not provide it.
memmove() copies len bytes from src into dst. The data
is copied correctly even if src and dst overlap.
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 0.
Special case II: Returns a random nonzero value if str1 is 0
or str2 is 0 (but not both).
See also qstrncmp(), qstricmp(), qstrnicmp(), and Note on character comparisons.
A safe strcpy() function.
Copies all characters up to and including the '\0' from src
into dst and returns a pointer to dst.
Returns a duplicate string.
Allocates space for a copy of src, copies it, and returns a
pointer to the copy. If src is 0, it immediately returns 0.
The returned string must be deleted using delete[].
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 0.
Special case II: Returns a random nonzero value if str1 is 0
or str2 is 0 (but not both).
See also qstrcmp(), qstrncmp(), qstrnicmp(), and Note on character comparisons.
A safe strlen function.
Returns the number of characters that precede the terminating '\0'.
or 0 if str is 0.
A safe strncmp() function.
Compares at most len bytes of 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 0.
Special case II: Returns a random nonzero value if str1 is 0
or str2 is 0 (but not both).
See also qstrcmp(), qstricmp(), qstrnicmp(), and Note on character comparisons.
A safe strncpy() function.
Copies at most len bytes from src (stopping at len or the
terminating '\0' whichever comes first) into dst and returns a
pointer to dst. Guarantees that dst is '\0'-terminated. If
src or dst is 0, returns 0 immediately.
See also qstrcpy().
A safe strnicmp() function.
Compares at most len bytes of 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 0.
Special case II: Returns a random nonzero value if str1 is 0
or str2 is 0 (but not both).
See also qstrcmp(), qstrncmp(), qstricmp(), and Note on character comparisons.
This file is part of the Qt toolkit.
Copyright © 1995-2003
Trolltech. All Rights Reserved. |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 3.2 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com