#include "qstringlist.h"
#include "qregexp.h"
#include "qunicodetables_p.h"
#include <qtextcodec.h>
#include <qdatastream.h>
#include <qlist.h>
#include "qlocale.h"
#include "qlocale_p.h"
#include "qstringmatcher.h"
#include "qtools_p.h"
#include "qhash.h"
#include "qdebug.h"
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
Include dependency graph for qstring.cpp:

Go to the source code of this file.
Classes | |
| class | qt_section_chunk |
| struct | ArgEscapeData |
Defines | |
| #define | LLONG_MAX qint64_C(9223372036854775807) |
| #define | LLONG_MIN (-LLONG_MAX - qint64_C(1)) |
| #define | ULLONG_MAX quint64_C(18446744073709551615) |
| #define | REHASH(a) |
| #define | CSTR_LESS_THAN 1 |
| #define | CSTR_EQUAL 2 |
| #define | CSTR_GREATER_THAN 3 |
| #define | QT_MAX_FLOAT 3.4028234663852886e+38 |
Functions | |
| static int | ucstrcmp (const QString &as, const QString &bs) |
| static int | ucstricmp (const QString &as, const QString &bs) |
| static int | ucstrncmp (const QChar *a, const QChar *b, int l) |
| static int | ucstrnicmp (const QChar *a, const QChar *b, int l) |
| bool | qIsUpper (char ch) |
| bool | qIsDigit (char ch) |
| char | qToLower (char ch) |
| static ushort * | addOne (ushort *qch, QString &str) |
| static ArgEscapeData | findArgEscapes (const QString &s) |
| static QString | replaceArgEscapes (const QString &s, const ArgEscapeData &d, int field_width, const QString &arg, const QString &larg, const QChar &fillChar=QLatin1Char(' ')) |
| QDataStream & | operator<< (QDataStream &out, const QString &str) |
| QDataStream & | operator>> (QDataStream &in, QString &str) |
| #define CSTR_EQUAL 2 |
Definition at line 4151 of file qstring.cpp.
| #define CSTR_GREATER_THAN 3 |
| #define CSTR_LESS_THAN 1 |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.
Same as {localeAwareCompare(*this, other)}.
Definition at line 4150 of file qstring.cpp.
Referenced by QString::localeAwareCompare().
| #define LLONG_MAX qint64_C(9223372036854775807) |
Definition at line 50 of file qstring.cpp.
| #define LLONG_MIN (-LLONG_MAX - qint64_C(1)) |
Definition at line 53 of file qstring.cpp.
| #define QT_MAX_FLOAT 3.4028234663852886e+38 |
Returns the string converted to a float value.
If a conversion error occurs, *{ok} is set to false; otherwise {ok} is set to true. Returns 0.0 if the conversion fails.
Example:
snippets/qstring/main.cpp Widget::toFloatFunction() QString str1 str2.toFloat(&ok)
Definition at line 5153 of file qstring.cpp.
| #define REHASH | ( | a | ) |
Value:
if (sl_minus_1 < (int)sizeof(int) * CHAR_BIT) \ hashHaystack -= (a) << sl_minus_1; \ hashHaystack <<= 1
Definition at line 1936 of file qstring.cpp.
| #define ULLONG_MAX quint64_C(18446744073709551615) |
Definition at line 56 of file qstring.cpp.
| static ushort* addOne | ( | ushort * | qch, | |
| QString & | str | |||
| ) | [static] |
Definition at line 3328 of file qstring.cpp.
References QString::data(), QString::length(), QString::resize(), and QString::utf16().
Referenced by QString::fromUtf8().
03329 { 03330 long sidx = qch - str.utf16(); 03331 str.resize(str.length()+1); 03332 return (ushort *)str.data() + sidx; 03333 }
Here is the call graph for this function:

