summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qalgorithms.qdoc14
-rw-r--r--src/corelib/tools/qbytearray.cpp32
-rw-r--r--src/corelib/tools/qbytearray.h12
-rw-r--r--src/corelib/tools/qcryptographichash.cpp25
-rw-r--r--src/corelib/tools/qcryptographichash.h2
-rw-r--r--src/corelib/tools/qdatetime.cpp424
-rw-r--r--src/corelib/tools/qharfbuzz.cpp7
-rw-r--r--src/corelib/tools/qharfbuzz_p.h1
-rw-r--r--src/corelib/tools/qhash.cpp6
-rw-r--r--src/corelib/tools/qline.cpp20
-rw-r--r--src/corelib/tools/qlinkedlist.cpp6
-rw-r--r--src/corelib/tools/qlist.cpp6
-rw-r--r--src/corelib/tools/qlocale.cpp22
-rw-r--r--src/corelib/tools/qlocale.h1
-rw-r--r--src/corelib/tools/qlocale.qdoc12
-rw-r--r--src/corelib/tools/qlocale_p.h2
-rw-r--r--src/corelib/tools/qlocale_tools.cpp44
-rw-r--r--src/corelib/tools/qlocale_tools_p.h4
-rw-r--r--src/corelib/tools/qlocale_unix.cpp2
-rw-r--r--src/corelib/tools/qmap.cpp6
-rw-r--r--src/corelib/tools/qpair.h22
-rw-r--r--src/corelib/tools/qrect.cpp48
-rw-r--r--src/corelib/tools/qregexp.cpp411
-rw-r--r--src/corelib/tools/qregularexpression.cpp2134
-rw-r--r--src/corelib/tools/qregularexpression.h248
-rw-r--r--src/corelib/tools/qringbuffer_p.h2
-rw-r--r--src/corelib/tools/qscopedpointer.cpp6
-rw-r--r--src/corelib/tools/qscopedvaluerollback.h2
-rw-r--r--src/corelib/tools/qshareddata.cpp4
-rw-r--r--src/corelib/tools/qsize.cpp12
-rw-r--r--src/corelib/tools/qstring.cpp78
-rw-r--r--src/corelib/tools/qstring.h20
-rw-r--r--src/corelib/tools/qstringbuilder.h16
-rw-r--r--src/corelib/tools/qstringlist.cpp2
-rw-r--r--src/corelib/tools/qstringmatcher.h2
-rw-r--r--src/corelib/tools/qvarlengtharray.qdoc6
-rw-r--r--src/corelib/tools/qvector.cpp8
-rw-r--r--src/corelib/tools/tools.pri8
38 files changed, 3045 insertions, 632 deletions
diff --git a/src/corelib/tools/qalgorithms.qdoc b/src/corelib/tools/qalgorithms.qdoc
index a16ed8b3dc..5a4a278ad0 100644
--- a/src/corelib/tools/qalgorithms.qdoc
+++ b/src/corelib/tools/qalgorithms.qdoc
@@ -159,14 +159,14 @@
bidirectional iterator, and supports the following operations:
\table
- \row \i \c{i += n} \i advances iterator \c i by \c n positions
- \row \i \c{i -= n} \i moves iterator \c i back by \c n positions
- \row \i \c{i + n} or \c{n + i} \i returns the iterator for the item \c
+ \row \li \c{i += n} \li advances iterator \c i by \c n positions
+ \row \li \c{i -= n} \li moves iterator \c i back by \c n positions
+ \row \li \c{i + n} or \c{n + i} \li returns the iterator for the item \c
n positions ahead of iterator \c i
- \row \i \c{i - n} \i returns the iterator for the item \c n positions behind of iterator \c i
- \row \i \c{i - j} \i returns the number of items between iterators \c i and \c j
- \row \i \c{i[n]} \i same as \c{*(i + n)}
- \row \i \c{i < j} \i returns true if iterator \c j comes after iterator \c i
+ \row \li \c{i - n} \li returns the iterator for the item \c n positions behind of iterator \c i
+ \row \li \c{i - j} \li returns the number of items between iterators \c i and \c j
+ \row \li \c{i[n]} \li same as \c{*(i + n)}
+ \row \li \c{i < j} \li returns true if iterator \c j comes after iterator \c i
\endtable
QList and QVector's non-const iterator types are random access iterators.
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 0d5c0f59ba..ac936b1d0a 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -344,7 +344,7 @@ int qstrcmp(const QByteArray &str1, const QByteArray &str2)
{
int l1 = str1.length();
int l2 = str2.length();
- int ret = memcmp(str1, str2, qMin(l1, l2));
+ int ret = memcmp(str1.constData(), str2.constData(), qMin(l1, l2));
if (ret != 0)
return ret;
@@ -506,7 +506,7 @@ QByteArray qCompress(const uchar* data, int nbytes, int compressionLevel)
from this and any earlier Qt version, back to Qt 3.1 when this
feature was added.
- \bold{Note:} If you want to use this function to uncompress external
+ \b{Note:} If you want to use this function to uncompress external
data that was compressed using zlib, you first need to prepend a four
byte header to the byte array containing the data. The header must
contain the expected length (in bytes) of the uncompressed data,
@@ -996,6 +996,8 @@ QByteArray &QByteArray::operator=(const char *str)
/*! \fn QByteArray::operator const char *() const
\fn QByteArray::operator const void *() const
+ \obsolete Use constData() instead.
+
Returns a pointer to the data stored in the byte array. The
pointer can be used to access the bytes that compose the array.
The data is '\\0'-terminated. The pointer remains valid as long
@@ -2734,7 +2736,7 @@ QDataStream &operator<<(QDataStream &out, const QByteArray &ba)
out << (quint32)0xffffffff;
return out;
}
- return out.writeBytes(ba, ba.size());
+ return out.writeBytes(ba.constData(), ba.size());
}
/*! \relates QByteArray
@@ -3670,12 +3672,12 @@ QByteArray &QByteArray::setNum(qulonglong n, int base)
The format \a f can be any of the following:
\table
- \header \i Format \i Meaning
- \row \i \c e \i format as [-]9.9e[+|-]999
- \row \i \c E \i format as [-]9.9E[+|-]999
- \row \i \c f \i format as [-]9.9
- \row \i \c g \i use \c e or \c f format, whichever is the most concise
- \row \i \c G \i use \c E or \c f format, whichever is the most concise
+ \header \li Format \li Meaning
+ \row \li \c e \li format as [-]9.9e[+|-]999
+ \row \li \c E \li format as [-]9.9E[+|-]999
+ \row \li \c f \li format as [-]9.9
+ \row \li \c g \li use \c e or \c f format, whichever is the most concise
+ \row \li \c G \li use \c E or \c f format, whichever is the most concise
\endtable
With 'e', 'E', and 'f', \a prec is the number of digits after the
@@ -3799,12 +3801,12 @@ QByteArray QByteArray::number(qulonglong n, int base)
which is \c g by default, and can be any of the following:
\table
- \header \i Format \i Meaning
- \row \i \c e \i format as [-]9.9e[+|-]999
- \row \i \c E \i format as [-]9.9E[+|-]999
- \row \i \c f \i format as [-]9.9
- \row \i \c g \i use \c e or \c f format, whichever is the most concise
- \row \i \c G \i use \c E or \c f format, whichever is the most concise
+ \header \li Format \li Meaning
+ \row \li \c e \li format as [-]9.9e[+|-]999
+ \row \li \c E \li format as [-]9.9E[+|-]999
+ \row \li \c f \li format as [-]9.9
+ \row \li \c g \li use \c e or \c f format, whichever is the most concise
+ \row \li \c G \li use \c E or \c f format, whichever is the most concise
\endtable
With 'e', 'E', and 'f', \a prec is the number of digits after the
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index bd3a4a8444..e65a9201c2 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -205,8 +205,10 @@ public:
void squeeze();
#ifndef QT_NO_CAST_FROM_BYTEARRAY
- operator const char *() const;
- operator const void *() const;
+#if QT_DEPRECATED_SINCE(5, 0)
+ QT_DEPRECATED operator const char *() const { return constData(); }
+ QT_DEPRECATED operator const void *() const { return constData(); }
+#endif
#endif
char *data();
const char *data() const;
@@ -413,12 +415,6 @@ inline char QByteArray::operator[](uint i) const
inline bool QByteArray::isEmpty() const
{ return d->size == 0; }
-#ifndef QT_NO_CAST_FROM_BYTEARRAY
-inline QByteArray::operator const char *() const
-{ return d->data(); }
-inline QByteArray::operator const void *() const
-{ return d->data(); }
-#endif
inline char *QByteArray::data()
{ detach(); return d->data(); }
inline const char *QByteArray::data() const
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp
index 31a0fdc5e6..be124c94f7 100644
--- a/src/corelib/tools/qcryptographichash.cpp
+++ b/src/corelib/tools/qcryptographichash.cpp
@@ -48,14 +48,16 @@
#include "../../3rdparty/sha1/sha1.cpp"
/*
- These typedefs are needed by the RFC6234 code. Normally they would come
- from from stdint.h, but since this header is not available on all platforms
- (MSVC 2008, for example), we need to define them ourselves.
+ These #defines replace the typedefs needed by the RFC6234 code. Normally
+ the typedefs would come from from stdint.h, but since this header is not
+ available on all platforms (MSVC 2008, for example), we #define them to the
+ Qt equivalents.
*/
-typedef QT_PREPEND_NAMESPACE(quint64) uint64_t;
-typedef QT_PREPEND_NAMESPACE(quint32) uint32_t;
-typedef QT_PREPEND_NAMESPACE(quint8) uint8_t;
-typedef QT_PREPEND_NAMESPACE(qint16) int_least16_t;
+#define uint64_t QT_PREPEND_NAMESPACE(quint64)
+#define uint32_t QT_PREPEND_NAMESPACE(quint32)
+#define uint8_t QT_PREPEND_NAMESPACE(quint8)
+#define int_least16_t QT_PREPEND_NAMESPACE(qint16)
+
// Header from rfc6234 with 1 modification:
// sha1.h - commented out '#include <stdint.h>' on line 74
#include "../../3rdparty/rfc6234/sha.h"
@@ -81,16 +83,21 @@ static int SHA384_512AddLength(SHA512Context *context, unsigned int length);
// sha384-512.c - appended 'M' to the SHA224_256AddLength macro on line 304
#include "../../3rdparty/rfc6234/sha384-512.c"
+#undef uint64_t
+#undef uint32_t
+#undef uint68_t
+#undef int_least16_t
+
#include <qiodevice.h>
static inline int SHA224_256AddLength(SHA256Context *context, unsigned int length)
{
- uint32_t addTemp;
+ QT_PREPEND_NAMESPACE(quint32) addTemp;
return SHA224_256AddLengthM(context, length);
}
static inline int SHA384_512AddLength(SHA512Context *context, unsigned int length)
{
- uint64_t addTemp;
+ QT_PREPEND_NAMESPACE(quint64) addTemp;
return SHA384_512AddLengthM(context, length);
}
diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h
index 2bfc03373a..6ebe389faf 100644
--- a/src/corelib/tools/qcryptographichash.h
+++ b/src/corelib/tools/qcryptographichash.h
@@ -65,7 +65,7 @@ public:
Sha512
};
- QCryptographicHash(Algorithm method);
+ explicit QCryptographicHash(Algorithm method);
~QCryptographicHash();
void reset();
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 70efb5db22..fa5eed4f86 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -306,18 +306,18 @@ int QDate::year() const
the following convention:
\list
- \i 1 = "January"
- \i 2 = "February"
- \i 3 = "March"
- \i 4 = "April"
- \i 5 = "May"
- \i 6 = "June"
- \i 7 = "July"
- \i 8 = "August"
- \i 9 = "September"
- \i 10 = "October"
- \i 11 = "November"
- \i 12 = "December"
+ \li 1 = "January"
+ \li 2 = "February"
+ \li 3 = "March"
+ \li 4 = "April"
+ \li 5 = "May"
+ \li 6 = "June"
+ \li 7 = "July"
+ \li 8 = "August"
+ \li 9 = "September"
+ \li 10 = "October"
+ \li 11 = "November"
+ \li 12 = "December"
\endlist
Returns 0 if the date is invalid.
@@ -521,18 +521,18 @@ int QDate::weekNumber(int *yearNumber) const
The months are enumerated using the following convention:
\list
- \i 1 = "Jan"
- \i 2 = "Feb"
- \i 3 = "Mar"
- \i 4 = "Apr"
- \i 5 = "May"
- \i 6 = "Jun"
- \i 7 = "Jul"
- \i 8 = "Aug"
- \i 9 = "Sep"
- \i 10 = "Oct"
- \i 11 = "Nov"
- \i 12 = "Dec"
+ \li 1 = "Jan"
+ \li 2 = "Feb"
+ \li 3 = "Mar"
+ \li 4 = "Apr"
+ \li 5 = "May"
+ \li 6 = "Jun"
+ \li 7 = "Jul"
+ \li 8 = "Aug"
+ \li 9 = "Sep"
+ \li 10 = "Oct"
+ \li 11 = "Nov"
+ \li 12 = "Dec"
\endlist
The month names will be localized according to the system's locale
@@ -568,18 +568,18 @@ QString QDate::shortMonthName(int month, QDate::MonthNameType type)
The months are enumerated using the following convention:
\list
- \i 1 = "January"
- \i 2 = "February"
- \i 3 = "March"
- \i 4 = "April"
- \i 5 = "May"
- \i 6 = "June"
- \i 7 = "July"
- \i 8 = "August"
- \i 9 = "September"
- \i 10 = "October"
- \i 11 = "November"
- \i 12 = "December"
+ \li 1 = "January"
+ \li 2 = "February"
+ \li 3 = "March"
+ \li 4 = "April"
+ \li 5 = "May"
+ \li 6 = "June"
+ \li 7 = "July"
+ \li 8 = "August"
+ \li 9 = "September"
+ \li 10 = "October"
+ \li 11 = "November"
+ \li 12 = "December"
\endlist
The month names will be localized according to the system's locale
@@ -615,13 +615,13 @@ QString QDate::longMonthName(int month, MonthNameType type)
The days are enumerated using the following convention:
\list
- \i 1 = "Mon"
- \i 2 = "Tue"
- \i 3 = "Wed"
- \i 4 = "Thu"
- \i 5 = "Fri"
- \i 6 = "Sat"
- \i 7 = "Sun"
+ \li 1 = "Mon"
+ \li 2 = "Tue"
+ \li 3 = "Wed"
+ \li 4 = "Thu"
+ \li 5 = "Fri"
+ \li 6 = "Sat"
+ \li 7 = "Sun"
\endlist
The day names will be localized according to the system's locale
@@ -657,13 +657,13 @@ QString QDate::shortDayName(int weekday, MonthNameType type)
The days are enumerated using the following convention:
\list
- \i 1 = "Monday"
- \i 2 = "Tuesday"
- \i 3 = "Wednesday"
- \i 4 = "Thursday"
- \i 5 = "Friday"
- \i 6 = "Saturday"
- \i 7 = "Sunday"
+ \li 1 = "Monday"
+ \li 2 = "Tuesday"
+ \li 3 = "Wednesday"
+ \li 4 = "Thursday"
+ \li 5 = "Friday"
+ \li 6 = "Saturday"
+ \li 7 = "Sunday"
\endlist
The day names will be localized according to the system's locale
@@ -781,25 +781,25 @@ QString QDate::toString(Qt::DateFormat f) const
These expressions may be used:
\table
- \header \i Expression \i Output
- \row \i d \i the day as number without a leading zero (1 to 31)
- \row \i dd \i the day as number with a leading zero (01 to 31)
- \row \i ddd
- \i the abbreviated localized day name (e.g. 'Mon' to 'Sun').
+ \header \li Expression \li Output
+ \row \li d \li the day as number without a leading zero (1 to 31)
+ \row \li dd \li the day as number with a leading zero (01 to 31)
+ \row \li ddd
+ \li the abbreviated localized day name (e.g. 'Mon' to 'Sun').
Uses QDate::shortDayName().
- \row \i dddd
- \i the long localized day name (e.g. 'Monday' to 'Sunday').
+ \row \li dddd
+ \li the long localized day name (e.g. 'Monday' to 'Sunday').
Uses QDate::longDayName().
- \row \i M \i the month as number without a leading zero (1 to 12)
- \row \i MM \i the month as number with a leading zero (01 to 12)
- \row \i MMM
- \i the abbreviated localized month name (e.g. 'Jan' to 'Dec').
+ \row \li M \li the month as number without a leading zero (1 to 12)
+ \row \li MM \li the month as number with a leading zero (01 to 12)
+ \row \li MMM
+ \li the abbreviated localized month name (e.g. 'Jan' to 'Dec').
Uses QDate::shortMonthName().
- \row \i MMMM
- \i the long localized month name (e.g. 'January' to 'December').
+ \row \li MMMM
+ \li the long localized month name (e.g. 'January' to 'December').
Uses QDate::longMonthName().
- \row \i yy \i the year as two digit number (00 to 99)
- \row \i yyyy \i the year as four digit number. If the year is negative,
+ \row \li yy \li the year as two digit number (00 to 99)
+ \row \li yyyy \li the year as four digit number. If the year is negative,
a minus sign is prepended in addition.
\endtable
@@ -812,10 +812,10 @@ QString QDate::toString(Qt::DateFormat f) const
1969):
\table
- \header \o Format \o Result
- \row \o dd.MM.yyyy \o 20.07.1969
- \row \o ddd MMMM d yy \o Sun July 20 69
- \row \o 'The day is' dddd \o The day is Sunday
+ \header \li Format \li Result
+ \row \li dd.MM.yyyy \li 20.07.1969
+ \row \li ddd MMMM d yy \li Sun July 20 69
+ \row \li 'The day is' dddd \li The day is Sunday
\endtable
If the datetime is invalid, an empty string will be returned.
@@ -1191,25 +1191,25 @@ QDate QDate::fromString(const QString& s, Qt::DateFormat f)
These expressions may be used for the format:
\table
- \header \i Expression \i Output
- \row \i d \i The day as a number without a leading zero (1 to 31)
- \row \i dd \i The day as a number with a leading zero (01 to 31)
- \row \i ddd
- \i The abbreviated localized day name (e.g. 'Mon' to 'Sun').
+ \header \li Expression \li Output
+ \row \li d \li The day as a number without a leading zero (1 to 31)
+ \row \li dd \li The day as a number with a leading zero (01 to 31)
+ \row \li ddd
+ \li The abbreviated localized day name (e.g. 'Mon' to 'Sun').
Uses QDate::shortDayName().
- \row \i dddd
- \i The long localized day name (e.g. 'Monday' to 'Sunday').
+ \row \li dddd
+ \li The long localized day name (e.g. 'Monday' to 'Sunday').
Uses QDate::longDayName().
- \row \i M \i The month as a number without a leading zero (1 to 12)
- \row \i MM \i The month as a number with a leading zero (01 to 12)
- \row \i MMM
- \i The abbreviated localized month name (e.g. 'Jan' to 'Dec').
+ \row \li M \li The month as a number without a leading zero (1 to 12)
+ \row \li MM \li The month as a number with a leading zero (01 to 12)
+ \row \li MMM
+ \li The abbreviated localized month name (e.g. 'Jan' to 'Dec').
Uses QDate::shortMonthName().
- \row \i MMMM
- \i The long localized month name (e.g. 'January' to 'December').
+ \row \li MMMM
+ \li The long localized month name (e.g. 'January' to 'December').
Uses QDate::longMonthName().
- \row \i yy \i The year as two digit number (00 to 99)
- \row \i yyyy \i The year as four digit number. If the year is negative,
+ \row \li yy \li The year as two digit number (00 to 99)
+ \row \li yyyy \li The year as four digit number. If the year is negative,
a minus sign is prepended in addition.
\endtable
@@ -1233,10 +1233,10 @@ QDate QDate::fromString(const QString& s, Qt::DateFormat f)
defaults are used:
\table
- \header \i Field \i Default value
- \row \i Year \i 1900
- \row \i Month \i 1
- \row \i Day \i 1
+ \header \li Field \li Default value
+ \row \li Year \li 1900
+ \row \li Month \li 1
+ \row \li Day \li 1
\endtable
The following examples demonstrate the default values:
@@ -1543,26 +1543,26 @@ QString QTime::toString(Qt::DateFormat format) const
These expressions may be used:
\table
- \header \i Expression \i Output
- \row \i h
- \i the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
- \row \i hh
- \i the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
- \row \i H
- \i the hour without a leading zero (0 to 23, even with AM/PM display)
- \row \i HH
- \i the hour with a leading zero (00 to 23, even with AM/PM display)
- \row \i m \i the minute without a leading zero (0 to 59)
- \row \i mm \i the minute with a leading zero (00 to 59)
- \row \i s \i the second without a leading zero (0 to 59)
- \row \i ss \i the second with a leading zero (00 to 59)
- \row \i z \i the milliseconds without leading zeroes (0 to 999)
- \row \i zzz \i the milliseconds with leading zeroes (000 to 999)
- \row \i AP or A
- \i use AM/PM display. \e AP will be replaced by either "AM" or "PM".
- \row \i ap or a
- \i use am/pm display. \e ap will be replaced by either "am" or "pm".
- \row \i t \i the timezone (for example "CEST")
+ \header \li Expression \li Output
+ \row \li h
+ \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
+ \row \li hh
+ \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
+ \row \li H
+ \li the hour without a leading zero (0 to 23, even with AM/PM display)
+ \row \li HH
+ \li the hour with a leading zero (00 to 23, even with AM/PM display)
+ \row \li m \li the minute without a leading zero (0 to 59)
+ \row \li mm \li the minute with a leading zero (00 to 59)
+ \row \li s \li the second without a leading zero (0 to 59)
+ \row \li ss \li the second with a leading zero (00 to 59)
+ \row \li z \li the milliseconds without leading zeroes (0 to 999)
+ \row \li zzz \li the milliseconds with leading zeroes (000 to 999)
+ \row \li AP or A
+ \li use AM/PM display. \e AP will be replaced by either "AM" or "PM".
+ \row \li ap or a
+ \li use am/pm display. \e ap will be replaced by either "am" or "pm".
+ \row \li t \li the timezone (for example "CEST")
\endtable
All other input characters will be ignored. Any sequence of characters that
@@ -1573,10 +1573,10 @@ QString QTime::toString(Qt::DateFormat format) const
Example format strings (assuming that the QTime is 14:13:09.042)
\table
- \header \i Format \i Result
- \row \i hh:mm:ss.zzz \i 14:13:09.042
- \row \i h:m:s ap \i 2:13:9 pm
- \row \i H:m:s a \i 14:13:9 pm
+ \header \li Format \li Result
+ \row \li hh:mm:ss.zzz \li 14:13:09.042
+ \row \li h:m:s ap \li 2:13:9 pm
+ \row \li H:m:s a \li 14:13:9 pm
\endtable
If the datetime is invalid, an empty string will be returned.
@@ -1824,21 +1824,21 @@ QTime QTime::fromString(const QString& s, Qt::DateFormat f)
These expressions may be used for the format:
\table
- \header \i Expression \i Output
- \row \i h
- \i the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
- \row \i hh
- \i the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
- \row \i m \i the minute without a leading zero (0 to 59)
- \row \i mm \i the minute with a leading zero (00 to 59)
- \row \i s \i the second without a leading zero (0 to 59)
- \row \i ss \i the second with a leading zero (00 to 59)
- \row \i z \i the milliseconds without leading zeroes (0 to 999)
- \row \i zzz \i the milliseconds with leading zeroes (000 to 999)
- \row \i AP
- \i interpret as an AM/PM time. \e AP must be either "AM" or "PM".
- \row \i ap
- \i Interpret as an AM/PM time. \e ap must be either "am" or "pm".
+ \header \li Expression \li Output
+ \row \li h
+ \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
+ \row \li hh
+ \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
+ \row \li m \li the minute without a leading zero (0 to 59)
+ \row \li mm \li the minute with a leading zero (00 to 59)
+ \row \li s \li the second without a leading zero (0 to 59)
+ \row \li ss \li the second with a leading zero (00 to 59)
+ \row \li z \li the milliseconds without leading zeroes (0 to 999)
+ \row \li zzz \li the milliseconds with leading zeroes (000 to 999)
+ \row \li AP
+ \li interpret as an AM/PM time. \e AP must be either "AM" or "PM".
+ \row \li ap
+ \li Interpret as an AM/PM time. \e ap must be either "am" or "pm".
\endtable
All other input characters will be treated as text. Any sequence
@@ -2515,45 +2515,45 @@ QString QDateTime::toString(Qt::DateFormat f) const
These expressions may be used for the date:
\table
- \header \i Expression \i Output
- \row \i d \i the day as number without a leading zero (1 to 31)
- \row \i dd \i the day as number with a leading zero (01 to 31)
- \row \i ddd
- \i the abbreviated localized day name (e.g. 'Mon' to 'Sun').
+ \header \li Expression \li Output
+ \row \li d \li the day as number without a leading zero (1 to 31)
+ \row \li dd \li the day as number with a leading zero (01 to 31)
+ \row \li ddd
+ \li the abbreviated localized day name (e.g. 'Mon' to 'Sun').
Uses QDate::shortDayName().
- \row \i dddd
- \i the long localized day name (e.g. 'Monday' to 'Qt::Sunday').
+ \row \li dddd
+ \li the long localized day name (e.g. 'Monday' to 'Qt::Sunday').
Uses QDate::longDayName().
- \row \i M \i the month as number without a leading zero (1-12)
- \row \i MM \i the month as number with a leading zero (01-12)
- \row \i MMM
- \i the abbreviated localized month name (e.g. 'Jan' to 'Dec').
+ \row \li M \li the month as number without a leading zero (1-12)
+ \row \li MM \li the month as number with a leading zero (01-12)
+ \row \li MMM
+ \li the abbreviated localized month name (e.g. 'Jan' to 'Dec').
Uses QDate::shortMonthName().
- \row \i MMMM
- \i the long localized month name (e.g. 'January' to 'December').
+ \row \li MMMM
+ \li the long localized month name (e.g. 'January' to 'December').
Uses QDate::longMonthName().
- \row \i yy \i the year as two digit number (00-99)
- \row \i yyyy \i the year as four digit number
+ \row \li yy \li the year as two digit number (00-99)
+ \row \li yyyy \li the year as four digit number
\endtable
These expressions may be used for the time:
\table
- \header \i Expression \i Output
- \row \i h
- \i the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
- \row \i hh
- \i the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
- \row \i m \i the minute without a leading zero (0 to 59)
- \row \i mm \i the minute with a leading zero (00 to 59)
- \row \i s \i the second without a leading zero (0 to 59)
- \row \i ss \i the second with a leading zero (00 to 59)
- \row \i z \i the milliseconds without leading zeroes (0 to 999)
- \row \i zzz \i the milliseconds with leading zeroes (000 to 999)
- \row \i AP
- \i use AM/PM display. \e AP will be replaced by either "AM" or "PM".
- \row \i ap
- \i use am/pm display. \e ap will be replaced by either "am" or "pm".
+ \header \li Expression \li Output
+ \row \li h
+ \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
+ \row \li hh
+ \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
+ \row \li m \li the minute without a leading zero (0 to 59)
+ \row \li mm \li the minute with a leading zero (00 to 59)
+ \row \li s \li the second without a leading zero (0 to 59)
+ \row \li ss \li the second with a leading zero (00 to 59)
+ \row \li z \li the milliseconds without leading zeroes (0 to 999)
+ \row \li zzz \li the milliseconds with leading zeroes (000 to 999)
+ \row \li AP
+ \li use AM/PM display. \e AP will be replaced by either "AM" or "PM".
+ \row \li ap
+ \li use am/pm display. \e ap will be replaced by either "am" or "pm".
\endtable
All other input characters will be ignored. Any sequence of characters that
@@ -2565,11 +2565,11 @@ QString QDateTime::toString(Qt::DateFormat f) const
14:13:09):
\table
- \header \i Format \i Result
- \row \i dd.MM.yyyy \i 21.05.2001
- \row \i ddd MMMM d yy \i Tue May 21 01
- \row \i hh:mm:ss.zzz \i 14:13:09.042
- \row \i h:m:s ap \i 2:13:9 pm
+ \header \li Format \li Result
+ \row \li dd.MM.yyyy \li 21.05.2001
+ \row \li ddd MMMM d yy \li Tue May 21 01
+ \row \li hh:mm:ss.zzz \li 14:13:09.042
+ \row \li h:m:s ap \li 2:13:9 pm
\endtable
If the datetime is invalid, an empty string will be returned.
@@ -3367,25 +3367,25 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f)
These expressions may be used for the date part of the format string:
\table
- \header \i Expression \i Output
- \row \i d \i the day as number without a leading zero (1 to 31)
- \row \i dd \i the day as number with a leading zero (01 to 31)
- \row \i ddd
- \i the abbreviated localized day name (e.g. 'Mon' to 'Sun').
+ \header \li Expression \li Output
+ \row \li d \li the day as number without a leading zero (1 to 31)
+ \row \li dd \li the day as number with a leading zero (01 to 31)
+ \row \li ddd
+ \li the abbreviated localized day name (e.g. 'Mon' to 'Sun').
Uses QDate::shortDayName().
- \row \i dddd
- \i the long localized day name (e.g. 'Monday' to 'Sunday').
+ \row \li dddd
+ \li the long localized day name (e.g. 'Monday' to 'Sunday').
Uses QDate::longDayName().
- \row \i M \i the month as number without a leading zero (1-12)
- \row \i MM \i the month as number with a leading zero (01-12)
- \row \i MMM
- \i the abbreviated localized month name (e.g. 'Jan' to 'Dec').
+ \row \li M \li the month as number without a leading zero (1-12)
+ \row \li MM \li the month as number with a leading zero (01-12)
+ \row \li MMM
+ \li the abbreviated localized month name (e.g. 'Jan' to 'Dec').
Uses QDate::shortMonthName().
- \row \i MMMM
- \i the long localized month name (e.g. 'January' to 'December').
+ \row \li MMMM
+ \li the long localized month name (e.g. 'January' to 'December').
Uses QDate::longMonthName().
- \row \i yy \i the year as two digit number (00-99)
- \row \i yyyy \i the year as four digit number
+ \row \li yy \li the year as two digit number (00-99)
+ \row \li yyyy \li the year as four digit number
\endtable
\note Unlike the other version of this function, day and month names must
@@ -3395,25 +3395,25 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f)
These expressions may be used for the time part of the format string:
\table
- \header \i Expression \i Output
- \row \i h
- \i the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
- \row \i hh
- \i the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
- \row \i H
- \i the hour without a leading zero (0 to 23, even with AM/PM display)
- \row \i HH
- \i the hour with a leading zero (00 to 23, even with AM/PM display)
- \row \i m \i the minute without a leading zero (0 to 59)
- \row \i mm \i the minute with a leading zero (00 to 59)
- \row \i s \i the second without a leading zero (0 to 59)
- \row \i ss \i the second with a leading zero (00 to 59)
- \row \i z \i the milliseconds without leading zeroes (0 to 999)
- \row \i zzz \i the milliseconds with leading zeroes (000 to 999)
- \row \i AP or A
- \i interpret as an AM/PM time. \e AP must be either "AM" or "PM".
- \row \i ap or a
- \i Interpret as an AM/PM time. \e ap must be either "am" or "pm".
+ \header \li Expression \li Output
+ \row \li h
+ \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
+ \row \li hh
+ \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
+ \row \li H
+ \li the hour without a leading zero (0 to 23, even with AM/PM display)
+ \row \li HH
+ \li the hour with a leading zero (00 to 23, even with AM/PM display)
+ \row \li m \li the minute without a leading zero (0 to 59)
+ \row \li mm \li the minute with a leading zero (00 to 59)
+ \row \li s \li the second without a leading zero (0 to 59)
+ \row \li ss \li the second with a leading zero (00 to 59)
+ \row \li z \li the milliseconds without leading zeroes (0 to 999)
+ \row \li zzz \li the milliseconds with leading zeroes (000 to 999)
+ \row \li AP or A
+ \li interpret as an AM/PM time. \e AP must be either "AM" or "PM".
+ \row \li ap or a
+ \li Interpret as an AM/PM time. \e ap must be either "am" or "pm".
\endtable
All other input characters will be treated as text. Any sequence
@@ -3437,13 +3437,13 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f)
defaults are used:
\table
- \header \i Field \i Default value
- \row \i Year \i 1900
- \row \i Month \i 1 (January)
- \row \i Day \i 1
- \row \i Hour \i 0
- \row \i Minute \i 0
- \row \i Second \i 0
+ \header \li Field \li Default value
+ \row \li Year \li 1900
+ \row \li Month \li 1 (January)
+ \row \li Day \li 1
+ \row \li Hour \li 0
+ \row \li Minute \li 0
+ \row \li Second \li 0
\endtable
For example:
@@ -3511,7 +3511,10 @@ void QDateTime::detach()
QDataStream &operator<<(QDataStream &out, const QDate &date)
{
- return out << (qint64)(date.jd);
+ if (out.version() < QDataStream::Qt_5_0)
+ return out << quint32(date.jd);
+ else
+ return out << qint64(date.jd);
}
/*!
@@ -3524,9 +3527,16 @@ QDataStream &operator<<(QDataStream &out, const QDate &date)
QDataStream &operator>>(QDataStream &in, QDate &date)
{
- qint64 jd;
- in >> jd;
- date.jd = jd;
+ if (in.version() < QDataStream::Qt_5_0) {
+ quint32 jd;
+ in >> jd;
+ date.jd = jd;
+ } else {
+ qint64 jd;
+ in >> jd;
+ date.jd = jd;
+ }
+
return in;
}
diff --git a/src/corelib/tools/qharfbuzz.cpp b/src/corelib/tools/qharfbuzz.cpp
index 7d08547ab8..11126b814d 100644
--- a/src/corelib/tools/qharfbuzz.cpp
+++ b/src/corelib/tools/qharfbuzz.cpp
@@ -122,7 +122,12 @@ HB_Bool qShapeItem(HB_ShaperItem *item)
HB_Face qHBNewFace(void *font, HB_GetFontTableFunc tableFunc)
{
- return HB_NewFace(font, tableFunc);
+ return HB_AllocFace(font, tableFunc);
+}
+
+HB_Face qHBLoadFace(HB_Face face)
+{
+ return HB_LoadFace(face);
}
void qHBFreeFace(HB_Face face)
diff --git a/src/corelib/tools/qharfbuzz_p.h b/src/corelib/tools/qharfbuzz_p.h
index cc575ddffa..3cef3a55dd 100644
--- a/src/corelib/tools/qharfbuzz_p.h
+++ b/src/corelib/tools/qharfbuzz_p.h
@@ -68,6 +68,7 @@ Q_CORE_EXPORT HB_Bool qShapeItem(HB_ShaperItem *item);
// ### temporary
Q_CORE_EXPORT HB_Face qHBNewFace(void *font, HB_GetFontTableFunc tableFunc);
Q_CORE_EXPORT void qHBFreeFace(HB_Face);
+Q_CORE_EXPORT HB_Face qHBLoadFace(HB_Face face);
Q_DECLARE_TYPEINFO(HB_GlyphAttributes, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(HB_FixedPoint, Q_PRIMITIVE_TYPE);
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index e0cd068158..897de77f2e 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -547,11 +547,11 @@ void QHashData::checkSanity()
differences are:
\list
- \i QHash provides faster lookups than QMap. (See \l{Algorithmic
+ \li QHash provides faster lookups than QMap. (See \l{Algorithmic
Complexity} for details.)
- \i When iterating over a QMap, the items are always sorted by
+ \li When iterating over a QMap, the items are always sorted by
key. With QHash, the items are arbitrarily ordered.
- \i The key type of a QMap must provide operator<(). The key
+ \li The key type of a QMap must provide operator<(). The key
type of a QHash must provide operator==() and a global
hash function called qHash() (see the related non-member
functions).
diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp
index 78f1c44263..39ec0ed97c 100644
--- a/src/corelib/tools/qline.cpp
+++ b/src/corelib/tools/qline.cpp
@@ -61,8 +61,8 @@ QT_BEGIN_NAMESPACE
\table
\row
- \o \inlineimage qline-point.png
- \o \inlineimage qline-coordinates.png
+ \li \inlineimage qline-point.png
+ \li \inlineimage qline-coordinates.png
\endtable
The positions of the line's start and end points can be retrieved
@@ -322,8 +322,8 @@ QDataStream &operator>>(QDataStream &stream, QLine &line)
\table
\row
- \o \inlineimage qline-point.png
- \o \inlineimage qline-coordinates.png
+ \li \inlineimage qline-point.png
+ \li \inlineimage qline-coordinates.png
\endtable
The positions of the line's start and end points can be retrieved
@@ -360,11 +360,11 @@ QDataStream &operator>>(QDataStream &stream, QLine &line)
\table
\row
- \o \inlineimage qlinef-unbounded.png
- \o \inlineimage qlinef-bounded.png
+ \li \inlineimage qlinef-unbounded.png
+ \li \inlineimage qlinef-bounded.png
\row
- \o QLineF::UnboundedIntersection
- \o QLineF::BoundedIntersection
+ \li QLineF::UnboundedIntersection
+ \li QLineF::BoundedIntersection
\endtable
\value NoIntersection Indicates that the lines do not intersect;
@@ -795,8 +795,8 @@ qreal QLineF::angleTo(const QLineF &l) const
\table
\row
- \o \inlineimage qlinef-angle-identicaldirection.png
- \o \inlineimage qlinef-angle-oppositedirection.png
+ \li \inlineimage qlinef-angle-identicaldirection.png
+ \li \inlineimage qlinef-angle-oppositedirection.png
\endtable
When the lines are parallel, this function returns 0 if they have
diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp
index db5404e429..6e66f804c0 100644
--- a/src/corelib/tools/qlinkedlist.cpp
+++ b/src/corelib/tools/qlinkedlist.cpp
@@ -65,16 +65,16 @@ const QLinkedListData QLinkedListData::shared_null = {
functionality. Here's an overview:
\list
- \i For most purposes, QList is the right class to use. Its
+ \li For most purposes, QList is the right class to use. Its
index-based API is more convenient than QLinkedList's
iterator-based API, and it is usually faster than
QVector because of the way it stores its items in
memory (see \l{Algorithmic Complexity} for details).
It also expands to less code in your executable.
- \i If you need a real linked list, with guarantees of \l{constant
+ \li If you need a real linked list, with guarantees of \l{constant
time} insertions in the middle of the list and iterators to
items rather than indexes, use QLinkedList.
- \i If you want the items to occupy adjacent memory positions,
+ \li If you want the items to occupy adjacent memory positions,
use QVector.
\endlist
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index 1b6610a724..9ee4c0a797 100644
--- a/src/corelib/tools/qlist.cpp
+++ b/src/corelib/tools/qlist.cpp
@@ -338,15 +338,15 @@ void **QListData::erase(void **xi)
functionality. Here's an overview:
\list
- \i For most purposes, QList is the right class to use. Its
+ \li For most purposes, QList is the right class to use. Its
index-based API is more convenient than QLinkedList's
iterator-based API, and it is usually faster than
QVector because of the way it stores its items in
memory. It also expands to less code in your executable.
- \i If you need a real linked list, with guarantees of \l{constant
+ \li If you need a real linked list, with guarantees of \l{constant
time} insertions in the middle of the list and iterators to
items rather than indexes, use QLinkedList.
- \i If you want the items to occupy adjacent memory positions,
+ \li If you want the items to occupy adjacent memory positions,
use QVector.
\endlist
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 31f776dc2e..086ca7bd38 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -621,10 +621,10 @@ static quint16 localePrivateIndex(const QLocalePrivate *p)
"language[_script][_country][.codeset][@modifier]" or "C", where:
\list
- \i language is a lowercase, two-letter, ISO 639 language code,
- \i script is a titlecase, four-letter, ISO 15924 script code,
- \i country is an uppercase, two- or three-letter, ISO 3166 country code (also "419" as defined by United Nations),
- \i and codeset and modifier are ignored.
+ \li language is a lowercase, two-letter, ISO 639 language code,
+ \li script is a titlecase, four-letter, ISO 15924 script code,
+ \li country is an uppercase, two- or three-letter, ISO 3166 country code (also "419" as defined by United Nations),
+ \li and codeset and modifier are ignored.
\endlist
The separator can be either underscore or a minus sign.
@@ -671,11 +671,11 @@ QLocale::QLocale()
country.
\list
- \i If the language/country pair is found in the database, it is used.
- \i If the language is found but the country is not, or if the country
+ \li If the language/country pair is found in the database, it is used.
+ \li If the language is found but the country is not, or if the country
is \c AnyCountry, the language is used with the most
appropriate available country (for example, Germany for German),
- \i If neither the language nor the country are found, QLocale
+ \li If neither the language nor the country are found, QLocale
defaults to the default locale (see setDefault()).
\endlist
@@ -707,14 +707,14 @@ QLocale::QLocale(Language language, Country country)
\a country.
\list
- \i If the language/script/country is found in the database, it is used.
- \i If both \a script is AnyScript and \a country is AnyCountry, the
+ \li If the language/script/country is found in the database, it is used.
+ \li If both \a script is AnyScript and \a country is AnyCountry, the
language is used with the most appropriate available script and country
(for example, Germany for German),
- \i If either \a script is AnyScript or \a country is AnyCountry, the
+ \li If either \a script is AnyScript or \a country is AnyCountry, the
language is used with the first locale that matches the given \a script
and \a country.
- \i If neither the language nor the country are found, QLocale
+ \li If neither the language nor the country are found, QLocale
defaults to the default locale (see setDefault()).
\endlist
diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h
index c029f627b2..2ecd934100 100644
--- a/src/corelib/tools/qlocale.h
+++ b/src/corelib/tools/qlocale.h
@@ -42,7 +42,6 @@
#ifndef QLOCALE_H
#define QLOCALE_H
-#include <QtCore/qvariant.h>
#include <QtCore/qstring.h>
#include <QtCore/qobjectdefs.h>
diff --git a/src/corelib/tools/qlocale.qdoc b/src/corelib/tools/qlocale.qdoc
index 3a386c17d6..8e90d7d94e 100644
--- a/src/corelib/tools/qlocale.qdoc
+++ b/src/corelib/tools/qlocale.qdoc
@@ -51,12 +51,12 @@
following effects:
\list
- \i If a QLocale object is constructed with the default constructor,
+ \li If a QLocale object is constructed with the default constructor,
it will use the default locale's settings.
- \i QString::toInt(), QString::toDouble(), etc., interpret the
+ \li QString::toInt(), QString::toDouble(), etc., interpret the
string according to the default locale. If this fails, it
falls back on the "C" locale.
- \i QString::arg() uses the default locale to format a number when
+ \li QString::arg() uses the default locale to format a number when
its position specifier in the format string contains an 'L',
e.g. "%L1".
\endlist
@@ -69,11 +69,11 @@
of three things can happen:
\list
- \i If the language/country pair is found in the database, it is used.
- \i If the language is found but the country is not, or if the country
+ \li If the language/country pair is found in the database, it is used.
+ \li If the language is found but the country is not, or if the country
is \c AnyCountry, the language is used with the most
appropriate available country (for example, Germany for German),
- \i If neither the language nor the country are found, QLocale
+ \li If neither the language nor the country are found, QLocale
defaults to the default locale (see setDefault()).
\endlist
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index c6902ca206..ad7c9706c4 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -55,7 +55,7 @@
#include "QtCore/qstring.h"
#include "QtCore/qvarlengtharray.h"
-#include "QtCore/qmetatype.h"
+#include "QtCore/qvariant.h"
#include "qlocale.h"
diff --git a/src/corelib/tools/qlocale_tools.cpp b/src/corelib/tools/qlocale_tools.cpp
index 31a29d7fe1..2d6b8047a6 100644
--- a/src/corelib/tools/qlocale_tools.cpp
+++ b/src/corelib/tools/qlocale_tools.cpp
@@ -601,7 +601,7 @@ QT_END_INCLUDE_NAMESPACE
#error Exactly one of IEEE_BIG_OR_LITTLE_ENDIAN, VAX, or IBM should be defined.
#endif
-static inline ULong _getWord0(const NEEDS_VOLATILE double x)
+static inline ULong getWord0(const NEEDS_VOLATILE double x)
{
const NEEDS_VOLATILE uchar *ptr = reinterpret_cast<const NEEDS_VOLATILE uchar *>(&x);
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
@@ -611,7 +611,7 @@ static inline ULong _getWord0(const NEEDS_VOLATILE double x)
}
}
-static inline void _setWord0(NEEDS_VOLATILE double *x, ULong l)
+static inline void setWord0(NEEDS_VOLATILE double *x, ULong l)
{
NEEDS_VOLATILE uchar *ptr = reinterpret_cast<NEEDS_VOLATILE uchar *>(x);
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
@@ -627,7 +627,7 @@ static inline void _setWord0(NEEDS_VOLATILE double *x, ULong l)
}
}
-static inline ULong _getWord1(const NEEDS_VOLATILE double x)
+static inline ULong getWord1(const NEEDS_VOLATILE double x)
{
const NEEDS_VOLATILE uchar *ptr = reinterpret_cast<const NEEDS_VOLATILE uchar *>(&x);
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
@@ -636,7 +636,7 @@ static inline ULong _getWord1(const NEEDS_VOLATILE double x)
return (ptr[3]<<24) + (ptr[2]<<16) + (ptr[1]<<8) + ptr[0];
}
}
-static inline void _setWord1(NEEDS_VOLATILE double *x, ULong l)
+static inline void setWord1(NEEDS_VOLATILE double *x, ULong l)
{
NEEDS_VOLATILE uchar *ptr = reinterpret_cast<uchar NEEDS_VOLATILE *>(x);
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
@@ -652,42 +652,6 @@ static inline void _setWord1(NEEDS_VOLATILE double *x, ULong l)
}
}
-static inline ULong getWord0(const NEEDS_VOLATILE double x)
-{
-#ifdef QT_ARMFPA
- return _getWord1(x);
-#else
- return _getWord0(x);
-#endif
-}
-
-static inline void setWord0(NEEDS_VOLATILE double *x, ULong l)
-{
-#ifdef QT_ARMFPA
- _setWord1(x, l);
-#else
- _setWord0(x, l);
-#endif
-}
-
-static inline ULong getWord1(const NEEDS_VOLATILE double x)
-{
-#ifdef QT_ARMFPA
- return _getWord0(x);
-#else
- return _getWord1(x);
-#endif
-}
-
-static inline void setWord1(NEEDS_VOLATILE double *x, ULong l)
-{
-#ifdef QT_ARMFPA
- _setWord0(x, l);
-#else
- _setWord1(x, l);
-#endif
-}
-
static inline void Storeinc(ULong *&a, const ULong &b, const ULong &c)
{
diff --git a/src/corelib/tools/qlocale_tools_p.h b/src/corelib/tools/qlocale_tools_p.h
index 2dc5c03a20..d920d41cb3 100644
--- a/src/corelib/tools/qlocale_tools_p.h
+++ b/src/corelib/tools/qlocale_tools_p.h
@@ -97,15 +97,11 @@ QString &exponentForm(QChar zero, QChar decimal, QChar exponential,
inline bool isZero(double d)
{
uchar *ch = (uchar *)&d;
-#ifdef QT_ARMFPA
- return !(ch[3] & 0x7F || ch[2] || ch[1] || ch[0] || ch[7] || ch[6] || ch[5] || ch[4]);
-#else
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
return !(ch[0] & 0x7F || ch[1] || ch[2] || ch[3] || ch[4] || ch[5] || ch[6] || ch[7]);
} else {
return !(ch[7] & 0x7F || ch[6] || ch[5] || ch[4] || ch[3] || ch[2] || ch[1] || ch[0]);
}
-#endif
}
// Removes thousand-group separators in "C" locale.
diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp
index 6ace96f771..f2876912b4 100644
--- a/src/corelib/tools/qlocale_unix.cpp
+++ b/src/corelib/tools/qlocale_unix.cpp
@@ -98,7 +98,7 @@ QLocale QSystemLocale::fallbackLocale() const
lang = qgetenv("LC_NUMERIC");
if (lang.isEmpty())
lang = qgetenv("LANG");
- return QLocale(QLatin1String(lang));
+ return QLocale(QString::fromLatin1(lang));
}
QVariant QSystemLocale::query(QueryType type, QVariant in) const
diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp
index 474e9cb59d..c922d7aab0 100644
--- a/src/corelib/tools/qmap.cpp
+++ b/src/corelib/tools/qmap.cpp
@@ -232,11 +232,11 @@ void QMapData::dump()
differences are:
\list
- \i QHash provides faster lookups than QMap. (See \l{Algorithmic
+ \li QHash provides faster lookups than QMap. (See \l{Algorithmic
Complexity} for details.)
- \i When iterating over a QHash, the items are arbitrarily ordered.
+ \li When iterating over a QHash, the items are arbitrarily ordered.
With QMap, the items are always sorted by key.
- \i The key type of a QHash must provide operator==() and a global
+ \li The key type of a QHash must provide operator==() and a global
qHash(Key) function. The key type of a QMap must provide
operator<() specifying a total order.
\endlist
diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h
index 501f2af3e6..4dc28f2d26 100644
--- a/src/corelib/tools/qpair.h
+++ b/src/corelib/tools/qpair.h
@@ -55,16 +55,30 @@ struct QPair
typedef T1 first_type;
typedef T2 second_type;
- QPair() : first(T1()), second(T2()) {}
+ QPair() : first(), second() {}
QPair(const T1 &t1, const T2 &t2) : first(t1), second(t2) {}
-
- QPair<T1, T2> &operator=(const QPair<T1, T2> &other)
- { first = other.first; second = other.second; return *this; }
+ // compiler-generated copy/move ctor/assignment operators are fine!
T1 first;
T2 second;
};
+// mark QPair<T1,T2> as complex/movable/primitive depending on the
+// typeinfos of the constituents:
+template<class T1, class T2>
+class QTypeInfo< QPair<T1, T2> >
+{
+public:
+ enum {
+ isComplex = QTypeInfo<T1>::isComplex || QTypeInfo<T2>::isComplex,
+ isStatic = QTypeInfo<T1>::isStatic || QTypeInfo<T2>::isStatic,
+ isLarge = sizeof(QPair<T1, T2>) > sizeof(void*),
+ isPointer = false,
+ isDummy = false,
+ sizeOf = sizeof(QPair<T1, T2>)
+ };
+};
+
template <class T1, class T2>
Q_INLINE_TEMPLATE bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
{ return p1.first == p2.first && p1.second == p2.second; }
diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp
index 7ff883a99a..aeab97803d 100644
--- a/src/corelib/tools/qrect.cpp
+++ b/src/corelib/tools/qrect.cpp
@@ -99,11 +99,11 @@ QT_BEGIN_NAMESPACE
\table
\row
- \o \inlineimage qrect-intersect.png
- \o \inlineimage qrect-unite.png
+ \li \inlineimage qrect-intersect.png
+ \li \inlineimage qrect-unite.png
\row
- \o intersected()
- \o united()
+ \li intersected()
+ \li united()
\endtable
The isEmpty() function returns true if left() > right() or top() >
@@ -139,17 +139,17 @@ QT_BEGIN_NAMESPACE
\table
\row
- \o \inlineimage qrect-diagram-zero.png
- \o \inlineimage qrect-diagram-one.png
+ \li \inlineimage qrect-diagram-zero.png
+ \li \inlineimage qrect-diagram-one.png
\row
- \o Logical representation
- \o One pixel wide pen
+ \li Logical representation
+ \li One pixel wide pen
\row
- \o \inlineimage qrect-diagram-two.png
- \o \inlineimage qrect-diagram-three.png
+ \li \inlineimage qrect-diagram-two.png
+ \li \inlineimage qrect-diagram-three.png
\row
- \o Two pixel wide pen
- \o Three pixel wide pen
+ \li Two pixel wide pen
+ \li Three pixel wide pen
\endtable
\section1 Coordinates
@@ -1278,11 +1278,11 @@ QDebug operator<<(QDebug dbg, const QRect &r) {
\table
\row
- \o \inlineimage qrect-intersect.png
- \o \inlineimage qrect-unite.png
+ \li \inlineimage qrect-intersect.png
+ \li \inlineimage qrect-unite.png
\row
- \o intersected()
- \o united()
+ \li intersected()
+ \li united()
\endtable
The isEmpty() function returns true if the rectangle's width or
@@ -1318,17 +1318,17 @@ QDebug operator<<(QDebug dbg, const QRect &r) {
\table
\row
- \o \inlineimage qrect-diagram-zero.png
- \o \inlineimage qrectf-diagram-one.png
+ \li \inlineimage qrect-diagram-zero.png
+ \li \inlineimage qrectf-diagram-one.png
\row
- \o Logical representation
- \o One pixel wide pen
+ \li Logical representation
+ \li One pixel wide pen
\row
- \o \inlineimage qrectf-diagram-two.png
- \o \inlineimage qrectf-diagram-three.png
+ \li \inlineimage qrectf-diagram-two.png
+ \li \inlineimage qrectf-diagram-three.png
\row
- \o Two pixel wide pen
- \o Three pixel wide pen
+ \li Two pixel wide pen
+ \li Three pixel wide pen
\endtable
\section1 Coordinates
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp
index d7bcd0edbc..29b3424315 100644
--- a/src/corelib/tools/qregexp.cpp
+++ b/src/corelib/tools/qregexp.cpp
@@ -90,21 +90,21 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
substrings in a text. This is useful in many contexts, e.g.,
\table
- \row \i Validation
- \i A regexp can test whether a substring meets some criteria,
+ \row \li Validation
+ \li A regexp can test whether a substring meets some criteria,
e.g. is an integer or contains no whitespace.
- \row \i Searching
- \i A regexp provides more powerful pattern matching than
+ \row \li Searching
+ \li A regexp provides more powerful pattern matching than
simple substring matching, e.g., match one of the words
\e{mail}, \e{letter} or \e{correspondence}, but none of the
words \e{email}, \e{mailman}, \e{mailer}, \e{letterbox}, etc.
- \row \i Search and Replace
- \i A regexp can replace all occurrences of a substring with a
+ \row \li Search and Replace
+ \li A regexp can replace all occurrences of a substring with a
different substring, e.g., replace all occurrences of \e{&}
with \e{\&amp;} except where the \e{&} is already followed by
an \e{amp;}.
- \row \i String Splitting
- \i A regexp can be used to identify where a string should be
+ \row \li String Splitting
+ \li A regexp can be used to identify where a string should be
split apart, e.g. splitting tab-delimited strings.
\endtable
@@ -127,18 +127,18 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
\section1 Introduction
Regexps are built up from expressions, quantifiers, and
- assertions. The simplest expression is a character, e.g. \bold{x}
- or \bold{5}. An expression can also be a set of characters
- enclosed in square brackets. \bold{[ABCD]} will match an \bold{A}
- or a \bold{B} or a \bold{C} or a \bold{D}. We can write this same
- expression as \bold{[A-D]}, and an experession to match any
+ assertions. The simplest expression is a character, e.g. \b{x}
+ or \b{5}. An expression can also be a set of characters
+ enclosed in square brackets. \b{[ABCD]} will match an \b{A}
+ or a \b{B} or a \b{C} or a \b{D}. We can write this same
+ expression as \b{[A-D]}, and an experession to match any
captital letter in the English alphabet is written as
- \bold{[A-Z]}.
+ \b{[A-Z]}.
A quantifier specifies the number of occurrences of an expression
- that must be matched. \bold{x{1,1}} means match one and only one
- \bold{x}. \bold{x{1,5}} means match a sequence of \bold{x}
- characters that contains at least one \bold{x} but no more than
+ that must be matched. \b{x{1,1}} means match one and only one
+ \b{x}. \b{x{1,5}} means match a sequence of \b{x}
+ characters that contains at least one \b{x} but no more than
five.
Note that in general regexps cannot be used to check for balanced
@@ -156,35 +156,35 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
Suppose we want a regexp to match integers in the range 0 to 99.
At least one digit is required, so we start with the expression
- \bold{[0-9]{1,1}}, which matches a single digit exactly once. This
+ \b{[0-9]{1,1}}, which matches a single digit exactly once. This
regexp matches integers in the range 0 to 9. To match integers up
to 99, increase the maximum number of occurrences to 2, so the
- regexp becomes \bold{[0-9]{1,2}}. This regexp satisfies the
+ regexp becomes \b{[0-9]{1,2}}. This regexp satisfies the
original requirement to match integers from 0 to 99, but it will
also match integers that occur in the middle of strings. If we
want the matched integer to be the whole string, we must use the
- anchor assertions, \bold{^} (caret) and \bold{$} (dollar). When
- \bold{^} is the first character in a regexp, it means the regexp
- must match from the beginning of the string. When \bold{$} is the
+ anchor assertions, \b{^} (caret) and \b{$} (dollar). When
+ \b{^} is the first character in a regexp, it means the regexp
+ must match from the beginning of the string. When \b{$} is the
last character of the regexp, it means the regexp must match to
- the end of the string. The regexp becomes \bold{^[0-9]{1,2}$}.
- Note that assertions, e.g. \bold{^} and \bold{$}, do not match
+ the end of the string. The regexp becomes \b{^[0-9]{1,2}$}.
+ Note that assertions, e.g. \b{^} and \b{$}, do not match
characters but locations in the string.
If you have seen regexps described elsewhere, they may have looked
different from the ones shown here. This is because some sets of
characters and some quantifiers are so common that they have been
- given special symbols to represent them. \bold{[0-9]} can be
- replaced with the symbol \bold{\\d}. The quantifier to match
- exactly one occurrence, \bold{{1,1}}, can be replaced with the
- expression itself, i.e. \bold{x{1,1}} is the same as \bold{x}. So
- our 0 to 99 matcher could be written as \bold{^\\d{1,2}$}. It can
- also be written \bold{^\\d\\d{0,1}$}, i.e. \e{From the start of
+ given special symbols to represent them. \b{[0-9]} can be
+ replaced with the symbol \b{\\d}. The quantifier to match
+ exactly one occurrence, \b{{1,1}}, can be replaced with the
+ expression itself, i.e. \b{x{1,1}} is the same as \b{x}. So
+ our 0 to 99 matcher could be written as \b{^\\d{1,2}$}. It can
+ also be written \b{^\\d\\d{0,1}$}, i.e. \e{From the start of
the string, match a digit, followed immediately by 0 or 1 digits}.
- In practice, it would be written as \bold{^\\d\\d?$}. The \bold{?}
- is shorthand for the quantifier \bold{{0,1}}, i.e. 0 or 1
- occurrences. \bold{?} makes an expression optional. The regexp
- \bold{^\\d\\d?$} means \e{From the beginning of the string, match
+ In practice, it would be written as \b{^\\d\\d?$}. The \b{?}
+ is shorthand for the quantifier \b{{0,1}}, i.e. 0 or 1
+ occurrences. \b{?} makes an expression optional. The regexp
+ \b{^\\d\\d?$} means \e{From the beginning of the string, match
one digit, followed immediately by 0 or 1 more digit, followed
immediately by end of string}.
@@ -192,45 +192,45 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
'letter' \e or 'correspondence' but does not match words that
contain these words, e.g., 'email', 'mailman', 'mailer', and
'letterbox', start with a regexp that matches 'mail'. Expressed
- fully, the regexp is \bold{m{1,1}a{1,1}i{1,1}l{1,1}}, but because
+ fully, the regexp is \b{m{1,1}a{1,1}i{1,1}l{1,1}}, but because
a character expression is automatically quantified by
- \bold{{1,1}}, we can simplify the regexp to \bold{mail}, i.e., an
+ \b{{1,1}}, we can simplify the regexp to \b{mail}, i.e., an
'm' followed by an 'a' followed by an 'i' followed by an 'l'. Now
- we can use the vertical bar \bold{|}, which means \bold{or}, to
+ we can use the vertical bar \b{|}, which means \b{or}, to
include the other two words, so our regexp for matching any of the
- three words becomes \bold{mail|letter|correspondence}. Match
- 'mail' \bold{or} 'letter' \bold{or} 'correspondence'. While this
+ three words becomes \b{mail|letter|correspondence}. Match
+ 'mail' \b{or} 'letter' \b{or} 'correspondence'. While this
regexp will match one of the three words we want to match, it will
also match words we don't want to match, e.g., 'email'. To
prevent the regexp from matching unwanted words, we must tell it
to begin and end the match at word boundaries. First we enclose
- our regexp in parentheses, \bold{(mail|letter|correspondence)}.
+ our regexp in parentheses, \b{(mail|letter|correspondence)}.
Parentheses group expressions together, and they identify a part
of the regexp that we wish to \l{capturing text}{capture}.
Enclosing the expression in parentheses allows us to use it as a
component in more complex regexps. It also allows us to examine
which of the three words was actually matched. To force the match
to begin and end on word boundaries, we enclose the regexp in
- \bold{\\b} \e{word boundary} assertions:
- \bold{\\b(mail|letter|correspondence)\\b}. Now the regexp means:
+ \b{\\b} \e{word boundary} assertions:
+ \b{\\b(mail|letter|correspondence)\\b}. Now the regexp means:
\e{Match a word boundary, followed by the regexp in parentheses,
- followed by a word boundary}. The \bold{\\b} assertion matches a
+ followed by a word boundary}. The \b{\\b} assertion matches a
\e position in the regexp, not a \e character. A word boundary is
any non-word character, e.g., a space, newline, or the beginning
or ending of a string.
If we want to replace ampersand characters with the HTML entity
- \bold{\&amp;}, the regexp to match is simply \bold{\&}. But this
+ \b{\&amp;}, the regexp to match is simply \b{\&}. But this
regexp will also match ampersands that have already been converted
to HTML entities. We want to replace only ampersands that are not
- already followed by \bold{amp;}. For this, we need the negative
- lookahead assertion, \bold{(?!}__\bold{)}. The regexp can then be
- written as \bold{\&(?!amp;)}, i.e. \e{Match an ampersand that is}
- \bold{not} \e{followed by} \bold{amp;}.
+ already followed by \b{amp;}. For this, we need the negative
+ lookahead assertion, \b{(?!}__\b{)}. The regexp can then be
+ written as \b{\&(?!amp;)}, i.e. \e{Match an ampersand that is}
+ \b{not} \e{followed by} \b{amp;}.
If we want to count all the occurrences of 'Eric' and 'Eirik' in a
- string, two valid solutions are \bold{\\b(Eric|Eirik)\\b} and
- \bold{\\bEi?ri[ck]\\b}. The word boundary assertion '\\b' is
+ string, two valid solutions are \b{\\b(Eric|Eirik)\\b} and
+ \b{\\bEi?ri[ck]\\b}. The word boundary assertion '\\b' is
required to avoid matching words that contain either name,
e.g. 'Ericsson'. Note that the second regexp matches more
spellings than we want: 'Eric', 'Erik', 'Eiric' and 'Eirik'.
@@ -242,52 +242,52 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
\section1 Characters and Abbreviations for Sets of Characters
\table
- \header \i Element \i Meaning
- \row \i \bold{c}
- \i A character represents itself unless it has a special
- regexp meaning. e.g. \bold{c} matches the character \e c.
- \row \i \bold{\\c}
- \i A character that follows a backslash matches the character
+ \header \li Element \li Meaning
+ \row \li \b{c}
+ \li A character represents itself unless it has a special
+ regexp meaning. e.g. \b{c} matches the character \e c.
+ \row \li \b{\\c}
+ \li A character that follows a backslash matches the character
itself, except as specified below. e.g., To match a literal
- caret at the beginning of a string, write \bold{\\^}.
- \row \i \bold{\\a}
- \i Matches the ASCII bell (BEL, 0x07).
- \row \i \bold{\\f}
- \i Matches the ASCII form feed (FF, 0x0C).
- \row \i \bold{\\n}
- \i Matches the ASCII line feed (LF, 0x0A, Unix newline).
- \row \i \bold{\\r}
- \i Matches the ASCII carriage return (CR, 0x0D).
- \row \i \bold{\\t}
- \i Matches the ASCII horizontal tab (HT, 0x09).
- \row \i \bold{\\v}
- \i Matches the ASCII vertical tab (VT, 0x0B).
- \row \i \bold{\\x\e{hhhh}}
- \i Matches the Unicode character corresponding to the
+ caret at the beginning of a string, write \b{\\^}.
+ \row \li \b{\\a}
+ \li Matches the ASCII bell (BEL, 0x07).
+ \row \li \b{\\f}
+ \li Matches the ASCII form feed (FF, 0x0C).
+ \row \li \b{\\n}
+ \li Matches the ASCII line feed (LF, 0x0A, Unix newline).
+ \row \li \b{\\r}
+ \li Matches the ASCII carriage return (CR, 0x0D).
+ \row \li \b{\\t}
+ \li Matches the ASCII horizontal tab (HT, 0x09).
+ \row \li \b{\\v}
+ \li Matches the ASCII vertical tab (VT, 0x0B).
+ \row \li \b{\\x\e{hhhh}}
+ \li Matches the Unicode character corresponding to the
hexadecimal number \e{hhhh} (between 0x0000 and 0xFFFF).
- \row \i \bold{\\0\e{ooo}} (i.e., \\zero \e{ooo})
- \i matches the ASCII/Latin1 character for the octal number
+ \row \li \b{\\0\e{ooo}} (i.e., \\zero \e{ooo})
+ \li matches the ASCII/Latin1 character for the octal number
\e{ooo} (between 0 and 0377).
- \row \i \bold{. (dot)}
- \i Matches any character (including newline).
- \row \i \bold{\\d}
- \i Matches a digit (QChar::isDigit()).
- \row \i \bold{\\D}
- \i Matches a non-digit.
- \row \i \bold{\\s}
- \i Matches a whitespace character (QChar::isSpace()).
- \row \i \bold{\\S}
- \i Matches a non-whitespace character.
- \row \i \bold{\\w}
- \i Matches a word character (QChar::isLetterOrNumber(), QChar::isMark(), or '_').
- \row \i \bold{\\W}
- \i Matches a non-word character.
- \row \i \bold{\\\e{n}}
- \i The \e{n}-th \l backreference, e.g. \\1, \\2, etc.
+ \row \li \b{. (dot)}
+ \li Matches any character (including newline).
+ \row \li \b{\\d}
+ \li Matches a digit (QChar::isDigit()).
+ \row \li \b{\\D}
+ \li Matches a non-digit.
+ \row \li \b{\\s}
+ \li Matches a whitespace character (QChar::isSpace()).
+ \row \li \b{\\S}
+ \li Matches a non-whitespace character.
+ \row \li \b{\\w}
+ \li Matches a word character (QChar::isLetterOrNumber(), QChar::isMark(), or '_').
+ \row \li \b{\\W}
+ \li Matches a non-word character.
+ \row \li \b{\\\e{n}}
+ \li The \e{n}-th \l backreference, e.g. \\1, \\2, etc.
\endtable
- \bold{Note:} The C++ compiler transforms backslashes in strings.
- To include a \bold{\\} in a regexp, enter it twice, i.e. \c{\\}.
+ \b{Note:} The C++ compiler transforms backslashes in strings.
+ To include a \b{\\} in a regexp, enter it twice, i.e. \c{\\}.
To match the backslash character itself, enter it four times, i.e.
\c{\\\\}.
@@ -301,24 +301,24 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
characters do not have special meanings in square brackets.
\table
- \row \i \bold{^}
+ \row \li \b{^}
- \i The caret negates the character set if it occurs as the
+ \li The caret negates the character set if it occurs as the
first character (i.e. immediately after the opening square
- bracket). \bold{[abc]} matches 'a' or 'b' or 'c', but
- \bold{[^abc]} matches anything \e but 'a' or 'b' or 'c'.
+ bracket). \b{[abc]} matches 'a' or 'b' or 'c', but
+ \b{[^abc]} matches anything \e but 'a' or 'b' or 'c'.
- \row \i \bold{-}
+ \row \li \b{-}
- \i The dash indicates a range of characters. \bold{[W-Z]}
+ \li The dash indicates a range of characters. \b{[W-Z]}
matches 'W' or 'X' or 'Y' or 'Z'.
\endtable
Using the predefined character set abbreviations is more portable
than using character ranges across platforms and languages. For
- example, \bold{[0-9]} matches a digit in Western alphabets but
- \bold{\\d} matches a digit in \e any alphabet.
+ example, \b{[0-9]} matches a digit in Western alphabets but
+ \b{\\d} matches a digit in \e any alphabet.
Note: In other regexp documentation, sets of characters are often
called "character classes".
@@ -327,64 +327,64 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
\section1 Quantifiers
By default, an expression is automatically quantified by
- \bold{{1,1}}, i.e. it should occur exactly once. In the following
- list, \bold{\e {E}} stands for expression. An expression is a
+ \b{{1,1}}, i.e. it should occur exactly once. In the following
+ list, \b{\e {E}} stands for expression. An expression is a
character, or an abbreviation for a set of characters, or a set of
characters in square brackets, or an expression in parentheses.
\table
- \row \i \bold{\e {E}?}
+ \row \li \b{\e {E}?}
- \i Matches zero or one occurrences of \e E. This quantifier
+ \li Matches zero or one occurrences of \e E. This quantifier
means \e{The previous expression is optional}, because it
- will match whether or not the expression is found. \bold{\e
- {E}?} is the same as \bold{\e {E}{0,1}}. e.g., \bold{dents?}
+ will match whether or not the expression is found. \b{\e
+ {E}?} is the same as \b{\e {E}{0,1}}. e.g., \b{dents?}
matches 'dent' or 'dents'.
- \row \i \bold{\e {E}+}
+ \row \li \b{\e {E}+}
- \i Matches one or more occurrences of \e E. \bold{\e {E}+} is
- the same as \bold{\e {E}{1,}}. e.g., \bold{0+} matches '0',
+ \li Matches one or more occurrences of \e E. \b{\e {E}+} is
+ the same as \b{\e {E}{1,}}. e.g., \b{0+} matches '0',
'00', '000', etc.
- \row \i \bold{\e {E}*}
+ \row \li \b{\e {E}*}
- \i Matches zero or more occurrences of \e E. It is the same
- as \bold{\e {E}{0,}}. The \bold{*} quantifier is often used
- in error where \bold{+} should be used. For example, if
- \bold{\\s*$} is used in an expression to match strings that
+ \li Matches zero or more occurrences of \e E. It is the same
+ as \b{\e {E}{0,}}. The \b{*} quantifier is often used
+ in error where \b{+} should be used. For example, if
+ \b{\\s*$} is used in an expression to match strings that
end in whitespace, it will match every string because
- \bold{\\s*$} means \e{Match zero or more whitespaces followed
+ \b{\\s*$} means \e{Match zero or more whitespaces followed
by end of string}. The correct regexp to match strings that
have at least one trailing whitespace character is
- \bold{\\s+$}.
+ \b{\\s+$}.
- \row \i \bold{\e {E}{n}}
+ \row \li \b{\e {E}{n}}
- \i Matches exactly \e n occurrences of \e E. \bold{\e {E}{n}}
+ \li Matches exactly \e n occurrences of \e E. \b{\e {E}{n}}
is the same as repeating \e E \e n times. For example,
- \bold{x{5}} is the same as \bold{xxxxx}. It is also the same
- as \bold{\e {E}{n,n}}, e.g. \bold{x{5,5}}.
+ \b{x{5}} is the same as \b{xxxxx}. It is also the same
+ as \b{\e {E}{n,n}}, e.g. \b{x{5,5}}.
- \row \i \bold{\e {E}{n,}}
- \i Matches at least \e n occurrences of \e E.
+ \row \li \b{\e {E}{n,}}
+ \li Matches at least \e n occurrences of \e E.
- \row \i \bold{\e {E}{,m}}
- \i Matches at most \e m occurrences of \e E. \bold{\e {E}{,m}}
- is the same as \bold{\e {E}{0,m}}.
+ \row \li \b{\e {E}{,m}}
+ \li Matches at most \e m occurrences of \e E. \b{\e {E}{,m}}
+ is the same as \b{\e {E}{0,m}}.
- \row \i \bold{\e {E}{n,m}}
- \i Matches at least \e n and at most \e m occurrences of \e E.
+ \row \li \b{\e {E}{n,m}}
+ \li Matches at least \e n and at most \e m occurrences of \e E.
\endtable
To apply a quantifier to more than just the preceding character,
use parentheses to group characters together in an expression. For
- example, \bold{tag+} matches a 't' followed by an 'a' followed by
- at least one 'g', whereas \bold{(tag)+} matches at least one
+ example, \b{tag+} matches a 't' followed by an 'a' followed by
+ at least one 'g', whereas \b{(tag)+} matches at least one
occurrence of 'tag'.
Note: Quantifiers are normally "greedy". They always match as much
- text as they can. For example, \bold{0+} matches the first zero it
+ text as they can. For example, \b{0+} matches the first zero it
finds and all the consecutive zeros after the first zero. Applied
to '20005', it matches'2\underline{000}5'. Quantifiers can be made
non-greedy, see setMinimal().
@@ -395,10 +395,10 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
Parentheses allow us to group elements together so that we can
quantify and capture them. For example if we have the expression
- \bold{mail|letter|correspondence} that matches a string we know
+ \b{mail|letter|correspondence} that matches a string we know
that \e one of the words matched but not which one. Using
parentheses allows us to "capture" whatever is matched within
- their bounds, so if we used \bold{(mail|letter|correspondence)}
+ their bounds, so if we used \b{(mail|letter|correspondence)}
and matched this regexp against the string "I sent you some email"
we can use the cap() or capturedTexts() functions to extract the
matched characters, in this case 'mail'.
@@ -406,14 +406,14 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
We can use captured text within the regexp itself. To refer to the
captured text we use \e backreferences which are indexed from 1,
the same as for cap(). For example we could search for duplicate
- words in a string using \bold{\\b(\\w+)\\W+\\1\\b} which means match a
+ words in a string using \b{\\b(\\w+)\\W+\\1\\b} which means match a
word boundary followed by one or more word characters followed by
one or more non-word characters followed by the same text as the
first parenthesized expression followed by a word boundary.
If we want to use parentheses purely for grouping and not for
capturing we can use the non-capturing syntax, e.g.
- \bold{(?:green|blue)}. Non-capturing parentheses begin '(?:' and
+ \b{(?:green|blue)}. Non-capturing parentheses begin '(?:' and
end ')'. In this example we match either 'green' or 'blue' but we
do not capture the match so we only know whether or not we matched
but not which color we actually found. Using non-capturing
@@ -424,9 +424,9 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
\target greedy quantifiers
- For historical reasons, quantifiers (e.g. \bold{*}) that apply to
+ For historical reasons, quantifiers (e.g. \b{*}) that apply to
capturing parentheses are more "greedy" than other quantifiers.
- For example, \bold{a*(a*)} will match "aaa" with cap(1) == "aaa".
+ For example, \b{a*(a*)} will match "aaa" with cap(1) == "aaa".
This behavior is different from what other regexp engines do
(notably, Perl). To obtain a more intuitive capturing behavior,
specify QRegExp::RegExp2 to the QRegExp constructor or call
@@ -444,54 +444,54 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
Assertions make some statement about the text at the point where
they occur in the regexp but they do not match any characters. In
- the following list \bold{\e {E}} stands for any expression.
+ the following list \b{\e {E}} stands for any expression.
\table
- \row \i \bold{^}
- \i The caret signifies the beginning of the string. If you
+ \row \li \b{^}
+ \li The caret signifies the beginning of the string. If you
wish to match a literal \c{^} you must escape it by
- writing \c{\\^}. For example, \bold{^#include} will only
+ writing \c{\\^}. For example, \b{^#include} will only
match strings which \e begin with the characters '#include'.
(When the caret is the first character of a character set it
has a special meaning, see \link #sets-of-characters Sets of
Characters \endlink.)
- \row \i \bold{$}
- \i The dollar signifies the end of the string. For example
- \bold{\\d\\s*$} will match strings which end with a digit
+ \row \li \b{$}
+ \li The dollar signifies the end of the string. For example
+ \b{\\d\\s*$} will match strings which end with a digit
optionally followed by whitespace. If you wish to match a
literal \c{$} you must escape it by writing
\c{\\$}.
- \row \i \bold{\\b}
- \i A word boundary. For example the regexp
- \bold{\\bOK\\b} means match immediately after a word
+ \row \li \b{\\b}
+ \li A word boundary. For example the regexp
+ \b{\\bOK\\b} means match immediately after a word
boundary (e.g. start of string or whitespace) the letter 'O'
then the letter 'K' immediately before another word boundary
(e.g. end of string or whitespace). But note that the
assertion does not actually match any whitespace so if we
- write \bold{(\\bOK\\b)} and we have a match it will only
+ write \b{(\\bOK\\b)} and we have a match it will only
contain 'OK' even if the string is "It's \underline{OK} now".
- \row \i \bold{\\B}
- \i A non-word boundary. This assertion is true wherever
- \bold{\\b} is false. For example if we searched for
- \bold{\\Bon\\B} in "Left on" the match would fail (space
+ \row \li \b{\\B}
+ \li A non-word boundary. This assertion is true wherever
+ \b{\\b} is false. For example if we searched for
+ \b{\\Bon\\B} in "Left on" the match would fail (space
and end of string aren't non-word boundaries), but it would
match in "t\underline{on}ne".
- \row \i \bold{(?=\e E)}
- \i Positive lookahead. This assertion is true if the
+ \row \li \b{(?=\e E)}
+ \li Positive lookahead. This assertion is true if the
expression matches at this point in the regexp. For example,
- \bold{const(?=\\s+char)} matches 'const' whenever it is
+ \b{const(?=\\s+char)} matches 'const' whenever it is
followed by 'char', as in 'static \underline{const} char *'.
- (Compare with \bold{const\\s+char}, which matches 'static
+ (Compare with \b{const\\s+char}, which matches 'static
\underline{const char} *'.)
- \row \i \bold{(?!\e E)}
- \i Negative lookahead. This assertion is true if the
+ \row \li \b{(?!\e E)}
+ \li Negative lookahead. This assertion is true if the
expression does not match at this point in the regexp. For
- example, \bold{const(?!\\s+char)} matches 'const' \e except
+ example, \b{const(?!\\s+char)} matches 'const' \e except
when it is followed by 'char'.
\endtable
@@ -505,17 +505,17 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
simpler than full regexps and has only four features:
\table
- \row \i \bold{c}
- \i Any character represents itself apart from those mentioned
- below. Thus \bold{c} matches the character \e c.
- \row \i \bold{?}
- \i Matches any single character. It is the same as
- \bold{.} in full regexps.
- \row \i \bold{*}
- \i Matches zero or more of any characters. It is the
- same as \bold{.*} in full regexps.
- \row \i \bold{[...]}
- \i Sets of characters can be represented in square brackets,
+ \row \li \b{c}
+ \li Any character represents itself apart from those mentioned
+ below. Thus \b{c} matches the character \e c.
+ \row \li \b{?}
+ \li Matches any single character. It is the same as
+ \b{.} in full regexps.
+ \row \li \b{*}
+ \li Matches zero or more of any characters. It is the
+ same as \b{.*} in full regexps.
+ \row \li \b{[...]}
+ \li Sets of characters can be represented in square brackets,
similar to full regexps. Within the character class, like
outside, backslash has no special meaning.
\endtable
@@ -525,7 +525,7 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
wildcard.
For example if we are in wildcard mode and have strings which
- contain filenames we could identify HTML files with \bold{*.html}.
+ contain filenames we could identify HTML files with \b{*.html}.
This will match zero or more characters followed by a dot followed
by 'h', 't', 'm' and 'l'.
@@ -553,7 +553,7 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
(but see the \l{greedy quantifiers}{note above}). Non-greedy
matching cannot be applied to individual quantifiers, but can be
applied to all the quantifiers in the pattern. For example, to
- match the Perl regexp \bold{ro+?m} requires:
+ match the Perl regexp \b{ro+?m} requires:
\snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 2
@@ -562,7 +562,7 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
Perl's \c{/g} option can be emulated using a \l{#cap_in_a_loop}{loop}.
- In QRegExp \bold{.} matches any character, therefore all QRegExp
+ In QRegExp \b{.} matches any character, therefore all QRegExp
regexps have the equivalent of Perl's \c{/s} option. QRegExp
does not have an equivalent to Perl's \c{/m} option, but this
can be emulated in various ways for example by splitting the input
@@ -598,7 +598,7 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
to Perl's split and join functions.
Note: because C++ transforms \\'s they must be written \e twice in
- code, e.g. \bold{\\b} must be written \bold{\\\\b}.
+ code, e.g. \b{\\b} must be written \b{\\\\b}.
\target code-examples
\section1 Code Examples
@@ -670,10 +670,10 @@ int qFindString(const QChar *haystack, int haystackLen, int from,
Wildcard matching can be convenient because of its simplicity, but
any wildcard regexp can be defined using full regexps, e.g.
- \bold{.*\\.html$}. Notice that we can't match both \c .html and \c
- .htm files with a wildcard unless we use \bold{*.htm*} which will
+ \b{.*\\.html$}. Notice that we can't match both \c .html and \c
+ .htm files with a wildcard unless we use \b{*.htm*} which will
also match 'test.html.bak'. A full regexp gives us the precision
- we need, \bold{.*\\.html?$}.
+ we need, \b{.*\\.html?$}.
QRegExp can match case insensitively using setCaseSensitivity(),
and can use non-greedy matching, see setMinimal(). By
@@ -3015,6 +3015,8 @@ int QRegExpEngine::getEscape()
if (xmlSchemaExtensions) {
yyCharClass->setNegative(!yyCharClass->negative());
// fall through
+ } else {
+ break;
}
case 'i':
if (xmlSchemaExtensions) {
@@ -3045,12 +3047,16 @@ int QRegExpEngine::getEscape()
yyCharClass->addRange(0xf900, 0xfdcf);
yyCharClass->addRange(0xfdf0, 0xfffd);
yyCharClass->addRange((ushort)0x10000, (ushort)0xeffff);
+ return Tok_CharClass;
+ } else {
+ break;
}
- return Tok_CharClass;
case 'C':
if (xmlSchemaExtensions) {
yyCharClass->setNegative(!yyCharClass->negative());
// fall through
+ } else {
+ break;
}
case 'c':
if (xmlSchemaExtensions) {
@@ -3087,12 +3093,16 @@ int QRegExpEngine::getEscape()
yyCharClass->addRange((ushort)0x10000, (ushort)0xeffff);
yyCharClass->addRange(0x0300, 0x036f);
yyCharClass->addRange(0x203f, 0x2040);
+ return Tok_CharClass;
+ } else {
+ break;
}
- return Tok_CharClass;
case 'P':
if (xmlSchemaExtensions) {
yyCharClass->setNegative(!yyCharClass->negative());
// fall through
+ } else {
+ break;
}
case 'p':
if (xmlSchemaExtensions) {
@@ -3246,8 +3256,10 @@ int QRegExpEngine::getEscape()
} else {
error(RXERR_CATEGORY);
}
+ return Tok_CharClass;
+ } else {
+ break;
}
- return Tok_CharClass;
#endif
#ifndef QT_NO_REGEXP_ESCAPE
case 'x':
@@ -3265,20 +3277,21 @@ int QRegExpEngine::getEscape()
return Tok_Char | val;
#endif
default:
- if (prevCh >= '1' && prevCh <= '9') {
+ break;
+ }
+ if (prevCh >= '1' && prevCh <= '9') {
#ifndef QT_NO_REGEXP_BACKREF
- val = prevCh - '0';
- while (yyCh >= '0' && yyCh <= '9') {
- val = (val * 10) + (yyCh - '0');
- yyCh = getChar();
- }
- return Tok_BackRef | val;
+ val = prevCh - '0';
+ while (yyCh >= '0' && yyCh <= '9') {
+ val = (val * 10) + (yyCh - '0');
+ yyCh = getChar();
+ }
+ return Tok_BackRef | val;
#else
- error(RXERR_DISABLED);
+ error(RXERR_DISABLED);
#endif
- }
- return Tok_Char | prevCh;
}
+ return Tok_Char | prevCh;
}
#ifndef QT_NO_REGEXP_INTERVAL
@@ -3885,7 +3898,7 @@ static void invalidateEngine(QRegExpPrivate *priv)
\enum QRegExp::CaretMode
The CaretMode enum defines the different meanings of the caret
- (\bold{^}) in a regular expression. The possible values are:
+ (\b{^}) in a regular expression. The possible values are:
\value CaretAtZero
The caret corresponds to index 0 in the searched string.
@@ -4052,11 +4065,11 @@ bool QRegExp::isEmpty() const
Returns true if the regular expression is valid; otherwise returns
false. An invalid regular expression never matches.
- The pattern \bold{[a-z} is an example of an invalid pattern, since
+ The pattern \b{[a-z} is an example of an invalid pattern, since
it lacks a closing square bracket.
Note that the validity of a regexp may also depend on the setting
- of the wildcard flag, for example \bold{*.html} is a valid
+ of the wildcard flag, for example \b{*.html} is a valid
wildcard regexp but an invalid full regexp.
\sa errorString()
@@ -4111,7 +4124,7 @@ Qt::CaseSensitivity QRegExp::caseSensitivity() const
/*!
Sets case sensitive matching to \a cs.
- If \a cs is Qt::CaseSensitive, \bold{\\.txt$} matches
+ If \a cs is Qt::CaseSensitive, \b{\\.txt$} matches
\c{readme.txt} but not \c{README.TXT}.
\sa setPatternSyntax(), setPattern(), setMinimal()
@@ -4140,7 +4153,7 @@ QRegExp::PatternSyntax QRegExp::patternSyntax() const
QRegExp::RegExp.
Setting \a syntax to QRegExp::Wildcard enables simple shell-like
- \l{wildcard matching}. For example, \bold{r*.txt} matches the
+ \l{wildcard matching}. For example, \b{r*.txt} matches the
string \c{readme.txt} in wildcard mode, but does not match
\c{readme}.
@@ -4175,13 +4188,13 @@ bool QRegExp::isMinimal() const
For example, suppose we have the input string "We must be
<b>bold</b>, very <b>bold</b>!" and the pattern
- \bold{<b>.*</b>}. With the default greedy (maximal) matching,
+ \b{<b>.*</b>}. With the default greedy (maximal) matching,
the match is "We must be \underline{<b>bold</b>, very
<b>bold</b>}!". But with minimal (non-greedy) matching, the
first match is: "We must be \underline{<b>bold</b>}, very
<b>bold</b>!" and the second match is "We must be <b>bold</b>,
very \underline{<b>bold</b>}!". In practice we might use the pattern
- \bold{<b>[^<]*\</b>} instead, although this will still fail for
+ \b{<b>[^<]*\</b>} instead, although this will still fail for
nested tags.
\sa setCaseSensitivity()
@@ -4202,7 +4215,7 @@ void QRegExp::setMinimal(bool minimal)
in the start of string and end of string anchors, except that it
sets matchedLength() differently.
- For example, if the regular expression is \bold{blue}, then
+ For example, if the regular expression is \b{blue}, then
exactMatch() returns true only for input \c blue. For inputs \c
bluebell, \c blutak and \c lightblue, exactMatch() returns false
and matchedLength() will return 4, 3 and 0 respectively.
@@ -4234,7 +4247,7 @@ bool QRegExp::exactMatch(const QString &str) const
Returns the position of the first match, or -1 if there was no
match.
- The \a caretMode parameter can be used to instruct whether \bold{^}
+ The \a caretMode parameter can be used to instruct whether \b{^}
should match at index 0 or at \a offset.
You might prefer to use QString::indexOf(), QString::contains(),
@@ -4273,7 +4286,7 @@ int QRegExp::indexIn(const QString &str, int offset, CaretMode caretMode) const
Returns the position of the first match, or -1 if there was no
match.
- The \a caretMode parameter can be used to instruct whether \bold{^}
+ The \a caretMode parameter can be used to instruct whether \b{^}
should match at index 0 or at \a offset.
Although const, this function sets matchedLength(),
@@ -4358,7 +4371,7 @@ int QRegExp::captureCount() const
Some regexps can match an indeterminate number of times. For
example if the input string is "Offsets: 12 14 99 231 7" and the
- regexp, \c{rx}, is \bold{(\\d+)+}, we would hope to get a list of
+ regexp, \c{rx}, is \b{(\\d+)+}, we would hope to get a list of
all the numbers matched. However, after calling
\c{rx.indexIn(str)}, capturedTexts() will return the list ("12",
"12"), i.e. the entire match was "12" and the first subexpression
diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp
new file mode 100644
index 0000000000..0fa7d6459e
--- /dev/null
+++ b/src/corelib/tools/qregularexpression.cpp
@@ -0,0 +1,2134 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>.
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qregularexpression.h"
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qvector.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qdebug.h>
+
+#include <pcre.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QRegularExpression
+ \reentrant
+
+ \brief The QRegularExpression class provides pattern matching using regular
+ expressions.
+
+ \since 5.0
+
+ \ingroup tools
+ \ingroup shared
+
+ \keyword regular expression
+
+ Regular expressions, or \e{regexps}, are a very powerful tool to handle
+ strings and texts. This is useful in many contexts, e.g.,
+
+ \table
+ \row \li Validation
+ \li A regexp can test whether a substring meets some criteria,
+ e.g. is an integer or contains no whitespace.
+ \row \li Searching
+ \li A regexp provides more powerful pattern matching than
+ simple substring matching, e.g., match one of the words
+ \e{mail}, \e{letter} or \e{correspondence}, but none of the
+ words \e{email}, \e{mailman}, \e{mailer}, \e{letterbox}, etc.
+ \row \li Search and Replace
+ \li A regexp can replace all occurrences of a substring with a
+ different substring, e.g., replace all occurrences of \e{&}
+ with \e{\&amp;} except where the \e{&} is already followed by
+ an \e{amp;}.
+ \row \li String Splitting
+ \li A regexp can be used to identify where a string should be
+ split apart, e.g. splitting tab-delimited strings.
+ \endtable
+
+ This document is by no means a complete reference to pattern matching using
+ regular expressions, and the following parts will require the reader to
+ have some basic knowledge about Perl-like regular expressions and their
+ pattern syntax.
+
+ Good references about regular expressions include:
+
+ \list
+ \li \e {Mastering Regular Expressions} (Third Edition) by Jeffrey E. F.
+ Friedl, ISBN 0-596-52812-4;
+ \li the \l{http://pcre.org/pcre.txt} {pcrepattern(3)} man page, describing
+ the pattern syntax supported by PCRE (the reference implementation of
+ Perl-compatible regular expressions);
+ \li the \l{http://perldoc.perl.org/perlre.html} {Perl's regular expression
+ documentation} and the \l{http://perldoc.perl.org/perlretut.html} {Perl's
+ regular expression tutorial}.
+ \endlist
+
+ \tableofcontents
+
+ \section1 Introduction
+
+ QRegularExpression implements Perl-compatible regular expressions. It fully
+ supports Unicode. For an overview of the regular expression syntax
+ supported by QRegularExpression, please refer to the aforementioned
+ pcrepattern(3) man page. A regular expression is made up of two things: a
+ \b{pattern string} and a set of \b{pattern options} that change the
+ meaning of the pattern string.
+
+ You can set the pattern string by passing a string to the QRegularExpression
+ constructor:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 0
+
+ This sets the pattern string to \c{a pattern}. You can also use the
+ setPattern() function to set a pattern on an existing QRegularExpression
+ object:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 1
+
+ Note that due to C++ literal strings rules, you must escape all backslashes
+ inside the pattern string with another backslash:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 2
+
+ The pattern() function returns the pattern that it's currently set for a
+ QRegularExpression object:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 3
+
+ \section1 Pattern options
+
+ The meaning of the pattern string can be modified by setting one or more
+ \e{pattern options}. For instance, it is possible to set a pattern to match
+ case insensitively by setting the QRegularExpression::CaseInsensitiveOption.
+
+ You can set the options by passing them to the QRegularExpression
+ constructor, as in:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 4
+
+ Alternatively, you can use the setPatternOptions() function on an existing
+ QRegularExpressionObject:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 5
+
+ It is possible to get the pattern options currently set on a
+ QRegularExpression object by using the patternOptions() function:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 6
+
+ Please refer to the QRegularExpression::PatternOption enum documentation for
+ more information about each pattern option.
+
+ \section1 Match type and match options
+
+ The last two arguments of the match() and the globalMatch() functions set
+ the match type and the match options. The match type is a value of the
+ QRegularExpression::MatchType enum; the "traditional" matching algorithm is
+ chosen by using the NormalMatch match type (the default). It is also
+ possible to enable partial matching of the regular expression against a
+ subject string: see the \l{partial matching} section for more details.
+
+ The match options are a set of one or more QRegularExpression::MatchOption
+ values. They change the way a specific match of a regular expression
+ against a subject string is done. Please refer to the
+ QRegularExpression::MatchOption enum documentation for more details.
+
+ \target normal matching
+ \section1 Normal matching
+
+ In order to perform a match you can simply invoke the match() function
+ passing a string to match against. We refer to this string as the
+ \e{subject string}. The result of the match() function is a
+ QRegularExpressionMatch object that can be used to inspect the results of
+ the match. For instance:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 7
+
+ If a match is successful, the (implicit) capturing group number 0 can be
+ used to retrieve the substring matched by the entire pattern (see also the
+ section about \l{extracting captured substrings}):
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 8
+
+ It's also possible to start a match at an arbitrary offset inside the
+ subject string by passing the offset as an argument of the
+ match() function. In the following example \c{"12 abc"}
+ is not matched because the match is started at offset 1:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 9
+
+ \target extracting captured substrings
+ \section2 Extracting captured substrings
+
+ The QRegularExpressionMatch object contains also information about the
+ substrings captured by the capturing groups in the pattern string. The
+ \l{QRegularExpressionMatch::}{captured()} function will return the string
+ captured by the n-th capturing group:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 10
+
+ Capturing groups in the pattern are numbered starting from 1, and the
+ implicit capturing group 0 is used to capture the substring that matched
+ the entire pattern.
+
+ It's also possible to retrieve the starting and the ending offsets (inside
+ the subject string) of each captured substring, by using the
+ \l{QRegularExpressionMatch::}{capturedStart()} and the
+ \l{QRegularExpressionMatch::}{capturedEnd()} functions:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 11
+
+ All of these functions have an overload taking a QString as a parameter
+ in order to extract \e{named} captured substrings. For instance:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 12
+
+ \target global matching
+ \section1 Global matching
+
+ \e{Global matching} is useful to find all the occurrences of a given
+ regular expression inside a subject string. Suppose that we want to extract
+ all the words from a given string, where a word is a substring matching
+ the pattern \c{\w+}.
+
+ QRegularExpression::globalMatch returns a QRegularExpressionMatchIterator,
+ which is a Java-like forward iterator that can be used to iterate over the
+ results. For instance:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 13
+
+ Since it's a Java-like iterator, the QRegularExpressionMatchIterator will
+ point immediately before the first result. Every result is returned as a
+ QRegularExpressionMatch object. The
+ \l{QRegularExpressionMatchIterator::}{hasNext()} function will return true
+ if there's at least one more result, and
+ \l{QRegularExpressionMatchIterator::}{next()} will return the next result
+ and advance the iterator. Continuing from the previous example:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 14
+
+ You can also use \l{QRegularExpressionMatchIterator::}{peekNext()} to get
+ the next result without advancing the iterator.
+
+ It is possible to pass a starting offset and one or more match options to
+ the globalMatch() function, exactly like normal matching with match().
+
+ \target partial matching
+ \section1 Partial matching
+
+ A \e{partial match} is obtained when the end of the subject string is
+ reached, but more characters are needed to successfully complete the match.
+ Note that a partial match is usually much more inefficient than a normal
+ match because many optimizations of the matching algorithm cannot be
+ employed.
+
+ A partial match must be explicitly requested by specifying a match type of
+ PartialPreferCompleteMatch or PartialPreferFirstMatch when calling
+ QRegularExpression::match or QRegularExpression::globalMatch. If a partial
+ match is found, then calling the \l{QRegularExpressionMatch::}{hasMatch()}
+ function on the QRegularExpressionMatch object returned by match() will
+ return \c{false}, but \l{QRegularExpressionMatch::}{hasPartialMatch()} will return
+ \c{true}.
+
+ When a partial match is found, no captured substrings are returned, and the
+ (implicit) capturing group 0 corresponding to the whole match captures the
+ partially matched substring of the subject string.
+
+ Note that asking for a partial match can still lead to a complete match, if
+ one is found; in this case, \l{QRegularExpressionMatch::}{hasMatch()} will
+ return \c{true} and \l{QRegularExpressionMatch::}{hasPartialMatch()}
+ \c{false}. It never happens that a QRegularExpressionMatch reports both a
+ partial and a complete match.
+
+ Partial matching is mainly useful in two scenarios: validating user input
+ in real time and incremental/multi-segment matching.
+
+ \target
+ \section2 Validating user input
+
+ Suppose that we would like the user to input a date in a specific
+ format, for instance "MMM dd, yyyy". We can check the input validity with
+ a pattern like:
+
+ \c{^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d\d?, \d\d\d\d$}
+
+ (This pattern doesn't catch invalid days, but let's keep it for the
+ example's purposes).
+
+ We would like to validate the input with this regular expression \e{while}
+ the user is typing it, so that we can report an error in the input as soon
+ as it is committed (for instance, the user typed the wrong key). In order
+ to do so we must distinguish three cases:
+
+ \list
+ \li the input cannot possibly match the regular expression;
+ \li the input does match the regular expression;
+ \li the input does not match the regular expression right now,
+ but it will if more charaters will be added to it.
+ \endlist
+
+ Note that these three cases represent exactly the possible states of a
+ QValidator (see the QValidator::State enum).
+
+ In particular, in the last case we want the regular expression engine to
+ report a partial match: we are successfully matching the pattern against
+ the subject string but the matching cannot continue because the end of the
+ subject is encountered. Notice, however, that the matching algorithm should
+ continue and try all possibilities, and in case a complete (non-partial)
+ match is found, then this one should be reported, and the input string
+ accepted as fully valid.
+
+ This behaviour is implemented by the PartialPreferCompleteMatch match type.
+ For instance:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 15
+
+ If matching the same regular expression against the subject string leads to
+ a complete match, it is reported as usual:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 16
+
+ Another example with a different pattern, showing the behaviour of
+ preferring a complete match over a partial one:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 17
+
+ In this case, the subpattern \c{abc\\w+X} partially matches the subject
+ string; however, the subpattern \c{def} matches the subject string
+ completely, and therefore a complete match is reported.
+
+ In case multiple partial matches are found when matching (but no complete
+ match), then the QRegularExpressionMatch will report the first one that it
+ is found. For instance:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 18
+
+ \section2 Incremental/multi-segment matching
+
+ Incremental matching is another use case of partial matching. Suppose that
+ we want to find the occurrences of a regular expression inside a large text
+ (that is, substrings matching the regular expression). In order to do so we
+ would like to "feed" the large text to the regular expression engines in
+ smaller chunks. The obvious problem is what happens if the substring that
+ matches the regular expression spans across two or more chunks.
+
+ In this case, the regular expression engine should report a partial match,
+ so that we can match again adding new data and (eventually) get a complete
+ match. This implies that the regular expression engine may assume that
+ there are other characters \e{beyond the end} of the subject string. This
+ is not to be taken literally -- the engine will never try to access
+ any character after the last one in the subject.
+
+ QRegularExpression implements this behaviour when using the
+ PartialPreferFirstMatch match type. This match type reports a partial match
+ as soon as it is found, and other match alternatives are not tried
+ (even if they could lead to a complete match). For instance:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 19
+
+ This happens because when matching the first branch of the alternation
+ operator a partial match is found, and therefore matching stops, without
+ trying the second branch. Another example:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 20
+
+ This shows what could seem a counterintuitve behaviour of quantifiers:
+ since \c{?} is greedy, then the engine tries first to continue the match
+ after having matched \c{"abc"}; but then the matching reaches the end of the
+ subject string, and therefore a partial match is reported. This is
+ even more surprising in the following example:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 21
+
+ It's easy to understand this behaviour if we remember that the engine
+ expects the subject string to be only a substring of the whole text we're
+ looking for a match into (that is, how we said before, that the engine
+ assumes that there are other characters beyond the end of the subject
+ string).
+
+ Since the \c{*} quantifier is greedy, then reporting a complete match could
+ be an error, because after the current subject \c{"abc"} there may be other
+ occurrences of \c{"abc"}. For instance, the complete text could have been
+ "abcabcX", and therefore the \e{right} match to report (in the complete
+ text) would have been \c{"abcabc"}; by matching only against the leading
+ \c{"abc"} we instead get a partial match.
+
+ \section1 Error handling
+
+ It is possible for a QRegularExpression object to be invalid because of
+ syntax errors in the pattern string. The isValid() function will return
+ true if the regular expression is valid, or false otherwise:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 22
+
+ You can get more information about the specific error by calling the
+ errorString() function; moreover, the patternErrorOffset() function
+ will return the offset inside the pattern string
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 23
+
+ If a match is attempted with an invalid QRegularExpression, then the
+ returned QRegularExpressionMatch object will be invalid as well (that is,
+ its \l{QRegularExpressionMatch::}{isValid()} function will return false).
+ The same applies for attempting a global match.
+
+ \section1 Unsupported Perl-compatible regular expressions features
+
+ QRegularExpression does not support all the features available in
+ Perl-compatible regular expressions. The most notable one is the fact that
+ duplicated names for capturing groups are not supported, and using them can
+ lead to undefined behaviour.
+
+ This may change in a future version of Qt.
+
+ \section1 Notes for QRegExp users
+
+ The QRegularExpression class introduced in Qt 5 is a big improvement upon
+ QRegExp, in terms of APIs offered, supported pattern syntax and speed of
+ execution. The biggest difference is that QRegularExpression simply holds a
+ regular expression, and it's \e{not} modified when a match is requested.
+ Instead, a QRegularExpressionMatch object is returned, in order to check
+ the result of a match and extract the captured substring. The same applies
+ with global matching and QRegularExpressionMatchIterator.
+
+ Other differences are outlined below.
+
+ \section2 Exact matching
+
+ QRegExp::exactMatch in Qt 4 served for two purposes: it exactly matched
+ a regular expression against a subject string, and it implemented partial
+ matching. In fact, if an exact match was not found, one could still find
+ out how much of the subject string was matched by the regular expression
+ by calling QRegExp::matchedLength(). If the returned length was equal
+ to the subject string's length, then one could desume that a partial match
+ was found.
+
+ QRegularExpression supports partial matching explicitly by means of the
+ appropriate MatchType. If instead you simply want to be sure that the
+ subject string matches the regular expression exactly, you can wrap the
+ pattern between a couple of anchoring expressions. Simply
+ putting the pattern between the \c{^} and the \c{$} anchors is enough
+ in most cases:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 24
+
+ However, remember that the \c{$} anchor not only matches at the end of the
+ string, but also at a newline character right before the end of the string;
+ that is, the previous pattern matches against the string "this pattern must
+ match exactly\n". Also, the behaviour of both the \c{^} and the \c{$}
+ anchors changes if the MultiLineOption is set either explicitely (as a
+ pattern option) or implicitly (as a directive inside the pattern string).
+
+ Therefore, in the most general case, you should wrap the pattern between
+ the \c{\A} and the \c{\z} anchors:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 25
+
+ Note the usage of the non-capturing group in order to preserve the meaning
+ of the branch operator inside the pattern.
+
+ \section2 Global matching
+
+ Due to limitations of the QRegExp API it was impossible to implement global
+ matching correctly (that is, like Perl does). In particular, patterns that
+ can match 0 characters (like \c{"a*"}) are problematic.
+
+ QRegularExpression::globalMatch implements Perl global match correctly, and
+ the returned iterator can be used to examine each result.
+
+ \section2 Wildcard matching
+
+ There is no equivalent of wildcard matching in QRegularExpression.
+ Nevertheless, rewriting a regular expression in wildcard syntax to a
+ Perl-compatible regular expression is a very easy task, given the fact
+ that wildcard syntax supported by QRegExp is very simple.
+
+ \section2 Other pattern syntaxes
+
+ QRegularExpression supports only Perl-compatible regular expressions.
+
+ \section2 Minimal matching
+
+ QRegExp::setMinimal implemented minimal matching by simply reversing the
+ greediness of the quantifiers (QRegExp did not support lazy quantifiers,
+ like \c{*?}, \c{+?}, etc.). QRegularExpression instead does support greedy,
+ lazy and possessive quantifiers. The InvertedGreedinessOption
+ pattern option can be useful to emulate the effects of QRegExp::setMinimal:
+ if enabled, it inverts the greediness of quantifiers (greedy ones become
+ lazy and vice versa).
+
+ \section2 Caret modes
+
+ The AnchoredMatchOption match option can be used to emulate the
+ QRegExp::CaretAtOffset behaviour. There is no equivalent for the other
+ QRegExp::CaretMode modes.
+
+ \section1 Debugging code that uses QRegularExpression
+
+ QRegularExpression internally uses a just in time compiler (JIT) to
+ optimize the execution of the matching algorithm. The JIT makes extensive
+ usage of self-modifying code, which can lead debugging tools such as
+ Valgrind to crash. You must enable all checks for self-modifying code if
+ you want to debug programs using QRegularExpression (f.i., see Valgrind's
+ \c{--smc-check} command line option). The downside of enabling such checks
+ is that your program will run considerably slower.
+
+ To avoid that, the JIT is disabled by default if you compile Qt in debug
+ mode. It is possible to override the default and enable or disable the JIT
+ usage (both in debug or release mode) by setting the
+ \c{QT_ENABLE_REGEXP_JIT} environment variable to a non-zero or zero value
+ respectively.
+
+ \sa QRegularExpressionMatch, QRegularExpressionMatchIterator
+*/
+
+/*!
+ \class QRegularExpressionMatch
+ \reentrant
+
+ \brief The QRegularExpressionMatch class provides the results of a matching
+ a QRegularExpression against a string.
+
+ \since 5.0
+
+ \ingroup tools
+ \ingroup shared
+
+ \keyword regular expression match
+
+ A QRegularExpressionMatch object can be obtained by calling the
+ QRegularExpression::match() function, or as a single result of a global
+ match from a QRegularExpressionMatchIterator.
+
+ The success or the failure of a match attempt can be inspected by calling
+ the hasMatch() function. QRegularExpressionMatch also reports a successful
+ partial match through the hasPartialMatch() function.
+
+ In addition, QRegularExpressionMatch returns the substrings captured by the
+ capturing groups in the pattern string. The implicit capturing group with
+ index 0 captures the result of the whole match. The captured() function
+ returns each substring captured, either by the capturing group's index or
+ by its name:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 29
+
+ For each captured substring it is possible to query its starting and ending
+ offsets in the subject string by calling the capturedStart() and the
+ capturedEnd() function, respectively. The length of each captured
+ substring is available using the capturedLength() function.
+
+ The convenience function capturedTexts() will return \e{all} the captured
+ substrings at once (including the substring matched by the entire pattern)
+ in the order they have been captured by captring groups; that is,
+ \c{captured(i) == capturedTexts().at(i)}.
+
+ You can retrieve the QRegularExpression object the subject string was
+ matched against by calling the regularExpression() function; the
+ match type and the match options are available as well by calling
+ the matchType() and the matchOptions() respectively.
+
+ Please refer to the QRegularExpression documentation for more information
+ about the Qt regular expression classes.
+
+ \sa QRegularExpression
+*/
+
+/*!
+ \class QRegularExpressionMatchIterator
+ \reentrant
+
+ \brief The QRegularExpressionMatchIterator class provides an iterator on
+ the results of a global match of a QRegularExpression object against a string.
+
+ \since 5.0
+
+ \ingroup tools
+ \ingroup shared
+
+ \keyword regular expression iterator
+
+ A QRegularExpressionMatchIterator object is a forward only Java-like
+ iterator; it can be obtained by calling the
+ QRegularExpression::globalMatch() function. A new
+ QRegularExpressionMatchIterator will be positioned before the first result.
+ You can then call the hasNext() function to check if there are more
+ results available; if so, the next() function will return the next
+ result and advance the iterator.
+
+ Each result is a QRegularExpressionMatch object holding all the information
+ for that result (including captured substrings).
+
+ For instance:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 30
+
+ Moreover, QRegularExpressionMatchIterator offers a peekNext() function
+ to get the next result \e{without} advancing the iterator.
+
+ You can retrieve the QRegularExpression object the subject string was
+ matched against by calling the regularExpression() function; the
+ match type and the match options are available as well by calling
+ the matchType() and the matchOptions() respectively.
+
+ Please refer to the QRegularExpression documentation for more information
+ about the Qt regular expression classes.
+
+ \sa QRegularExpression, QRegularExpressionMatch
+*/
+
+
+/*!
+ \enum QRegularExpression::PatternOption
+
+ The PatternOption enum defines modifiers to the way the pattern string
+ should be interpreted, and therefore the way the pattern matches against a
+ subject string.
+
+ \value NoPatternOption
+ No pattern options are set.
+
+ \value CaseInsensitiveOption
+ The pattern should match against the subject string in a case
+ insensitive way. This option corresponds to the /i modifier in Perl
+ regular expressions.
+
+ \value DotMatchesEverythingOption
+ The dot metacharacter (\c{.}) in the pattern string is allowed to match
+ any character in the subject string, including newlines (normally, the
+ dot does not match newlines). This option corresponds to the \c{/s}
+ modifier in Perl regular expressions.
+
+ \value MultilineOption
+ The caret (\c{^}) and the dollar (\c{$}) metacharacters in the pattern
+ string are allowed to match, respectively, immediately after and
+ immediately before any newline in the subject string, as well as at the
+ very beginning and at the very end of the subject string. This option
+ corresponds to the \c{/m} modifier in Perl regular expressions.
+
+ \value ExtendedPatternSyntaxOption
+ Any whitespace in the pattern string which is not escaped and outside a
+ character class is ignored. Moreover, an unescaped sharp (\b{#})
+ outside a character class causes all the following characters, until
+ the first newline (included), to be ignored. This can be used to
+ increase the readability of a pattern string as well as put comments
+ inside regular expressions; this is particulary useful if the pattern
+ string is loaded from a file or written by the user, because in C++
+ code it is always possible to use the rules for string literals to put
+ comments outside the pattern string. This option corresponds to the \c{/x}
+ modifier in Perl regular expressions.
+
+ \value InvertedGreedinessOption
+ The greediness of the quantifiers is inverted: \c{*}, \c{+}, \c{?},
+ \c{{m,n}}, etc. become lazy, while their lazy versions (\c{*?},
+ \c{+?}, \c{??}, \c{{m,n}?}, etc.) become greedy. There is no equivalent
+ for this option in Perl regular expressions.
+
+ \value DontCaptureOption
+ The non-named capturing groups do not capture substrings; named
+ capturing groups still work as intended, as well as the implicit
+ capturing group number 0 corresponding to the entire match. There is no
+ equivalent for this option in Perl regular expressions.
+
+ \value UseUnicodePropertiesOption
+ The meaning of the \c{\w}, \c{\d}, etc., character types, as well as
+ the meaning of their counterparts (\c{\W}, \c{\D}, etc.), is changed
+ from matching ASCII charaters only to matching any character with the
+ corresponding Unicode property. For instance, \c{\d} is changed to
+ match any character with the Unicode Nd (decimal digit) property;
+ \c{\w} to match any character with either the Unicode L (letter) or N
+ (digit) property, plus underscore, and so on. This option corresponds
+ to the \c{/u} modifier in Perl regular expressions.
+*/
+
+/*!
+ \enum QRegularExpression::MatchType
+
+ The MatchType enum defines the type of the match that should be attempted
+ against the subject string.
+
+ \value NormalMatch
+ A normal match is done.
+
+ \value PartialPreferCompleteMatch
+ The pattern string is matched partially against the subject string. If
+ a partial match is found, then it is recorded, and other matching
+ alternatives are tried as usual. If a complete match is then found,
+ then it's preferred to the partial match; in this case only the
+ complete match is reported. If instead no complete match is found (but
+ only the partial one), then the partial one is reported.
+
+ \value PartialPreferFirstMatch
+ The pattern string is matched partially against the subject string. If
+ a partial match is found, then matching stops and the partial match is
+ reported. In this case, other matching alternatives (potentially
+ leading to a complete match) are not tried. Moreover, this match type
+ assumes that the subject string only a substring of a larger text, and
+ that (in this text) there are other characters beyond the end of the
+ subject string. This can lead to surprising results; see the discussion
+ in the \l{partial matching} section for more details.
+*/
+
+/*!
+ \enum QRegularExpression::MatchOption
+
+ \value NoMatchOption
+ No match options are set.
+
+ \value AnchoredMatchOption
+ The match is constrained to start exactly at the offset passed to
+ match() in order to be successful, even if the pattern string does not
+ contain any metacharacter that anchors the match at that point.
+*/
+
+// after how many usages we optimize the regexp
+#ifdef QT_BUILD_INTERNAL
+Q_AUTOTEST_EXPORT unsigned int qt_qregularexpression_optimize_after_use_count = 10;
+#else
+static const unsigned int qt_qregularexpression_optimize_after_use_count = 10;
+#endif // QT_BUILD_INTERNAL
+
+/*!
+ \internal
+*/
+static int convertToPcreOptions(QRegularExpression::PatternOptions patternOptions)
+{
+ int options = 0;
+
+ if (patternOptions & QRegularExpression::CaseInsensitiveOption)
+ options |= PCRE_CASELESS;
+ if (patternOptions & QRegularExpression::DotMatchesEverythingOption)
+ options |= PCRE_DOTALL;
+ if (patternOptions & QRegularExpression::MultilineOption)
+ options |= PCRE_MULTILINE;
+ if (patternOptions & QRegularExpression::ExtendedPatternSyntaxOption)
+ options |= PCRE_EXTENDED;
+ if (patternOptions & QRegularExpression::InvertedGreedinessOption)
+ options |= PCRE_UNGREEDY;
+ if (patternOptions & QRegularExpression::DontCaptureOption)
+ options |= PCRE_NO_AUTO_CAPTURE;
+ if (patternOptions & QRegularExpression::UseUnicodePropertiesOption)
+ options |= PCRE_UCP;
+
+ return options;
+}
+
+/*!
+ \internal
+*/
+static int convertToPcreOptions(QRegularExpression::MatchOptions matchOptions)
+{
+ int options = 0;
+
+ if (matchOptions & QRegularExpression::AnchoredMatchOption)
+ options |= PCRE_ANCHORED;
+
+ return options;
+}
+
+struct QRegularExpressionPrivate : QSharedData
+{
+ QRegularExpressionPrivate();
+ ~QRegularExpressionPrivate();
+ QRegularExpressionPrivate(const QRegularExpressionPrivate &other);
+
+ void cleanCompiledPattern();
+ void compilePattern();
+ void getPatternInfo();
+ pcre16_extra *optimizePattern();
+
+ QRegularExpressionMatchPrivate *doMatch(const QString &subject,
+ int offset,
+ QRegularExpression::MatchType matchType,
+ QRegularExpression::MatchOptions matchOptions,
+ const QRegularExpressionMatchPrivate *previous = 0) const;
+
+ int captureIndexForName(const QString &name) const;
+
+ QString pattern;
+ QRegularExpression::PatternOptions patternOptions;
+
+ // *All* of the following members are set managed while holding this mutex,
+ // except for isDirty which is set to true by QRegularExpression setters
+ // (right after a detach happened).
+ // On the other hand, after the compilation and studying,
+ // it's safe to *use* (i.e. read) them from multiple threads at the same time.
+ // Therefore, doMatch doesn't need to lock this mutex.
+ QMutex mutex;
+
+ // The PCRE pointers are reference-counted by the QRegularExpressionPrivate
+ // objects themselves; when the private is copied (i.e. a detach happened)
+ // they are set to 0
+ pcre16 *compiledPattern;
+ pcre16_extra *studyData;
+ const char *errorString;
+ int errorOffset;
+ int capturingCount;
+ unsigned int usedCount;
+ bool usingCrLfNewlines;
+ bool isDirty;
+};
+
+struct QRegularExpressionMatchPrivate : QSharedData
+{
+ QRegularExpressionMatchPrivate(const QRegularExpression &re,
+ const QString &subject,
+ QRegularExpression::MatchType matchType,
+ QRegularExpression::MatchOptions matchOptions,
+ int capturingCount);
+
+ QRegularExpressionMatch nextMatch() const;
+
+ const QRegularExpression regularExpression;
+ const QString subject;
+ // the capturedOffsets vector contains pairs of (start, end) positions
+ // for each captured substring
+ QVector<int> capturedOffsets;
+
+ const QRegularExpression::MatchType matchType;
+ const QRegularExpression::MatchOptions matchOptions;
+
+ int capturedCount;
+
+ bool hasMatch;
+ bool hasPartialMatch;
+ bool isValid;
+};
+
+struct QRegularExpressionMatchIteratorPrivate : QSharedData
+{
+ QRegularExpressionMatchIteratorPrivate(const QRegularExpression &re,
+ QRegularExpression::MatchType matchType,
+ QRegularExpression::MatchOptions matchOptions,
+ const QRegularExpressionMatch &next);
+
+ bool hasNext() const;
+ QRegularExpressionMatch next;
+ const QRegularExpression regularExpression;
+ const QRegularExpression::MatchType matchType;
+ const QRegularExpression::MatchOptions matchOptions;
+};
+
+/*!
+ \internal
+*/
+QRegularExpression::QRegularExpression(QRegularExpressionPrivate &dd)
+ : d(&dd)
+{
+}
+
+/*!
+ \internal
+*/
+QRegularExpressionPrivate::QRegularExpressionPrivate()
+ : pattern(), patternOptions(0),
+ mutex(),
+ compiledPattern(0), studyData(0),
+ errorString(0), errorOffset(-1),
+ capturingCount(0),
+ usedCount(0),
+ usingCrLfNewlines(false),
+ isDirty(true)
+{
+}
+
+/*!
+ \internal
+*/
+QRegularExpressionPrivate::~QRegularExpressionPrivate()
+{
+ cleanCompiledPattern();
+}
+
+/*!
+ \internal
+
+ Copies the private, which means copying only the pattern and the pattern
+ options. The compiledPattern and the studyData pointers are NOT copied (we
+ do not own them any more), and in general all the members set when
+ compiling a pattern are set to default values. isDirty is set back to true
+ so that the pattern has to be recompiled again.
+*/
+QRegularExpressionPrivate::QRegularExpressionPrivate(const QRegularExpressionPrivate &other)
+ : QSharedData(other),
+ pattern(other.pattern), patternOptions(other.patternOptions),
+ mutex(),
+ compiledPattern(0), studyData(0),
+ errorString(0),
+ errorOffset(-1), capturingCount(0),
+ usedCount(0),
+ usingCrLfNewlines(false), isDirty(true)
+{
+}
+
+/*!
+ \internal
+*/
+void QRegularExpressionPrivate::cleanCompiledPattern()
+{
+ pcre16_free(compiledPattern);
+ pcre16_free_study(studyData);
+ usedCount = 0;
+ compiledPattern = 0;
+ studyData = 0;
+ usingCrLfNewlines = false;
+ errorOffset = -1;
+ capturingCount = 0;
+}
+
+/*!
+ \internal
+*/
+void QRegularExpressionPrivate::compilePattern()
+{
+ QMutexLocker lock(&mutex);
+
+ if (!isDirty)
+ return;
+
+ isDirty = false;
+ cleanCompiledPattern();
+
+ int options = convertToPcreOptions(patternOptions);
+ options |= PCRE_UTF16;
+
+ int errorCode;
+ compiledPattern = pcre16_compile2(pattern.utf16(), options,
+ &errorCode, &errorString, &errorOffset, 0);
+
+ if (!compiledPattern)
+ return;
+
+ Q_ASSERT(errorCode == 0);
+ Q_ASSERT(studyData == 0); // studying (=>optimizing) is always done later
+ errorOffset = -1;
+
+ getPatternInfo();
+}
+
+/*!
+ \internal
+*/
+void QRegularExpressionPrivate::getPatternInfo()
+{
+ Q_ASSERT(compiledPattern);
+
+ pcre16_fullinfo(compiledPattern, 0, PCRE_INFO_CAPTURECOUNT, &capturingCount);
+
+ // detect the settings for the newline
+ int patternNewlineSetting;
+ pcre16_fullinfo(compiledPattern, studyData, PCRE_INFO_OPTIONS, &patternNewlineSetting);
+ patternNewlineSetting &= PCRE_NEWLINE_CR | PCRE_NEWLINE_LF | PCRE_NEWLINE_CRLF
+ | PCRE_NEWLINE_ANY | PCRE_NEWLINE_ANYCRLF;
+ if (patternNewlineSetting == 0) {
+ // no option was specified in the regexp, grab PCRE build defaults
+ int pcreNewlineSetting;
+ pcre16_config(PCRE_CONFIG_NEWLINE, &pcreNewlineSetting);
+ switch (pcreNewlineSetting) {
+ case 13:
+ patternNewlineSetting = PCRE_NEWLINE_CR; break;
+ case 10:
+ patternNewlineSetting = PCRE_NEWLINE_LF; break;
+ case 3338: // (13<<8 | 10)
+ patternNewlineSetting = PCRE_NEWLINE_CRLF; break;
+ case -2:
+ patternNewlineSetting = PCRE_NEWLINE_ANYCRLF; break;
+ case -1:
+ patternNewlineSetting = PCRE_NEWLINE_ANY; break;
+ default:
+ qWarning("QRegularExpressionPrivate::compilePattern(): "
+ "PCRE_CONFIG_NEWLINE returned an unknown newline");
+ break;
+ }
+ }
+
+ usingCrLfNewlines = (patternNewlineSetting == PCRE_NEWLINE_CRLF) ||
+ (patternNewlineSetting == PCRE_NEWLINE_ANY) ||
+ (patternNewlineSetting == PCRE_NEWLINE_ANYCRLF);
+}
+
+/*!
+ \internal
+*/
+static bool isJitEnabled()
+{
+ QByteArray jitEnvironment = qgetenv("QT_ENABLE_REGEXP_JIT");
+ if (!jitEnvironment.isEmpty()) {
+ bool ok;
+ int enableJit = jitEnvironment.toInt(&ok);
+ return ok ? (enableJit != 0) : true;
+ }
+
+#ifdef QT_DEBUG
+ return false;
+#else
+ return true;
+#endif
+}
+
+/*!
+ \internal
+
+ The purpose of the function is to call pcre16_study (which allows some
+ optimizations to be performed, including JIT-compiling the pattern), and
+ setting the studyData member variable to the result of the study. It gets
+ called by doMatch() every time a match is performed. As of now, the
+ optimizations on the pattern are performed after a certain number of usages
+ (i.e. the qt_qregularexpression_optimize_after_use_count constant).
+
+ Notice that although the method is protected by a mutex, one thread may
+ invoke this function and return immediately (i.e. not study the pattern,
+ leaving studyData to NULL); but before calling pcre16_exec to perform the
+ match, another thread performs the studying and sets studyData to something
+ else. Although the assignment to studyData is itself atomic, the release of
+ the memory pointed by studyData isn't. Therefore, the current studyData
+ value is returned and used by doMatch.
+*/
+pcre16_extra *QRegularExpressionPrivate::optimizePattern()
+{
+ Q_ASSERT(compiledPattern);
+
+ QMutexLocker lock(&mutex);
+
+ if (studyData || (++usedCount != qt_qregularexpression_optimize_after_use_count))
+ return studyData;
+
+ static const bool enableJit = isJitEnabled();
+
+ int studyOptions = 0;
+ if (enableJit)
+ studyOptions |= PCRE_STUDY_JIT_COMPILE;
+
+ const char *err;
+ studyData = pcre16_study(compiledPattern, studyOptions, &err);
+
+ if (!studyData && err)
+ qWarning("QRegularExpressionPrivate::optimizePattern(): pcre_study failed: %s", err);
+
+ return studyData;
+}
+
+/*!
+ \internal
+
+ Returns the capturing group number for the given name. Duplicated names for
+ capturing groups are not supported.
+*/
+int QRegularExpressionPrivate::captureIndexForName(const QString &name) const
+{
+ Q_ASSERT(!name.isEmpty());
+
+ int index = pcre16_get_stringnumber(compiledPattern, name.utf16());
+ if (index >= 0)
+ return index;
+
+ return -1;
+}
+
+/*!
+ \internal
+
+ Performs a match of type \a matchType on the given \a subject string with
+ options \a matchOptions and returns the QRegularExpressionMatchPrivate of
+ the result. It also advances a match if a previous result is given as \a
+ previous.
+
+ Advancing a match is a tricky algorithm. If the previous match matched a
+ non-empty string, we just do an ordinary match at the offset position.
+
+ If the previous match matched an empty string, then an anchored, non-empty
+ match is attempted at the offset position. If that succeeds, then we got
+ the next match and we can return it. Otherwise, we advance by 1 position
+ (which can be one or two code units in UTF-16!) and reattempt a "normal"
+ match. We also have the problem of detecting the current newline format: if
+ the new advanced offset is pointing to the beginning of a CRLF sequence, we
+ must advance over it.
+*/
+QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString &subject,
+ int offset,
+ QRegularExpression::MatchType matchType,
+ QRegularExpression::MatchOptions matchOptions,
+ const QRegularExpressionMatchPrivate *previous) const
+{
+ if (offset < 0)
+ offset += subject.length();
+
+ QRegularExpression re(*const_cast<QRegularExpressionPrivate *>(this));
+
+ if (offset < 0 || offset > subject.length())
+ return new QRegularExpressionMatchPrivate(re, subject, matchType, matchOptions, 0);
+
+ if (!compiledPattern) {
+ qWarning("QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object");
+ return new QRegularExpressionMatchPrivate(re, subject, matchType, matchOptions, 0);
+ }
+
+ QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject,
+ matchType, matchOptions,
+ capturingCount);
+
+ // this is mutex protected
+ const pcre16_extra *currentStudyData = const_cast<QRegularExpressionPrivate *>(this)->optimizePattern();
+
+ int pcreOptions = convertToPcreOptions(matchOptions);
+
+ if (matchType == QRegularExpression::PartialPreferCompleteMatch)
+ pcreOptions |= PCRE_PARTIAL_SOFT;
+ else if (matchType == QRegularExpression::PartialPreferFirstMatch)
+ pcreOptions |= PCRE_PARTIAL_HARD;
+
+ bool previousMatchWasEmpty = false;
+ if (previous && previous->hasMatch &&
+ (previous->capturedOffsets.at(0) == previous->capturedOffsets.at(1))) {
+ previousMatchWasEmpty = true;
+ }
+
+ int * const captureOffsets = priv->capturedOffsets.data();
+ const int captureOffsetsCount = priv->capturedOffsets.size();
+
+ const unsigned short * const subjectUtf16 = subject.utf16();
+ const int subjectLength = subject.length();
+
+ int result;
+
+ if (!previousMatchWasEmpty) {
+ result = pcre16_exec(compiledPattern, currentStudyData,
+ subjectUtf16, subjectLength,
+ offset, pcreOptions,
+ captureOffsets, captureOffsetsCount);
+ } else {
+ result = pcre16_exec(compiledPattern, currentStudyData,
+ subjectUtf16, subjectLength,
+ offset, pcreOptions | PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED,
+ captureOffsets, captureOffsetsCount);
+
+ if (result == PCRE_ERROR_NOMATCH) {
+ ++offset;
+
+ if (usingCrLfNewlines
+ && offset < subjectLength
+ && subjectUtf16[offset - 1] == QLatin1Char('\r')
+ && subjectUtf16[offset] == QLatin1Char('\n')) {
+ ++offset;
+ } else if (offset < subjectLength
+ && QChar::isLowSurrogate(subjectUtf16[offset])) {
+ ++offset;
+ }
+
+ result = pcre16_exec(compiledPattern, currentStudyData,
+ subjectUtf16, subjectLength,
+ offset, pcreOptions,
+ captureOffsets, captureOffsetsCount);
+ }
+ }
+
+#ifdef QREGULAREXPRESSION_DEBUG
+ qDebug() << "Matching" << pattern << "against" << subject
+ << offset << matchType << matchOptions << previousMatchWasEmpty
+ << "result" << result;
+#endif
+
+ // result == 0 means not enough space in captureOffsets; should never happen
+ Q_ASSERT(result != 0);
+
+ if (result > 0) {
+ // full match
+ priv->isValid = true;
+ priv->hasMatch = true;
+ priv->capturedCount = result;
+ priv->capturedOffsets.resize(result * 2);
+ } else {
+ // no match, partial match or error
+ priv->hasPartialMatch = (result == PCRE_ERROR_PARTIAL);
+ priv->isValid = (result == PCRE_ERROR_NOMATCH || result == PCRE_ERROR_PARTIAL);
+
+ if (result == PCRE_ERROR_PARTIAL) {
+ // partial match:
+ // leave the start and end capture offsets (i.e. cap(0))
+ priv->capturedCount = 1;
+ priv->capturedOffsets.resize(2);
+ } else {
+ // no match or error
+ priv->capturedCount = 0;
+ priv->capturedOffsets.clear();
+ }
+ }
+
+ return priv;
+}
+
+/*!
+ \internal
+*/
+QRegularExpressionMatchPrivate::QRegularExpressionMatchPrivate(const QRegularExpression &re,
+ const QString &subject,
+ QRegularExpression::MatchType matchType,
+ QRegularExpression::MatchOptions matchOptions,
+ int capturingCount)
+ : regularExpression(re), subject(subject),
+ matchType(matchType), matchOptions(matchOptions),
+ capturedCount(0),
+ hasMatch(false), hasPartialMatch(false), isValid(false)
+{
+ Q_ASSERT(capturingCount >= 0);
+ const int captureOffsetsCount = (capturingCount + 1) * 3;
+ capturedOffsets.resize(captureOffsetsCount);
+}
+
+
+/*!
+ \internal
+*/
+QRegularExpressionMatch QRegularExpressionMatchPrivate::nextMatch() const
+{
+ Q_ASSERT(isValid);
+ Q_ASSERT(hasMatch || hasPartialMatch);
+
+ QRegularExpressionMatchPrivate *nextPrivate = regularExpression.d->doMatch(subject,
+ capturedOffsets.at(1),
+ matchType,
+ matchOptions,
+ this);
+ return QRegularExpressionMatch(*nextPrivate);
+}
+
+/*!
+ \internal
+*/
+QRegularExpressionMatchIteratorPrivate::QRegularExpressionMatchIteratorPrivate(const QRegularExpression &re,
+ QRegularExpression::MatchType matchType,
+ QRegularExpression::MatchOptions matchOptions,
+ const QRegularExpressionMatch &next)
+ : next(next),
+ regularExpression(re),
+ matchType(matchType), matchOptions(matchOptions)
+{
+}
+
+/*!
+ \internal
+*/
+bool QRegularExpressionMatchIteratorPrivate::hasNext() const
+{
+ return next.isValid() && (next.hasMatch() || next.hasPartialMatch());
+}
+
+// PUBLIC API
+
+/*!
+ Constructs a QRegularExpression object with an empty pattern and no pattern
+ options.
+
+ \sa setPattern(), setPatternOptions()
+*/
+QRegularExpression::QRegularExpression()
+ : d(new QRegularExpressionPrivate)
+{
+}
+
+/*!
+ Constructs a QRegularExpression object using the given \a pattern as
+ pattern and the \a options as the pattern options.
+
+ \sa setPattern(), setPatternOptions()
+*/
+QRegularExpression::QRegularExpression(const QString &pattern, PatternOptions options)
+ : d(new QRegularExpressionPrivate)
+{
+ d->pattern = pattern;
+ d->patternOptions = options;
+}
+
+/*!
+ Constructs a QRegularExpression object as a copy of \a re.
+
+ \sa operator=()
+*/
+QRegularExpression::QRegularExpression(const QRegularExpression &re)
+ : d(re.d)
+{
+}
+
+/*!
+ Destroys the QRegularExpression object.
+*/
+QRegularExpression::~QRegularExpression()
+{
+}
+
+/*!
+ Assigns the regular expression \a re to this object, and returns a reference
+ to the copy. Both the pattern and the pattern options are copied.
+*/
+QRegularExpression &QRegularExpression::operator=(const QRegularExpression &re)
+{
+ d = re.d;
+ return *this;
+}
+
+/*!
+ \fn void QRegularExpression::swap(QRegularExpression &other)
+
+ Swaps the regular expression \a other with this regular expression. This
+ operation is very fast and never fails.
+*/
+
+/*!
+ Returns the pattern string of the regular expression.
+
+ \sa setPattern(), patternOptions()
+*/
+QString QRegularExpression::pattern() const
+{
+ return d->pattern;
+}
+
+/*!
+ Sets the pattern string of the regular expression to \a pattern. The
+ pattern options are left unchanged.
+
+ \sa pattern(), setPatternOptions()
+*/
+void QRegularExpression::setPattern(const QString &pattern)
+{
+ d.detach();
+ d->isDirty = true;
+ d->pattern = pattern;
+}
+
+/*!
+ Returns the pattern options for the regular expression.
+
+ \sa setPatternOptions(), pattern()
+*/
+QRegularExpression::PatternOptions QRegularExpression::patternOptions() const
+{
+ return d->patternOptions;
+}
+
+/*!
+ Sets the given \a options as the pattern options of the regular expression.
+ The pattern string is left unchanged.
+
+ \sa patternOptions(), setPattern()
+*/
+void QRegularExpression::setPatternOptions(PatternOptions options)
+{
+ d.detach();
+ d->isDirty = true;
+ d->patternOptions = options;
+}
+
+/*!
+ Returns the number of capturing groups inside the pattern string,
+ or -1 if the regular expression is not valid.
+
+ \sa isValid()
+*/
+int QRegularExpression::captureCount() const
+{
+ if (!isValid()) // will compile the pattern
+ return -1;
+ return d->capturingCount;
+}
+
+/*!
+ Returns true if the regular expression is a valid regular expression (that
+ is, it contains no syntax errors, etc.), or false otherwise. Use
+ errorString() to obtain a textual description of the error.
+
+ \sa errorString(), patternErrorOffset()
+*/
+bool QRegularExpression::isValid() const
+{
+ d.data()->compilePattern();
+ return d->compiledPattern;
+}
+
+/*!
+ Returns a textual description of the error found when checking the validity
+ of the regular expression, or "no error" if no error was found.
+
+ \sa isValid(), patternErrorOffset()
+*/
+QString QRegularExpression::errorString() const
+{
+ d.data()->compilePattern();
+ if (d->errorString)
+ return QCoreApplication::translate("QRegularExpression", d->errorString, 0, QCoreApplication::UnicodeUTF8);
+ return QCoreApplication::translate("QRegularExpression", "no error", 0, QCoreApplication::UnicodeUTF8);
+}
+
+/*!
+ Returns the offset, inside the pattern string, at which an error was found
+ when checking the validity of the regular expression. If no error was
+ found, then -1 is returned.
+
+ \sa pattern(), isValid(), errorString()
+*/
+int QRegularExpression::patternErrorOffset() const
+{
+ d.data()->compilePattern();
+ return d->errorOffset;
+}
+
+/*!
+ Attempts to match the regular expression against the given \a subject
+ string, starting at the position \a offset inside the subject, using a
+ match of type \a matchType and honoring the given \a matchOptions.
+
+ The returned QRegularExpressionMatch object contains the results of the
+ match.
+
+ \sa QRegularExpressionMatch, {normal matching}
+*/
+QRegularExpressionMatch QRegularExpression::match(const QString &subject,
+ int offset,
+ MatchType matchType,
+ MatchOptions matchOptions) const
+{
+ d.data()->compilePattern();
+
+ QRegularExpressionMatchPrivate *priv = d->doMatch(subject, offset, matchType, matchOptions);
+ return QRegularExpressionMatch(*priv);
+}
+
+/*!
+ Attempts to perform a global match of the regular expression against the
+ given \a subject string, starting at the position \a offset inside the
+ subject, using a match of type \a matchType and honoring the given \a
+ matchOptions.
+
+ The returned QRegularExpressionMatchIterator is positioned before the
+ first match result (if any).
+
+ \sa QRegularExpressionMatchIterator, {global matching}
+*/
+QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QString &subject,
+ int offset,
+ MatchType matchType,
+ MatchOptions matchOptions) const
+{
+ QRegularExpressionMatchIteratorPrivate *priv =
+ new QRegularExpressionMatchIteratorPrivate(*this,
+ matchType,
+ matchOptions,
+ match(subject, offset, matchType, matchOptions));
+
+ return QRegularExpressionMatchIterator(*priv);
+}
+
+/*!
+ Returns true if the regular expression is equal to \a re, or false
+ otherwise. Two QRegularExpression objects are equal if they have
+ the same pattern string and the same pattern options.
+
+ \sa operator!=()
+*/
+bool QRegularExpression::operator==(const QRegularExpression &re) const
+{
+ return (d == re.d) ||
+ (d->pattern == re.d->pattern && d->patternOptions == re.d->patternOptions);
+}
+
+/*!
+ \fn bool QRegularExpression::operator!=(const QRegularExpression &re) const
+
+ Returns true if the regular expression is different from \a re, or
+ false otherwise.
+
+ \sa operator==()
+*/
+
+/*!
+ Escapes all characters of \a str so that they no longer have any special
+ meaning when used as a regular expression pattern string, and returns
+ the escaped string. For instance:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 26
+
+ This is very convenient in order to build patterns from arbitrary strings:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 27
+
+ \note This function implements Perl's quotemeta algorithm and escapes with
+ a backslash all characters in \a str, except for the characters in the
+ \c{[A-Z]}, \c{[a-z]} and \c{[0-9]} ranges, as well as the underscore
+ (\c{_}) character. The only difference with Perl is that a literal NUL
+ inside \a str is escaped with the sequence \c{"\\\\0"} (backslash +
+ \c{'0'}), instead of \c{"\\\\\\0"} (backslash + \c{NUL}).
+*/
+QString QRegularExpression::escape(const QString &str)
+{
+ QString result;
+ const int count = str.size();
+ result.reserve(count * 2);
+
+ // everything but [a-zA-Z0-9_] gets escaped,
+ // cf. perldoc -f quotemeta
+ for (int i = 0; i < count; ++i) {
+ const QChar current = str.at(i);
+
+ if (current == QChar::Null) {
+ // unlike Perl, a literal NUL must be escaped with
+ // "\\0" (backslash + 0) and not "\\\0" (backslash + NUL),
+ // because pcre16_compile uses a NUL-terminated string
+ result.append(QLatin1Char('\\'));
+ result.append(QLatin1Char('0'));
+ } else if ( (current < QLatin1Char('a') || current > QLatin1Char('z')) &&
+ (current < QLatin1Char('A') || current > QLatin1Char('Z')) &&
+ (current < QLatin1Char('0') || current > QLatin1Char('9')) &&
+ current != QLatin1Char('_') )
+ {
+ result.append(QLatin1Char('\\'));
+ result.append(current);
+ if (current.isHighSurrogate() && i < (count - 1))
+ result.append(str.at(++i));
+ } else {
+ result.append(current);
+ }
+ }
+
+ result.squeeze();
+ return result;
+}
+
+/*!
+ Destroys the match result.
+*/
+QRegularExpressionMatch::~QRegularExpressionMatch()
+{
+}
+
+/*!
+ Constructs a match result by copying the result of the given \a match.
+
+ \sa operator=()
+*/
+QRegularExpressionMatch::QRegularExpressionMatch(const QRegularExpressionMatch &match)
+ : d(match.d)
+{
+}
+
+/*!
+ Assigns the match result \a match to this object, and returns a reference
+ to the copy.
+*/
+QRegularExpressionMatch &QRegularExpressionMatch::operator=(const QRegularExpressionMatch &match)
+{
+ d = match.d;
+ return *this;
+}
+
+/*!
+ \fn void QRegularExpressionMatch::swap(QRegularExpressionMatch &other)
+
+ Swaps the match result \a other with this match result. This
+ operation is very fast and never fails.
+*/
+
+/*!
+ \internal
+*/
+QRegularExpressionMatch::QRegularExpressionMatch(QRegularExpressionMatchPrivate &dd)
+ : d(&dd)
+{
+}
+
+/*!
+ Returns the QRegularExpression object whose match() function returned this
+ object.
+
+ \sa QRegularExpression::match(), matchType(), matchOptions()
+*/
+QRegularExpression QRegularExpressionMatch::regularExpression() const
+{
+ return d->regularExpression;
+}
+
+
+/*!
+ Returns the match type that was used to get this QRegularExpressionMatch
+ object, that is, the match type that was passed to
+ QRegularExpression::match() or QRegularExpression::globalMatch().
+
+ \sa QRegularExpression::match(), regularExpression(), matchOptions()
+*/
+QRegularExpression::MatchType QRegularExpressionMatch::matchType() const
+{
+ return d->matchType;
+}
+
+/*!
+ Returns the match options that were used to get this
+ QRegularExpressionMatch object, that is, the match options that were passed
+ to QRegularExpression::match() or QRegularExpression::globalMatch().
+
+ \sa QRegularExpression::match(), regularExpression(), matchType()
+*/
+QRegularExpression::MatchOptions QRegularExpressionMatch::matchOptions() const
+{
+ return d->matchOptions;
+}
+
+/*!
+ Returns the index of the last capturing group that captured something,
+ including the implicit capturing group 0. This can be used to extract all
+ the substrings that were captured:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 28
+
+ Note that some of the capturing groups with an index less than
+ lastCapturedIndex() could have not matched, and therefore captured nothing.
+
+ If the regular expression did not match, this function returns -1.
+
+ \sa captured(), capturedStart(), capturedEnd(), capturedLength()
+*/
+int QRegularExpressionMatch::lastCapturedIndex() const
+{
+ return d->capturedCount - 1;
+}
+
+/*!
+ Returns the substring captured by the \a nth capturing group. If the \a nth
+ capturing group did not capture a string or doesn't exist, returns a null
+ QString.
+
+ \sa capturedRef(), lastCapturedIndex(), capturedStart(), capturedEnd(),
+ capturedLength(), QString::isNull()
+*/
+QString QRegularExpressionMatch::captured(int nth) const
+{
+ if (nth < 0 || nth > lastCapturedIndex())
+ return QString();
+
+ int start = capturedStart(nth);
+
+ if (start == -1) // didn't capture
+ return QString();
+
+ return d->subject.mid(start, capturedLength(nth));
+}
+
+/*!
+ Returns a reference to the substring captured by the \a nth capturing group.
+ If the \a nth capturing group did not capture a string or doesn't exist,
+ returns a null QStringRef.
+
+ \sa captured(), lastCapturedIndex(), capturedStart(), capturedEnd(),
+ capturedLength(), QStringRef::isNull()
+*/
+QStringRef QRegularExpressionMatch::capturedRef(int nth) const
+{
+ if (nth < 0 || nth > lastCapturedIndex())
+ return QStringRef();
+
+ int start = capturedStart(nth);
+
+ if (start == -1) // didn't capture
+ return QStringRef();
+
+ return d->subject.midRef(start, capturedLength(nth));
+}
+
+/*!
+ Returns the substring captured by the capturing group named \a name. If the
+ capturing group named \a name did not capture a string or doesn't exist,
+ returns a null QString.
+
+ \sa capturedRef(), capturedStart(), capturedEnd(), capturedLength(),
+ QString::isNull()
+*/
+QString QRegularExpressionMatch::captured(const QString &name) const
+{
+ if (name.isEmpty()) {
+ qWarning("QRegularExpressionMatch::captured: empty capturing group name passed");
+ return QString();
+ }
+ int nth = d->regularExpression.d->captureIndexForName(name);
+ if (nth == -1)
+ return QString();
+ return captured(nth);
+}
+
+/*!
+ Returns a reference to the string captured by the capturing group named \a
+ name. If the capturing group named \a name did not capture a string or
+ doesn't exist, returns a null QStringRef.
+
+ \sa captured(), capturedStart(), capturedEnd(), capturedLength(),
+ QStringRef::isNull()
+*/
+QStringRef QRegularExpressionMatch::capturedRef(const QString &name) const
+{
+ if (name.isEmpty()) {
+ qWarning("QRegularExpressionMatch::capturedRef: empty capturing group name passed");
+ return QStringRef();
+ }
+ int nth = d->regularExpression.d->captureIndexForName(name);
+ if (nth == -1)
+ return QStringRef();
+ return capturedRef(nth);
+}
+
+/*!
+ Returns a list of all strings captured by capturing groups, in the order
+ the groups themselves appear in the pattern string.
+*/
+QStringList QRegularExpressionMatch::capturedTexts() const
+{
+ QStringList texts;
+ for (int i = 0; i <= lastCapturedIndex(); ++i)
+ texts << captured(i);
+ return texts;
+}
+
+/*!
+ Returns the offset inside the subject string corresponding to the
+ starting position of the substring captured by the \a nth capturing group.
+ If the \a nth capturing group did not capture a string or doesn't exist,
+ returns -1.
+
+ \sa capturedEnd(), capturedLength(), captured()
+*/
+int QRegularExpressionMatch::capturedStart(int nth) const
+{
+ if (nth < 0 || nth > lastCapturedIndex())
+ return -1;
+
+ return d->capturedOffsets.at(nth * 2);
+}
+
+/*!
+ Returns the length of the substring captured by the \a nth capturing group.
+
+ \note This function returns 0 if the \a nth capturing group did not capture
+ a string or doesn't exist.
+
+ \sa capturedStart(), capturedEnd(), captured()
+*/
+int QRegularExpressionMatch::capturedLength(int nth) const
+{
+ // bound checking performed by these two functions
+ return capturedEnd(nth) - capturedStart(nth);
+}
+
+/*!
+ Returns the offset inside the subject string immediately after the ending
+ position of the substring captured by the \a nth capturing group. If the \a
+ nth capturing group did not capture a string or doesn't exist, returns -1.
+
+ \sa capturedStart(), capturedLength(), captured()
+*/
+int QRegularExpressionMatch::capturedEnd(int nth) const
+{
+ if (nth < 0 || nth > lastCapturedIndex())
+ return -1;
+
+ return d->capturedOffsets.at(nth * 2 + 1);
+}
+
+/*!
+ Returns the offset inside the subject string corresponding to the starting
+ position of the substring captured by the capturing group named \a name.
+ If the capturing group named \a name did not capture a string or doesn't
+ exist, returns -1.
+
+ \sa capturedEnd(), capturedLength(), captured()
+*/
+int QRegularExpressionMatch::capturedStart(const QString &name) const
+{
+ if (name.isEmpty()) {
+ qWarning("QRegularExpressionMatch::capturedStart: empty capturing group name passed");
+ return -1;
+ }
+ int nth = d->regularExpression.d->captureIndexForName(name);
+ if (nth == -1)
+ return -1;
+ return capturedStart(nth);
+}
+
+/*!
+ Returns the offset inside the subject string corresponding to the starting
+ position of the substring captured by the capturing group named \a name.
+
+ \note This function returns 0 if the capturing group named \a name did not
+ capture a string or doesn't exist.
+
+ \sa capturedStart(), capturedEnd(), captured()
+*/
+int QRegularExpressionMatch::capturedLength(const QString &name) const
+{
+ if (name.isEmpty()) {
+ qWarning("QRegularExpressionMatch::capturedLength: empty capturing group name passed");
+ return 0;
+ }
+ int nth = d->regularExpression.d->captureIndexForName(name);
+ if (nth == -1)
+ return 0;
+ return capturedLength(nth);
+}
+
+/*!
+ Returns the offset inside the subject string immediately after the ending
+ position of the substring captured by the capturing group named \a name. If
+ the capturing group named \a name did not capture a string or doesn't
+ exist, returns -1.
+
+ \sa capturedStart(), capturedLength(), captured()
+*/
+int QRegularExpressionMatch::capturedEnd(const QString &name) const
+{
+ if (name.isEmpty()) {
+ qWarning("QRegularExpressionMatch::capturedEnd: empty capturing group name passed");
+ return -1;
+ }
+ int nth = d->regularExpression.d->captureIndexForName(name);
+ if (nth == -1)
+ return -1;
+ return capturedEnd(nth);
+}
+
+/*!
+ Returns true if the regular expression matched against the subject string,
+ or false otherwise.
+
+ \sa QRegularExpression::match(), hasPartialMatch()
+*/
+bool QRegularExpressionMatch::hasMatch() const
+{
+ return d->hasMatch;
+}
+
+/*!
+ Returns true if the regular expression partially matched against the
+ subject string, or false otherwise.
+
+ \note Only a match that explicitely used the one of the partial match types
+ can yield a partial match. Still, if such a match succeeds totally, this
+ function will return false, while hasMatch() will return true.
+
+ \sa QRegularExpression::match(), QRegularExpression::MatchType, hasMatch()
+*/
+bool QRegularExpressionMatch::hasPartialMatch() const
+{
+ return d->hasPartialMatch;
+}
+
+/*!
+ Returns true if the match object was obtained as a result from the
+ QRegularExpression::match() function invoked on a valid QRegularExpression
+ object; returns false if the QRegularExpression was invalid.
+
+ \sa QRegularExpression::match(), QRegularExpression::isValid()
+*/
+bool QRegularExpressionMatch::isValid() const
+{
+ return d->isValid;
+}
+
+/*!
+ \internal
+*/
+QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(QRegularExpressionMatchIteratorPrivate &dd)
+ : d(&dd)
+{
+}
+
+/*!
+ Destroys the QRegularExpressionMatchIterator object.
+*/
+QRegularExpressionMatchIterator::~QRegularExpressionMatchIterator()
+{
+}
+
+/*!
+ Constructs a QRegularExpressionMatchIterator object as a copy of \a
+ iterator.
+
+ \sa operator=()
+*/
+QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator)
+ : d(iterator.d)
+{
+}
+
+/*!
+ Assigns the iterator \a iterator to this object, and returns a reference to
+ the copy.
+*/
+QRegularExpressionMatchIterator &QRegularExpressionMatchIterator::operator=(const QRegularExpressionMatchIterator &iterator)
+{
+ d = iterator.d;
+ return *this;
+}
+
+/*!
+ \fn void QRegularExpressionMatchIterator::swap(QRegularExpressionMatchIterator &other)
+
+ Swaps the iterator \a other with this iterator object. This operation is
+ very fast and never fails.
+*/
+
+/*!
+ Returns true if the iterator object was obtained as a result from the
+ QRegularExpression::globalMatch() function invoked on a valid
+ QRegularExpression object; returns false if the QRegularExpression was
+ invalid.
+
+ \sa QRegularExpression::globalMatch(), QRegularExpression::isValid()
+*/
+bool QRegularExpressionMatchIterator::isValid() const
+{
+ return d->next.isValid();
+}
+
+/*!
+ Returns true if there is at least one match result ahead of the iterator;
+ otherwise it returns false.
+
+ \sa next()
+*/
+bool QRegularExpressionMatchIterator::hasNext() const
+{
+ return d->hasNext();
+}
+
+/*!
+ Returns the next match result without moving the iterator.
+
+ \note Calling this function when the iterator is at the end of the result
+ set leads to undefined results.
+*/
+QRegularExpressionMatch QRegularExpressionMatchIterator::peekNext() const
+{
+ if (!hasNext())
+ qWarning("QRegularExpressionMatchIterator::peekNext() called on an iterator already at end");
+
+ return d->next;
+}
+
+/*!
+ Returns the next match result and advances the iterator by one position.
+
+ \note Calling this function when the iterator is at the end of the result
+ set leads to undefined results.
+*/
+QRegularExpressionMatch QRegularExpressionMatchIterator::next()
+{
+ if (!hasNext()) {
+ qWarning("QRegularExpressionMatchIterator::next() called on an iterator already at end");
+ return d->next;
+ }
+
+ QRegularExpressionMatch current = d->next;
+ d->next = d->next.d.constData()->nextMatch();
+ return current;
+}
+
+/*!
+ Returns the QRegularExpression object whose globalMatch() function returned
+ this object.
+
+ \sa QRegularExpression::globalMatch(), matchType(), matchOptions()
+*/
+QRegularExpression QRegularExpressionMatchIterator::regularExpression() const
+{
+ return d->regularExpression;
+}
+
+/*!
+ Returns the match type that was used to get this
+ QRegularExpressionMatchIterator object, that is, the match type that was
+ passed to QRegularExpression::globalMatch().
+
+ \sa QRegularExpression::globalMatch(), regularExpression(), matchOptions()
+*/
+QRegularExpression::MatchType QRegularExpressionMatchIterator::matchType() const
+{
+ return d->matchType;
+}
+
+/*!
+ Returns the match options that were used to get this
+ QRegularExpressionMatchIterator object, that is, the match options that
+ were passed to QRegularExpression::globalMatch().
+
+ \sa QRegularExpression::globalMatch(), regularExpression(), matchType()
+*/
+QRegularExpression::MatchOptions QRegularExpressionMatchIterator::matchOptions() const
+{
+ return d->matchOptions;
+}
+
+#ifndef QT_NO_DATASTREAM
+/*!
+ \relates QRegularExpression
+
+ Writes the regular expression \a re to stream \a out.
+
+ \sa {Serializing Qt Data Types}
+*/
+QDataStream &operator<<(QDataStream &out, const QRegularExpression &re)
+{
+ out << re.pattern() << quint32(re.patternOptions());
+ return out;
+}
+
+/*!
+ \relates QRegularExpression
+
+ Reads a regular expression from stream \a in into \a re.
+
+ \sa {Serializing Qt Data Types}
+*/
+QDataStream &operator>>(QDataStream &in, QRegularExpression &re)
+{
+ QString pattern;
+ quint32 patternOptions;
+ in >> pattern >> patternOptions;
+ re.setPattern(pattern);
+ re.setPatternOptions(QRegularExpression::PatternOptions(patternOptions));
+ return in;
+}
+#endif
+
+#ifndef QT_NO_DEBUG_STREAM
+/*!
+ \relates QRegularExpression
+
+ Writes the regular expression \a re into the debug object \a debug for
+ debugging purposes.
+
+ \sa {Debugging Techniques}
+*/
+QDebug operator<<(QDebug debug, const QRegularExpression &re)
+{
+ debug.nospace() << "QRegularExpression(" << re.pattern() << ", " << re.patternOptions() << ")";
+ return debug.space();
+}
+
+/*!
+ \relates QRegularExpression
+
+ Writes the pattern options \a patternOptions into the debug object \a debug
+ for debugging purposes.
+
+ \sa {Debugging Techniques}
+*/
+QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions patternOptions)
+{
+ QStringList flags;
+
+ if (patternOptions == QRegularExpression::NoPatternOption) {
+ flags << QLatin1String("NoPatternOption");
+ } else {
+ if (patternOptions & QRegularExpression::CaseInsensitiveOption)
+ flags << QLatin1String("CaseInsensitiveOption");
+ if (patternOptions & QRegularExpression::DotMatchesEverythingOption)
+ flags << QLatin1String("DotMatchesEverythingOption");
+ if (patternOptions & QRegularExpression::MultilineOption)
+ flags << QLatin1String("MultilineOption");
+ if (patternOptions & QRegularExpression::ExtendedPatternSyntaxOption)
+ flags << QLatin1String("ExtendedPatternSyntaxOption");
+ if (patternOptions & QRegularExpression::InvertedGreedinessOption)
+ flags << QLatin1String("InvertedGreedinessOption");
+ if (patternOptions & QRegularExpression::DontCaptureOption)
+ flags << QLatin1String("DontCaptureOption");
+ if (patternOptions & QRegularExpression::UseUnicodePropertiesOption)
+ flags << QLatin1String("UseUnicodePropertiesOption");
+ }
+
+ debug.nospace() << "QRegularExpression::PatternOptions("
+ << qPrintable(flags.join(QLatin1String("|")))
+ << ")";
+
+ return debug.space();
+}
+/*!
+ \relates QRegularExpressionMatch
+
+ Writes the match object \a match into the debug object \a debug for
+ debugging purposes.
+
+ \sa {Debugging Techniques}
+*/
+QDebug operator<<(QDebug debug, const QRegularExpressionMatch &match)
+{
+ debug.nospace() << "QRegularExpressionMatch(";
+
+ if (!match.isValid()) {
+ debug << "Invalid)";
+ return debug.space();
+ }
+
+ debug << "Valid";
+
+ if (match.hasMatch()) {
+ debug << ", has match: ";
+ for (int i = 0; i <= match.lastCapturedIndex(); ++i) {
+ debug << i
+ << ":(" << match.capturedStart(i) << ", " << match.capturedEnd(i)
+ << ", " << match.captured(i) << ")";
+ if (i < match.lastCapturedIndex())
+ debug << ", ";
+ }
+ } else if (match.hasPartialMatch()) {
+ debug << ", has partial match: ("
+ << match.capturedStart(0) << ", "
+ << match.capturedEnd(0) << ", "
+ << match.captured(0) << ")";
+ } else {
+ debug << ", no match";
+ }
+
+ debug << ")";
+
+ return debug.space();
+}
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/corelib/tools/qregularexpression.h b/src/corelib/tools/qregularexpression.h
new file mode 100644
index 0000000000..3ca83c9e27
--- /dev/null
+++ b/src/corelib/tools/qregularexpression.h
@@ -0,0 +1,248 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>.
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QREGULAREXPRESSION_H
+#define QREGULAREXPRESSION_H
+
+#ifndef QT_NO_REGEXP
+
+#include <QtCore/qstring.h>
+#include <QtCore/qshareddata.h>
+#include <QtCore/qvariant.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QRegularExpressionMatch;
+class QRegularExpressionMatchIterator;
+struct QRegularExpressionPrivate;
+
+class Q_CORE_EXPORT QRegularExpression
+{
+public:
+ enum PatternOption {
+ NoPatternOption = 0x0000,
+ CaseInsensitiveOption = 0x0001,
+ DotMatchesEverythingOption = 0x0002,
+ MultilineOption = 0x0004,
+ ExtendedPatternSyntaxOption = 0x0008,
+ InvertedGreedinessOption = 0x0010,
+ DontCaptureOption = 0x0020,
+ UseUnicodePropertiesOption = 0x0040
+ };
+ Q_DECLARE_FLAGS(PatternOptions, PatternOption)
+
+ PatternOptions patternOptions() const;
+ void setPatternOptions(PatternOptions options);
+
+ QRegularExpression();
+ explicit QRegularExpression(const QString &pattern, PatternOptions options = NoPatternOption);
+ QRegularExpression(const QRegularExpression &re);
+ ~QRegularExpression();
+ QRegularExpression &operator=(const QRegularExpression &re);
+
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QRegularExpression &operator=(QRegularExpression &&re)
+ { d.swap(re.d); return *this; }
+#endif
+
+ inline void swap(QRegularExpression &re) { d.swap(re.d); }
+
+ QString pattern() const;
+ void setPattern(const QString &pattern);
+
+ bool isValid() const;
+ int patternErrorOffset() const;
+ QString errorString() const;
+
+ int captureCount() const;
+
+ enum MatchType {
+ NormalMatch = 0,
+ PartialPreferCompleteMatch,
+ PartialPreferFirstMatch
+ };
+
+ enum MatchOption {
+ NoMatchOption = 0x0000,
+ AnchoredMatchOption = 0x0001
+ };
+ Q_DECLARE_FLAGS(MatchOptions, MatchOption)
+
+ QRegularExpressionMatch match(const QString &subject,
+ int offset = 0,
+ MatchType matchType = NormalMatch,
+ MatchOptions matchOptions = NoMatchOption) const;
+
+ QRegularExpressionMatchIterator globalMatch(const QString &subject,
+ int offset = 0,
+ MatchType matchType = NormalMatch,
+ MatchOptions matchOptions = NoMatchOption) const;
+
+ static QString escape(const QString &str);
+
+ bool operator==(const QRegularExpression &re) const;
+ inline bool operator!=(const QRegularExpression &re) const { return !operator==(re); }
+
+private:
+ friend struct QRegularExpressionPrivate;
+ friend class QRegularExpressionMatch;
+ friend struct QRegularExpressionMatchPrivate;
+ friend class QRegularExpressionMatchIterator;
+
+ QRegularExpression(QRegularExpressionPrivate &dd);
+ QExplicitlySharedDataPointer<QRegularExpressionPrivate> d;
+};
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(QRegularExpression::PatternOptions)
+Q_DECLARE_OPERATORS_FOR_FLAGS(QRegularExpression::MatchOptions)
+Q_DECLARE_TYPEINFO(QRegularExpression, Q_MOVABLE_TYPE);
+
+#ifndef QT_NO_DATASTREAM
+Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegularExpression &re);
+Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegularExpression &re);
+#endif
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QRegularExpression &re);
+Q_CORE_EXPORT QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions patternOptions);
+#endif
+
+struct QRegularExpressionMatchPrivate;
+
+class Q_CORE_EXPORT QRegularExpressionMatch
+{
+public:
+ ~QRegularExpressionMatch();
+ QRegularExpressionMatch(const QRegularExpressionMatch &match);
+ QRegularExpressionMatch &operator=(const QRegularExpressionMatch &match);
+
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match)
+ { d.swap(match.d); return *this; }
+#endif
+ inline void swap(QRegularExpressionMatch &match) { d.swap(match.d); }
+
+ QRegularExpression regularExpression() const;
+ QRegularExpression::MatchType matchType() const;
+ QRegularExpression::MatchOptions matchOptions() const;
+
+ bool hasMatch() const;
+ bool hasPartialMatch() const;
+
+ bool isValid() const;
+
+ int lastCapturedIndex() const;
+
+ QString captured(int nth = 0) const;
+ QStringRef capturedRef(int nth = 0) const;
+
+ QString captured(const QString &name) const;
+ QStringRef capturedRef(const QString &name) const;
+
+ QStringList capturedTexts() const;
+
+ int capturedStart(int nth = 0) const;
+ int capturedLength(int nth = 0) const;
+ int capturedEnd(int nth = 0) const;
+
+ int capturedStart(const QString &name) const;
+ int capturedLength(const QString &name) const;
+ int capturedEnd(const QString &name) const;
+
+private:
+ friend class QRegularExpression;
+ friend struct QRegularExpressionMatchPrivate;
+ friend class QRegularExpressionMatchIterator;
+
+ QRegularExpressionMatch(QRegularExpressionMatchPrivate &dd);
+ QSharedDataPointer<QRegularExpressionMatchPrivate> d;
+};
+
+Q_DECLARE_TYPEINFO(QRegularExpressionMatch, Q_MOVABLE_TYPE);
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QRegularExpressionMatch &match);
+#endif
+
+struct QRegularExpressionMatchIteratorPrivate;
+
+class Q_CORE_EXPORT QRegularExpressionMatchIterator
+{
+public:
+ ~QRegularExpressionMatchIterator();
+ QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator);
+ QRegularExpressionMatchIterator &operator=(const QRegularExpressionMatchIterator &iterator);
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator)
+ { d.swap(iterator.d); return *this; }
+#endif
+ void swap(QRegularExpressionMatchIterator &iterator) { d.swap(iterator.d); }
+
+ bool isValid() const;
+
+ bool hasNext() const;
+ QRegularExpressionMatch next();
+ QRegularExpressionMatch peekNext() const;
+
+ QRegularExpression regularExpression() const;
+ QRegularExpression::MatchType matchType() const;
+ QRegularExpression::MatchOptions matchOptions() const;
+
+private:
+ friend class QRegularExpression;
+
+ QRegularExpressionMatchIterator(QRegularExpressionMatchIteratorPrivate &dd);
+ QSharedDataPointer<QRegularExpressionMatchIteratorPrivate> d;
+};
+
+Q_DECLARE_TYPEINFO(QRegularExpressionMatchIterator, Q_MOVABLE_TYPE);
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QRegularExpression)
+
+QT_END_HEADER
+
+#endif // QT_NO_REGEXP
+
+#endif // QREGULAREXPRESSION_H
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h
index 46e505099a..c248477f2c 100644
--- a/src/corelib/tools/qringbuffer_p.h
+++ b/src/corelib/tools/qringbuffer_p.h
@@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE
class QRingBuffer
{
public:
- inline QRingBuffer(int growth = 4096) : basicBlockSize(growth) {
+ explicit inline QRingBuffer(int growth = 4096) : basicBlockSize(growth) {
buffers << QByteArray();
clear();
}
diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp
index b6bf525fb9..5ecca89229 100644
--- a/src/corelib/tools/qscopedpointer.cpp
+++ b/src/corelib/tools/qscopedpointer.cpp
@@ -89,10 +89,10 @@ QT_BEGIN_NAMESPACE
The following custom cleanup handlers exist:
\list
- \i QScopedPointerDeleter - the default, deletes the pointer using \c delete
- \i QScopedPointerArrayDeleter - deletes the pointer using \c{delete []}. Use
+ \li QScopedPointerDeleter - the default, deletes the pointer using \c delete
+ \li QScopedPointerArrayDeleter - deletes the pointer using \c{delete []}. Use
this handler for pointers that were allocated with \c{new []}.
- \i QScopedPointerPodDeleter - deletes the pointer using \c{free()}. Use this
+ \li QScopedPointerPodDeleter - deletes the pointer using \c{free()}. Use this
handler for pointers that were allocated with \c{malloc()}.
\endlist
diff --git a/src/corelib/tools/qscopedvaluerollback.h b/src/corelib/tools/qscopedvaluerollback.h
index 23d2d9eda0..d53cabd315 100644
--- a/src/corelib/tools/qscopedvaluerollback.h
+++ b/src/corelib/tools/qscopedvaluerollback.h
@@ -51,7 +51,7 @@ template <typename T>
class QScopedValueRollback
{
public:
- QScopedValueRollback(T &var) :
+ explicit QScopedValueRollback(T &var) :
varRef(var)
{
oldValue = varRef;
diff --git a/src/corelib/tools/qshareddata.cpp b/src/corelib/tools/qshareddata.cpp
index 6250745400..ffc8ac601d 100644
--- a/src/corelib/tools/qshareddata.cpp
+++ b/src/corelib/tools/qshareddata.cpp
@@ -86,10 +86,10 @@ QT_BEGIN_NAMESPACE
\list
- \o Define the class \c Employee to have a single data member of
+ \li Define the class \c Employee to have a single data member of
type \c {QSharedDataPointer<EmployeeData>}.
- \o Define the \c EmployeeData class derived from \l QSharedData to
+ \li Define the \c EmployeeData class derived from \l QSharedData to
contain all the data members you would normally have put in the
\c Employee class.
diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp
index 4c94f899e7..b276d2d2e0 100644
--- a/src/corelib/tools/qsize.cpp
+++ b/src/corelib/tools/qsize.cpp
@@ -186,10 +186,10 @@ void QSize::transpose()
height, according to the specified \a mode:
\list
- \i If \a mode is Qt::IgnoreAspectRatio, the size is set to (\a width, \a height).
- \i If \a mode is Qt::KeepAspectRatio, the current size is scaled to a rectangle
+ \li If \a mode is Qt::IgnoreAspectRatio, the size is set to (\a width, \a height).
+ \li If \a mode is Qt::KeepAspectRatio, the current size is scaled to a rectangle
as large as possible inside (\a width, \a height), preserving the aspect ratio.
- \i If \a mode is Qt::KeepAspectRatioByExpanding, the current size is scaled to a rectangle
+ \li If \a mode is Qt::KeepAspectRatioByExpanding, the current size is scaled to a rectangle
as small as possible outside (\a width, \a height), preserving the aspect ratio.
\endlist
@@ -614,10 +614,10 @@ void QSizeF::transpose()
height, according to the specified \a mode.
\list
- \i If \a mode is Qt::IgnoreAspectRatio, the size is set to (\a width, \a height).
- \i If \a mode is Qt::KeepAspectRatio, the current size is scaled to a rectangle
+ \li If \a mode is Qt::IgnoreAspectRatio, the size is set to (\a width, \a height).
+ \li If \a mode is Qt::KeepAspectRatio, the current size is scaled to a rectangle
as large as possible inside (\a width, \a height), preserving the aspect ratio.
- \i If \a mode is Qt::KeepAspectRatioByExpanding, the current size is scaled to a rectangle
+ \li If \a mode is Qt::KeepAspectRatioByExpanding, the current size is scaled to a rectangle
as small as possible outside (\a width, \a height), preserving the aspect ratio.
\endlist
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index d0c2dd7148..58eb711168 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -608,12 +608,12 @@ const QString::Null QString::null = { };
toLatin1(), toUtf8(), and toLocal8Bit().
\list
- \o toAscii() returns a Latin-1 (ISO 8859-1) encoded 8-bit string.
- \o toLatin1() returns a Latin-1 (ISO 8859-1) encoded 8-bit string.
- \o toUtf8() returns a UTF-8 encoded 8-bit string. UTF-8 is a
+ \li toAscii() returns a Latin-1 (ISO 8859-1) encoded 8-bit string.
+ \li toLatin1() returns a Latin-1 (ISO 8859-1) encoded 8-bit string.
+ \li toUtf8() returns a UTF-8 encoded 8-bit string. UTF-8 is a
superset of US-ASCII (ANSI X3.4-1986) that supports the entire
Unicode character set through multibyte sequences.
- \o toLocal8Bit() returns an 8-bit string using the system's local
+ \li toLocal8Bit() returns an 8-bit string using the system's local
encoding.
\endlist
@@ -631,9 +631,9 @@ const QString::Null QString::null = { };
conversions by defining the following two preprocessor symbols:
\list
- \o \c QT_NO_CAST_FROM_ASCII disables automatic conversions from
+ \li \c QT_NO_CAST_FROM_ASCII disables automatic conversions from
C string literals and pointers to Unicode.
- \o \c QT_NO_CAST_TO_ASCII disables automatic conversion from QString
+ \li \c QT_NO_CAST_TO_ASCII disables automatic conversion from QString
to C strings.
\endlist
@@ -657,10 +657,10 @@ const QString::Null QString::null = { };
\table 100 %
\header
- \o Note for C Programmers
+ \li Note for C Programmers
\row
- \o
+ \li
Due to C++'s type system and the fact that QString is
\l{implicitly shared}, QStrings may be treated like \c{int}s or
other basic types. For example:
@@ -699,12 +699,12 @@ const QString::Null QString::null = { };
following:
\table
- \header \o Format \o Meaning
- \row \o \c e \o format as [-]9.9e[+|-]999
- \row \o \c E \o format as [-]9.9E[+|-]999
- \row \o \c f \o format as [-]9.9
- \row \o \c g \o use \c e or \c f format, whichever is the most concise
- \row \o \c G \o use \c E or \c f format, whichever is the most concise
+ \header \li Format \li Meaning
+ \row \li \c e \li format as [-]9.9e[+|-]999
+ \row \li \c E \li format as [-]9.9E[+|-]999
+ \row \li \c f \li format as [-]9.9
+ \row \li \c g \li use \c e or \c f format, whichever is the most concise
+ \row \li \c G \li use \c E or \c f format, whichever is the most concise
\endtable
A \e precision is also specified with the argument \e format. For
@@ -2115,7 +2115,8 @@ QString &QString::replace(QChar c, const QLatin1String &after, Qt::CaseSensitivi
/*!
- Returns true if string \a other is equal to this string; otherwise
+ \relates QString
+ Returns true if string \a s1 is equal to string \a s2; otherwise
returns false.
The comparison is based exclusively on the numeric Unicode values of
@@ -2123,12 +2124,12 @@ QString &QString::replace(QChar c, const QLatin1String &after, Qt::CaseSensitivi
expect. Consider sorting user-interface strings with
localeAwareCompare().
*/
-bool QString::operator==(const QString &other) const
+bool operator==(const QString &s1, const QString &s2)
{
- if (d->size != other.d->size)
+ if (s1.d->size != s2.d->size)
return false;
- return qMemEquals(d->data(), other.d->data(), d->size);
+ return qMemEquals(s1.d->data(), s2.d->data(), s1.d->size);
}
/*!
@@ -2183,17 +2184,18 @@ bool QString::operator==(const QLatin1String &other) const
*/
/*!
- Returns true if this string is lexically less than string \a
- other; otherwise returns false.
+ \relates QString
+ Returns true if string \a s1 is lexically less than string
+ \a s2; otherwise returns false.
The comparison is based exclusively on the numeric Unicode values
of the characters and is very fast, but is not what a human would
expect. Consider sorting user-interface strings using the
QString::localeAwareCompare() function.
*/
-bool QString::operator<(const QString &other) const
+bool operator<(const QString &s1, const QString &s2)
{
- return ucstrcmp(constData(), length(), other.constData(), other.length()) < 0;
+ return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0;
}
/*!
@@ -2244,10 +2246,11 @@ bool QString::operator<(const QLatin1String &other) const
go through QObject::tr(), for example.
*/
-/*! \fn bool QString::operator<=(const QString &other) const
+/*! \fn bool operator<=(const QString &s1, const QString &s2)
+ \relates QString
- Returns true if this string is lexically less than or equal to
- string \a other; otherwise returns false.
+ Returns true if string \a s1 is lexically less than or equal to
+ string \a s2; otherwise returns false.
The comparison is based exclusively on the numeric Unicode values
of the characters and is very fast, but is not what a human would
@@ -2287,10 +2290,11 @@ bool QString::operator<(const QLatin1String &other) const
go through QObject::tr(), for example.
*/
-/*! \fn bool QString::operator>(const QString &other) const
+/*! \fn bool operator>(const QString &s1, const QString &s2)
+ \relates QString
- Returns true if this string is lexically greater than string \a
- other; otherwise returns false.
+ Returns true if string \a s1 is lexically greater than string \a
+ s2; otherwise returns false.
The comparison is based exclusively on the numeric Unicode values
of the characters and is very fast, but is not what a human would
@@ -2346,10 +2350,11 @@ bool QString::operator>(const QLatin1String &other) const
for example.
*/
-/*! \fn bool QString::operator>=(const QString &other) const
+/*! \fn bool operator>=(const QString &s1, const QString &s2)
+ \relates QString
- Returns true if this string is lexically greater than or equal to
- string \a other; otherwise returns false.
+ Returns true if string \a s1 is lexically greater than or equal to
+ string \a s2; otherwise returns false.
The comparison is based exclusively on the numeric Unicode values
of the characters and is very fast, but is not what a human would
@@ -2389,9 +2394,10 @@ bool QString::operator>(const QLatin1String &other) const
for example.
*/
-/*! \fn bool QString::operator!=(const QString &other) const
+/*! \fn bool operator!=(const QString &s1, const QString &s2)
+ \relates QString
- Returns true if this string is not equal to string \a other;
+ Returns true if string \a s1 is not equal to string \a s2;
otherwise returns false.
The comparison is based exclusively on the numeric Unicode values
@@ -2772,7 +2778,7 @@ struct QStringCapture
\snippet doc/src/snippets/qstring/main.cpp 42
For regular expressions containing \l{capturing parentheses},
- occurrences of \bold{\\1}, \bold{\\2}, ..., in \a after are replaced
+ occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced
with \a{rx}.cap(1), cap(2), ...
\snippet doc/src/snippets/qstring/main.cpp 43
@@ -4706,7 +4712,7 @@ int QString::localeAwareCompare_helper(const QChar *data1, int length1,
} // else fall through
# endif
// declared in <string.h>
- int delta = strcoll(toLocal8Bit_helper(data1, length1), toLocal8Bit_helper(data2, length2));
+ int delta = strcoll(toLocal8Bit_helper(data1, length1).constData(), toLocal8Bit_helper(data2, length2).constData());
if (delta == 0)
delta = ucstrcmp(data1, length1, data2, length2);
return delta;
@@ -6038,7 +6044,7 @@ QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivit
\snippet doc/src/snippets/qstring/main.cpp 60
Here's a third example where we use a zero-length assertion,
- \bold{\\b} (word boundary), to split the string into an
+ \b{\\b} (word boundary), to split the string into an
alternating sequence of non-word and word tokens:
\snippet doc/src/snippets/qstring/main.cpp 61
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index ba68ab022b..26959d81f3 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -97,7 +97,9 @@ template<int N> struct QStaticStringData
#define QT_UNICODE_LITERAL_II(str) u"" str
-#elif defined(Q_OS_WIN) || (defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 2) || defined(WCHAR_MAX) && (WCHAR_MAX - 0 < 65536)
+#elif defined(Q_OS_WIN) \
+ || (defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 2) \
+ || (!defined(__SIZEOF_WCHAR_T__) && defined(WCHAR_MAX) && (WCHAR_MAX - 0 < 65536))
// wchar_t is 2 bytes
template<int N> struct QStaticStringData
{
@@ -415,6 +417,10 @@ public:
{
return fromLocal8Bit_helper(str, (str && size == -1) ? int(strlen(str)) : size);
}
+ static inline QString fromAscii(const QByteArray &str) { return fromAscii(str.data(), str.size()); }
+ static inline QString fromLatin1(const QByteArray &str) { return fromLatin1(str.data(), str.size()); }
+ static inline QString fromUtf8(const QByteArray &str) { return fromUtf8(str.data(), str.size()); }
+ static inline QString fromLocal8Bit(const QByteArray &str) { return fromLocal8Bit(str.data(), str.size()); }
static QString fromUtf16(const ushort *, int size = -1);
static QString fromUcs4(const uint *, int size = -1);
static QString fromRawData(const QChar *, int size);
@@ -480,12 +486,12 @@ public:
static QString number(qulonglong, int base=10);
static QString number(double, char f='g', int prec=6);
- bool operator==(const QString &s) const;
- bool operator<(const QString &s) const;
- inline bool operator>(const QString &s) const { return s < *this; }
- inline bool operator!=(const QString &s) const { return !operator==(s); }
- inline bool operator<=(const QString &s) const { return !operator>(s); }
- inline bool operator>=(const QString &s) const { return !operator<(s); }
+ friend Q_CORE_EXPORT bool operator==(const QString &s1, const QString &s2);
+ friend Q_CORE_EXPORT bool operator<(const QString &s1, const QString &s2);
+ friend inline bool operator>(const QString &s1, const QString &s2) { return s2 < s1; }
+ friend inline bool operator!=(const QString &s1, const QString &s2) { return !(s1 == s2); }
+ friend inline bool operator<=(const QString &s1, const QString &s2) { return !(s1 > s2); }
+ friend inline bool operator>=(const QString &s1, const QString &s2) { return !(s1 < s2); }
bool operator==(const QLatin1String &s) const;
bool operator<(const QLatin1String &s) const;
diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h
index c19d733243..0eb8aa8903 100644
--- a/src/corelib/tools/qstringbuilder.h
+++ b/src/corelib/tools/qstringbuilder.h
@@ -45,12 +45,6 @@
#include <QtCore/qstring.h>
#include <QtCore/qbytearray.h>
-#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL)
-# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ == 0)
-# include <QtCore/qmap.h>
-# endif
-#endif
-
#include <string.h>
QT_BEGIN_HEADER
@@ -173,6 +167,16 @@ template <> struct QConcatenable<QChar> : private QAbstractConcatenable
{ *out++ = c; }
};
+template <> struct QConcatenable<QChar::SpecialCharacter> : private QAbstractConcatenable
+{
+ typedef QChar::SpecialCharacter type;
+ typedef QString ConvertTo;
+ enum { ExactSize = true };
+ static int size(const QChar::SpecialCharacter) { return 1; }
+ static inline void appendTo(const QChar::SpecialCharacter c, QChar *&out)
+ { *out++ = c; }
+};
+
template <> struct QConcatenable<QCharRef> : private QAbstractConcatenable
{
typedef QCharRef type;
diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp
index a352045a7d..b4ec0c6498 100644
--- a/src/corelib/tools/qstringlist.cpp
+++ b/src/corelib/tools/qstringlist.cpp
@@ -342,7 +342,7 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QString &b
\snippet doc/src/snippets/qstringlist/main.cpp 14
For regular expressions that contain \l{capturing parentheses},
- occurrences of \bold{\\1}, \bold{\\2}, ..., in \a after are
+ occurrences of \b{\\1}, \b{\\2}, ..., in \a after are
replaced with \a{rx}.cap(1), \a{rx}.cap(2), ...
For example:
diff --git a/src/corelib/tools/qstringmatcher.h b/src/corelib/tools/qstringmatcher.h
index a9b2a7c371..3f614f732c 100644
--- a/src/corelib/tools/qstringmatcher.h
+++ b/src/corelib/tools/qstringmatcher.h
@@ -55,7 +55,7 @@ class Q_CORE_EXPORT QStringMatcher
{
public:
QStringMatcher();
- QStringMatcher(const QString &pattern,
+ explicit QStringMatcher(const QString &pattern,
Qt::CaseSensitivity cs = Qt::CaseSensitive);
QStringMatcher(const QChar *uc, int len,
Qt::CaseSensitivity cs = Qt::CaseSensitive);
diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc
index 1a0579a077..e1dc2bee9a 100644
--- a/src/corelib/tools/qvarlengtharray.qdoc
+++ b/src/corelib/tools/qvarlengtharray.qdoc
@@ -69,13 +69,13 @@
structure. The main differences between the two classes are:
\list
- \o QVarLengthArray's API is much more low-level. It provides no
+ \li QVarLengthArray's API is much more low-level. It provides no
iterators and lacks much of QVector's functionality.
- \o QVarLengthArray doesn't initialize the memory if the value is
+ \li QVarLengthArray doesn't initialize the memory if the value is
a basic type. (QVector always does.)
- \o QVector uses \l{implicit sharing} as a memory optimization.
+ \li QVector uses \l{implicit sharing} as a memory optimization.
QVarLengthArray doesn't provide that feature; however, it
usually produces slightly better performance due to reduced
overhead, especially in tight loops.
diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp
index b70436f907..1a746dc061 100644
--- a/src/corelib/tools/qvector.cpp
+++ b/src/corelib/tools/qvector.cpp
@@ -98,21 +98,21 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT)
similar functionality. Here's an overview:
\list
- \i For most purposes, QList is the right class to use. Operations
+ \li For most purposes, QList is the right class to use. Operations
like prepend() and insert() are usually faster than with
QVector because of the way QList stores its items in memory
(see \l{Algorithmic Complexity} for details),
and its index-based API is more convenient than QLinkedList's
iterator-based API. It also expands to less code in your
executable.
- \i If you need a real linked list, with guarantees of \l{constant
+ \li If you need a real linked list, with guarantees of \l{constant
time} insertions in the middle of the list and iterators to
items rather than indexes, use QLinkedList.
- \i If you want the items to occupy adjacent memory positions, or
+ \li If you want the items to occupy adjacent memory positions, or
if your items are larger than a pointer and you want to avoid
the overhead of allocating them on the heap individually at
insertion time, then use QVector.
- \i If you want a low-level variable-size array, QVarLengthArray
+ \li If you want a low-level variable-size array, QVarLengthArray
may be sufficient.
\endlist
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index 0342e53261..ac347404fd 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -33,6 +33,7 @@ HEADERS += \
tools/qqueue.h \
tools/qrect.h \
tools/qregexp.h \
+ tools/qregularexpression.h \
tools/qringbuffer_p.h \
tools/qrefcount.h \
tools/qscopedpointer.h \
@@ -79,6 +80,7 @@ SOURCES += \
tools/qcontiguouscache.cpp \
tools/qrect.cpp \
tools/qregexp.cpp \
+ tools/qregularexpression.cpp \
tools/qrefcount.cpp \
tools/qshareddata.cpp \
tools/qsharedpointer.cpp \
@@ -109,6 +111,12 @@ contains(QT_CONFIG,icu) {
DEFINES += QT_USE_ICU
}
+pcre {
+ include($$PWD/../../3rdparty/pcre.pri)
+} else {
+ LIBS_PRIVATE += -lpcre16
+}
+
DEFINES += HB_EXPORT=Q_CORE_EXPORT
INCLUDEPATH += ../3rdparty/harfbuzz/src
HEADERS += ../3rdparty/harfbuzz/src/harfbuzz.h