| static ArgEscapeData findArgEscapes | ( | const QString & | s | ) | [static] |
Definition at line 5548 of file qstring.cpp.
References c, d, Qt::escape(), and s.
Referenced by QString::arg().
05549 { 05550 const QChar *uc_begin = s.unicode(); 05551 const QChar *uc_end = uc_begin + s.length(); 05552 05553 ArgEscapeData d; 05554 05555 d.min_escape = INT_MAX; 05556 d.occurrences = 0; 05557 d.escape_len = 0; 05558 d.locale_occurrences = 0; 05559 05560 const QChar *c = uc_begin; 05561 while (c != uc_end) { 05562 while (c != uc_end && c->unicode() != '%') 05563 ++c; 05564 05565 if (c == uc_end) 05566 break; 05567 const QChar *escape_start = c; 05568 if (++c == uc_end) 05569 break; 05570 05571 bool locale_arg = false; 05572 if (c->unicode() == 'L') { 05573 locale_arg = true; 05574 if (++c == uc_end) 05575 break; 05576 } 05577 05578 if (c->digitValue() == -1) 05579 continue; 05580 05581 int escape = c->digitValue(); 05582 ++c; 05583 05584 if (c != uc_end && c->digitValue() != -1) { 05585 escape = (10 * escape) + c->digitValue(); 05586 ++c; 05587 } 05588 05589 if (escape > d.min_escape) 05590 continue; 05591 05592 if (escape < d.min_escape) { 05593 d.min_escape = escape; 05594 d.occurrences = 0; 05595 d.escape_len = 0; 05596 d.locale_occurrences = 0; 05597 } 05598 05599 ++d.occurrences; 05600 if (locale_arg) 05601 ++d.locale_occurrences; 05602 d.escape_len += c - escape_start; 05603 } 05604 return d; 05605 }
Here is the call graph for this function:

| QDataStream& operator<< | ( | QDataStream & | out, | |
| const QString & | str | |||
| ) | [related] |
Definition at line 6434 of file qstring.cpp.
06435 { 06436 if (out.version() == 1) { 06437 out << str.toLatin1(); 06438 } else { 06439 if (!str.isNull() || out.version() < 3) { 06440 int byteOrder = out.byteOrder(); 06441 const QChar* ub = str.unicode(); 06442 static const uint auto_size = 1024; 06443 char t[auto_size]; 06444 char *b; 06445 if (str.length()*sizeof(QChar) > auto_size) { 06446 b = new char[str.length()*sizeof(QChar)]; 06447 } else { 06448 b = t; 06449 } 06450 int l = str.length(); 06451 char *c=b; 06452 while (l--) { 06453 if (byteOrder == QDataStream::BigEndian) { 06454 *c++ = (char)ub->row(); 06455 *c++ = (char)ub->cell(); 06456 } else { 06457 *c++ = (char)ub->cell(); 06458 *c++ = (char)ub->row(); 06459 } 06460 ub++; 06461 } 06462 out.writeBytes(b, sizeof(QChar)*str.length()); 06463 if (str.length()*sizeof(QChar) > auto_size) 06464 delete [] b; 06465 } else { 06466 // write null marker 06467 out << (quint32)0xffffffff; 06468 } 06469 } 06470 return out; 06471 }
| QDataStream& operator>> | ( | QDataStream & | in, | |
| QString & | str | |||
| ) | [related] |
Definition at line 6482 of file qstring.cpp.
06483 { 06484 #ifdef QT_QSTRING_UCS_4 06485 #if defined(Q_CC_GNU) 06486 #warning "operator>> not working properly" 06487 #endif 06488 #endif 06489 06490 if (in.version() == 1) { 06491 QByteArray l; 06492 in >> l; 06493 str = QString::fromLatin1(l); 06494 } else { 06495 quint32 bytes = 0; 06496 in >> bytes; // read size of string 06497 if (bytes == 0xffffffff) { // null string 06498 str.clear(); 06499 } else if (bytes > 0) { // not empty 06500 if (bytes & 0x1) { 06501 str.clear(); 06502 in.setStatus(QDataStream::ReadCorruptData); 06503 return in; 06504 } 06505 06506 const quint32 Step = 1024 * 1024; 06507 quint32 len = bytes / 2; 06508 quint32 allocated = 0; 06509 06510 while (allocated < len) { 06511 int blockSize = qMin(Step, len - allocated); 06512 str.resize(allocated + blockSize); 06513 if (in.readRawData(reinterpret_cast<char *>(str.data()) + allocated * 2, 06514 blockSize * 2) != blockSize * 2) { 06515 str.clear(); 06516 in.setStatus(QDataStream::ReadPastEnd); 06517 return in; 06518 } 06519 allocated += blockSize; 06520 } 06521 06522 if ((in.byteOrder() == QDataStream::BigEndian) 06523 != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) { 06524 ushort *data = reinterpret_cast<ushort *>(str.data()); 06525 while (len--) { 06526 *data = (*data >> 8) | (*data << 8); 06527 ++data; 06528 } 06529 } 06530 } else { 06531 str = QLatin1String(""); 06532 } 06533 } 06534 return in; 06535 }
| bool qIsDigit | ( | char | ch | ) | [inline] |
| bool qIsUpper | ( | char | ch | ) | [inline] |
| char qToLower | ( | char | ch | ) | [inline] |
Definition at line 129 of file qstring.cpp.
00130 { 00131 if (ch >= 'A' && ch <= 'Z') 00132 return ch - 'A' + 'a'; 00133 else 00134 return ch; 00135 }
| static QString replaceArgEscapes | ( | const QString & | s, | |
| const ArgEscapeData & | d, | |||
| int | field_width, | |||
| const QString & | arg, | |||
| const QString & | larg, | |||
| const QChar & | fillChar = QLatin1Char(' ') | |||
| ) | [static] |
Definition at line 5607 of file qstring.cpp.
References c, d, QUnicodeTables::digitValue(), Qt::escape(), i, QString::length(), qMax(), QString::resize(), s, and QString::unicode().
Referenced by QString::arg().
05609 { 05610 const QChar *uc_begin = s.unicode(); 05611 const QChar *uc_end = uc_begin + s.length(); 05612 05613 int abs_field_width = qAbs(field_width); 05614 int result_len = s.length() 05615 - d.escape_len 05616 + (d.occurrences - d.locale_occurrences) 05617 *qMax(abs_field_width, arg.length()) 05618 + d.locale_occurrences 05619 *qMax(abs_field_width, larg.length()); 05620 05621 QString result; 05622 result.resize(result_len); 05623 QChar *result_buff = (QChar*) result.unicode(); 05624 05625 QChar *rc = result_buff; 05626 const QChar *c = uc_begin; 05627 int repl_cnt = 0; 05628 while (c != uc_end) { 05629 /* We don't have to check if we run off the end of the string with c, 05630 because as long as d.occurrences > 0 we KNOW there are valid escape 05631 sequences. */ 05632 05633 const QChar *text_start = c; 05634 05635 while (c->unicode() != '%') 05636 ++c; 05637 05638 const QChar *escape_start = c++; 05639 05640 bool locale_arg = false; 05641 if (c->unicode() == 'L') { 05642 locale_arg = true; 05643 ++c; 05644 } 05645 05646 int escape = c->digitValue(); 05647 if (escape != -1) { 05648 if (c + 1 != uc_end && (c + 1)->digitValue() != -1) { 05649 escape = (10 * escape) + (c + 1)->digitValue(); 05650 ++c; 05651 } 05652 } 05653 05654 if (escape != d.min_escape) { 05655 memcpy(rc, text_start, (c - text_start)*sizeof(QChar)); 05656 rc += c - text_start; 05657 } 05658 else { 05659 ++c; 05660 05661 memcpy(rc, text_start, (escape_start - text_start)*sizeof(QChar)); 05662 rc += escape_start - text_start; 05663 05664 uint pad_chars; 05665 if (locale_arg) 05666 pad_chars = qMax(abs_field_width, larg.length()) - larg.length(); 05667 else 05668 pad_chars = qMax(abs_field_width, arg.length()) - arg.length(); 05669 05670 if (field_width > 0) { // left padded 05671 for (uint i = 0; i < pad_chars; ++i) 05672 (rc++)->unicode() = fillChar.unicode(); 05673 } 05674 05675 if (locale_arg) { 05676 memcpy(rc, larg.unicode(), larg.length()*sizeof(QChar)); 05677 rc += larg.length(); 05678 } 05679 else { 05680 memcpy(rc, arg.unicode(), arg.length()*sizeof(QChar)); 05681 rc += arg.length(); 05682 } 05683 05684 if (field_width < 0) { // right padded 05685 for (uint i = 0; i < pad_chars; ++i) 05686 (rc++)->unicode() = fillChar.unicode(); 05687 } 05688 05689 if (++repl_cnt == d.occurrences) { 05690 memcpy(rc, c, (uc_end - c)*sizeof(QChar)); 05691 rc += uc_end - c; 05692 Q_ASSERT(rc - result_buff == result_len); 05693 c = uc_end; 05694 } 05695 } 05696 } 05697 Q_ASSERT(rc == result_buff + result_len); 05698 05699 return result; 05700 }
Here is the call graph for this function:

Definition at line 68 of file qstring.cpp.
References a, b, l, QString::length(), qMin(), and QString::unicode().
Referenced by QString::compare(), QString::localeAwareCompare(), and QString::operator<().
00069 { 00070 const QChar *a = as.unicode(); 00071 const QChar *b = bs.unicode(); 00072 if (a == b) 00073 return 0; 00074 int l = qMin(as.length(),bs.length()); 00075 while (l-- && *a == *b) 00076 a++,b++; 00077 if (l == -1) 00078 return (as.length()-bs.length()); 00079 return a->unicode() - b->unicode(); 00080 }
Here is the call graph for this function:

Definition at line 82 of file qstring.cpp.
References a, b, l, QString::length(), QUnicodeTables::lower(), qMin(), and QString::unicode().
Referenced by bestFoundry(), QFontDatabase::bold(), QString::compare(), QFontDatabasePrivate::family(), QFontDatabase::font(), QtFontFamily::foundry(), QFontDatabase::isBitmapScalable(), QFontDatabase::isSmoothlyScalable(), QFontDatabase::italic(), match(), QFontDatabase::pointSizes(), QFontDatabase::smoothSizes(), QFontDatabase::styles(), and QFontDatabase::weight().
00083 { 00084 const QChar *a = as.unicode(); 00085 const QChar *b = bs.unicode(); 00086 if (a == b) 00087 return 0; 00088 if (a == 0) 00089 return 1; 00090 if (b == 0) 00091 return -1; 00092 int l=qMin(as.length(),bs.length()); 00093 while (l-- && QUnicodeTables::lower(*a) == QUnicodeTables::lower(*b)) 00094 a++,b++; 00095 if (l==-1) 00096 return (as.length()-bs.length()); 00097 return QUnicodeTables::lower(*a).unicode() - QUnicodeTables::lower(*b).unicode(); 00098 }
Here is the call graph for this function:

Definition at line 100 of file qstring.cpp.
Referenced by QString::indexOf(), and QString::lastIndexOf().
00101 { 00102 while (l-- && *a == *b) 00103 a++,b++; 00104 if (l==-1) 00105 return 0; 00106 return a->unicode() - b->unicode(); 00107 }
Definition at line 109 of file qstring.cpp.
References a, b, and QUnicodeTables::lower().
Referenced by QString::indexOf(), and QString::lastIndexOf().
00110 { 00111 while (l-- && QUnicodeTables::lower(*a) == QUnicodeTables::lower(*b)) 00112 a++,b++; 00113 if (l==-1) 00114 return 0; 00115 return QUnicodeTables::lower(*a).unicode() - QUnicodeTables::lower(*b).unicode(); 00116 }
Here is the call graph for this function:

1.5.1