From 21549529ef0e80c3dae28b4d7ea9a8ffb859f351 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 29 May 2020 12:01:26 +0200 Subject: Rename snippet files to match the carved up corelib/tools/ This is a folllow-up to commits 548513a4bd050d3df0a85fed6e2d1a00ce06d2ab and a9aa206b7b8ac4e69f8c46233b4080e00e845ff5, renaming the snippets files referenced by the files moved out of corelib/tools/ to match the new locations of the files using them. Change-Id: I59f5d3c217ef835e9244387cc769e7212de9d8f5 Reviewed-by: Paul Wicking --- .../snippets/code/src_corelib_text_qbytearray.cpp | 509 +++++++++++++++++++++ .../code/src_corelib_text_qbytearraymatcher.cpp | 57 +++ .../doc/snippets/code/src_corelib_text_qlocale.cpp | 122 +++++ .../doc/snippets/code/src_corelib_text_qregexp.cpp | 243 ++++++++++ .../code/src_corelib_text_qregularexpression.cpp | 358 +++++++++++++++ .../doc/snippets/code/src_corelib_text_qstring.cpp | 122 +++++ .../code/src_corelib_text_qstringiterator.cpp | 79 ++++ .../snippets/code/src_corelib_text_qstringview.cpp | 62 +++ .../snippets/code/src_corelib_time_qdatetime.cpp | 218 +++++++++ .../snippets/code/src_corelib_tools_qbytearray.cpp | 509 --------------------- .../code/src_corelib_tools_qbytearraymatcher.cpp | 57 --- .../snippets/code/src_corelib_tools_qdatetime.cpp | 218 --------- .../snippets/code/src_corelib_tools_qlocale.cpp | 122 ----- .../snippets/code/src_corelib_tools_qregexp.cpp | 243 ---------- .../code/src_corelib_tools_qregularexpression.cpp | 358 --------------- .../snippets/code/src_corelib_tools_qstring.cpp | 122 ----- .../code/src_corelib_tools_qstringiterator.cpp | 79 ---- .../code/src_corelib_tools_qstringview.cpp | 62 --- 18 files changed, 1770 insertions(+), 1770 deletions(-) create mode 100644 src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_text_qbytearraymatcher.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_text_qlocale.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_text_qregexp.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_text_qregularexpression.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_text_qstring.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_text_qstringiterator.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_text_qstringview.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp delete mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp delete mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qbytearraymatcher.cpp delete mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp delete mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp delete mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qregexp.cpp delete mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qregularexpression.cpp delete mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp delete mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp delete mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qstringview.cpp (limited to 'src/corelib/doc/snippets/code') diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp new file mode 100644 index 0000000000..9c07a2e92c --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp @@ -0,0 +1,509 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +void wrapInFunction() +{ + +//! [0] +QByteArray ba("Hello"); +//! [0] + + +//! [1] +QByteArray ba; +ba.resize(5); +ba[0] = 0x3c; +ba[1] = 0xb8; +ba[2] = 0x64; +ba[3] = 0x18; +ba[4] = 0xca; +//! [1] + + +//! [2] +for (int i = 0; i < ba.size(); ++i) { + if (ba.at(i) >= 'a' && ba.at(i) <= 'f') + cout << "Found character in range [a-f]" << Qt::endl; +} +//! [2] + + +//! [3] +QByteArray x("and"); +x.prepend("rock "); // x == "rock and" +x.append(" roll"); // x == "rock and roll" +x.replace(5, 3, "&"); // x == "rock & roll" +//! [3] + + +//! [4] +QByteArray ba("We must be bold, very bold"); +int j = 0; +while ((j = ba.indexOf("", j)) != -1) { + cout << "Found tag at index position " << j << Qt::endl; + ++j; +} +//! [4] + + +//! [5] +QByteArray().isNull(); // returns true +QByteArray().isEmpty(); // returns true + +QByteArray("").isNull(); // returns false +QByteArray("").isEmpty(); // returns true + +QByteArray("abc").isNull(); // returns false +QByteArray("abc").isEmpty(); // returns false +//! [5] + + +//! [6] +QByteArray ba("Hello"); +int n = ba.size(); // n == 5 +ba.data()[0]; // returns 'H' +ba.data()[4]; // returns 'o' +ba.data()[5]; // returns '\0' +//! [6] + + +//! [7] +QByteArray().isEmpty(); // returns true +QByteArray("").isEmpty(); // returns true +QByteArray("abc").isEmpty(); // returns false +//! [7] + + +//! [8] +QByteArray ba("Hello world"); +char *data = ba.data(); +while (*data) { + cout << "[" << *data << "]" << Qt::endl; + ++data; +} +//! [8] + + +//! [9] +QByteArray ba("Hello, world"); +cout << ba[0]; // prints H +ba[7] = 'W'; +// ba == "Hello, World" +//! [9] + + +//! [10] +QByteArray ba("Stockholm"); +ba.truncate(5); // ba == "Stock" +//! [10] + + +//! [11] +QByteArray ba("STARTTLS\r\n"); +ba.chop(2); // ba == "STARTTLS" +//! [11] + + +//! [12] +QByteArray x("free"); +QByteArray y("dom"); +x += y; +// x == "freedom" +//! [12] + + +//! [13] +QByteArray().isNull(); // returns true +QByteArray("").isNull(); // returns false +QByteArray("abc").isNull(); // returns false +//! [13] + + +//! [14] +QByteArray ba("Istambul"); +ba.fill('o'); +// ba == "oooooooo" + +ba.fill('X', 2); +// ba == "XX" +//! [14] + + +//! [15] +QByteArray x("ship"); +QByteArray y("air"); +x.prepend(y); +// x == "airship" +//! [15] + + +//! [16] +QByteArray x("free"); +QByteArray y("dom"); +x.append(y); +// x == "freedom" +//! [16] + + +//! [17] +QByteArray ba("Meal"); +ba.insert(1, QByteArray("ontr")); +// ba == "Montreal" +//! [17] + + +//! [18] +QByteArray ba("Montreal"); +ba.remove(1, 4); +// ba == "Meal" +//! [18] + + +//! [19] +QByteArray x("Say yes!"); +QByteArray y("no"); +x.replace(4, 3, y); +// x == "Say no!" +//! [19] + + +//! [20] +QByteArray ba("colour behaviour flavour neighbour"); +ba.replace(QByteArray("ou"), QByteArray("o")); +// ba == "color behavior flavor neighbor" +//! [20] + + +//! [21] +QByteArray x("sticky question"); +QByteArray y("sti"); +x.indexOf(y); // returns 0 +x.indexOf(y, 1); // returns 10 +x.indexOf(y, 10); // returns 10 +x.indexOf(y, 11); // returns -1 +//! [21] + + +//! [22] +QByteArray ba("ABCBA"); +ba.indexOf("B"); // returns 1 +ba.indexOf("B", 1); // returns 1 +ba.indexOf("B", 2); // returns 3 +ba.indexOf("X"); // returns -1 +//! [22] + + +//! [23] +QByteArray x("crazy azimuths"); +QByteArray y("az"); +x.lastIndexOf(y); // returns 6 +x.lastIndexOf(y, 6); // returns 6 +x.lastIndexOf(y, 5); // returns 2 +x.lastIndexOf(y, 1); // returns -1 +//! [23] + + +//! [24] +QByteArray ba("ABCBA"); +ba.lastIndexOf("B"); // returns 3 +ba.lastIndexOf("B", 3); // returns 3 +ba.lastIndexOf("B", 2); // returns 1 +ba.lastIndexOf("X"); // returns -1 +//! [24] + + +//! [25] +QByteArray url("ftp://ftp.qt-project.org/"); +if (url.startsWith("ftp:")) + ... +//! [25] + + +//! [26] +QByteArray url("http://qt-project.org/doc/qt-5.0/qtdoc/index.html"); +if (url.endsWith(".html")) + ... +//! [26] + + +//! [27] +QByteArray x("Pineapple"); +QByteArray y = x.left(4); +// y == "Pine" +//! [27] + + +//! [28] +QByteArray x("Pineapple"); +QByteArray y = x.right(5); +// y == "apple" +//! [28] + + +//! [29] +QByteArray x("Five pineapples"); +QByteArray y = x.mid(5, 4); // y == "pine" +QByteArray z = x.mid(5); // z == "pineapples" +//! [29] + + +//! [30] +QByteArray x("Qt by THE QT COMPANY"); +QByteArray y = x.toLower(); +// y == "qt by the qt company" +//! [30] + + +//! [31] +QByteArray x("Qt by THE QT COMPANY"); +QByteArray y = x.toUpper(); +// y == "QT BY THE QT COMPANY" +//! [31] + + +//! [32] +QByteArray ba(" lots\t of\nwhitespace\r\n "); +ba = ba.simplified(); +// ba == "lots of whitespace"; +//! [32] + + +//! [33] +QByteArray ba(" lots\t of\nwhitespace\r\n "); +ba = ba.trimmed(); +// ba == "lots\t of\nwhitespace"; +//! [33] + + +//! [34] +QByteArray x("apple"); +QByteArray y = x.leftJustified(8, '.'); // y == "apple..." +//! [34] + + +//! [35] +QByteArray x("apple"); +QByteArray y = x.rightJustified(8, '.'); // y == "...apple" +//! [35] + + +//! [36] +QByteArray str("FF"); +bool ok; +int hex = str.toInt(&ok, 16); // hex == 255, ok == true +int dec = str.toInt(&ok, 10); // dec == 0, ok == false +//! [36] + + +//! [37] +QByteArray str("FF"); +bool ok; +long hex = str.toLong(&ok, 16); // hex == 255, ok == true +long dec = str.toLong(&ok, 10); // dec == 0, ok == false +//! [37] + + +//! [38] +QByteArray string("1234.56"); +bool ok; +double a = string.toDouble(&ok); // a == 1234.56, ok == true + +string = "1234.56 Volt"; +a = str.toDouble(&ok); // a == 0, ok == false +//! [38] + +//! [38float] +QByteArray string("1234.56"); +bool ok; +float a = string.toFloat(&ok); // a == 1234.56, ok == true + +string = "1234.56 Volt"; +a = str.toFloat(&ok); // a == 0, ok == false +//! [38float] + +//! [39] +QByteArray text("Qt is great!"); +text.toBase64(); // returns "UXQgaXMgZ3JlYXQh" + +QByteArray text("

Hello?

"); +text.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals); // returns "PHA+SGVsbG8/PC9wPg" +text.toBase64(QByteArray::Base64Encoding); // returns "PHA+SGVsbG8/PC9wPg==" +text.toBase64(QByteArray::Base64UrlEncoding); // returns "PHA-SGVsbG8_PC9wPg==" +text.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); // returns "PHA-SGVsbG8_PC9wPg" +//! [39] + +//! [40] +QByteArray ba; +int n = 63; +ba.setNum(n); // ba == "63" +ba.setNum(n, 16); // ba == "3f" +//! [40] + + +//! [41] +int n = 63; +QByteArray::number(n); // returns "63" +QByteArray::number(n, 16); // returns "3f" +QByteArray::number(n, 16).toUpper(); // returns "3F" +//! [41] + + +//! [42] +QByteArray ba = QByteArray::number(12.3456, 'E', 3); +// ba == 1.235E+01 +//! [42] + + +//! [43] + static const char mydata[] = { + '\x00', '\x00', '\x03', '\x84', '\x78', '\x9c', '\x3b', '\x76', + '\xec', '\x18', '\xc3', '\x31', '\x0a', '\xf1', '\xcc', '\x99', + ... + '\x6d', '\x5b' +}; + +QByteArray data = QByteArray::fromRawData(mydata, sizeof(mydata)); +QDataStream in(&data, QIODevice::ReadOnly); +... +//! [43] + + +//! [44] +QByteArray text = QByteArray::fromBase64("UXQgaXMgZ3JlYXQh"); +text.data(); // returns "Qt is great!" + +QByteArray::fromBase64("PHA+SGVsbG8/PC9wPg==", QByteArray::Base64Encoding); // returns "

Hello?

" +QByteArray::fromBase64("PHA-SGVsbG8_PC9wPg==", QByteArray::Base64UrlEncoding); // returns "

Hello?

" +//! [44bis] + +//! [44ter] +void process(const QByteArray &); + +if (auto result = QByteArray::fromBase64Encoding(encodedData)) + process(*result); +//! [44ter] + +//! [44quater] +auto result = QByteArray::fromBase64Encoding(encodedData); +if (result.decodingStatus == QByteArray::Base64DecodingStatus::Ok) + process(result.decoded); +//! [44quater] + +//! [45] +QByteArray text = QByteArray::fromHex("517420697320677265617421"); +text.data(); // returns "Qt is great!" +//! [45] + +//! [46] +QString tmp = "test"; +QByteArray text = tmp.toLocal8Bit(); +char *data = new char[text.size()]; +strcpy(data, text.data()); +delete [] data; +//! [46] + +//! [47] +QString tmp = "test"; +QByteArray text = tmp.toLocal8Bit(); +char *data = new char[text.size() + 1]; +strcpy(data, text.data()); +delete [] data; +//! [47] + +//! [48] +QByteArray ba1("ca\0r\0t"); +ba1.size(); // Returns 2. +ba1.constData(); // Returns "ca" with terminating \0. + +QByteArray ba2("ca\0r\0t", 3); +ba2.size(); // Returns 3. +ba2.constData(); // Returns "ca\0" with terminating \0. + +QByteArray ba3("ca\0r\0t", 4); +ba3.size(); // Returns 4. +ba3.constData(); // Returns "ca\0r" with terminating \0. + +const char cart[] = {'c', 'a', '\0', 'r', '\0', 't'}; +QByteArray ba4(QByteArray::fromRawData(cart, 6)); +ba4.size(); // Returns 6. +ba4.constData(); // Returns "ca\0r\0t" without terminating \0. +//! [48] + +//! [49] +QByteArray ba("ab"); +ba.repeated(4); // returns "abababab" +//! [49] + +//! [50] +QByteArray macAddress = QByteArray::fromHex("123456abcdef"); +macAddress.toHex(':'); // returns "12:34:56:ab:cd:ef" +macAddress.toHex(0); // returns "123456abcdef" +//! [50] + +//! [51] +QByteArray text = QByteArray::fromPercentEncoding("Qt%20is%20great%33"); +text.data(); // returns "Qt is great!" +//! [51] + +//! [52] +QByteArray text = "{a fishy string?}"; +QByteArray ba = text.toPercentEncoding("{}", "s"); +qDebug(ba.constData()); +// prints "{a fi%73hy %73tring%3F}" +//! [52] + +//! [53] +QByteArray ba = QByteArrayLiteral("byte array contents"); +//! [53] + +} + + diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qbytearraymatcher.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qbytearraymatcher.cpp new file mode 100644 index 0000000000..9cf94f0494 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_text_qbytearraymatcher.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +static const auto matcher = qMakeStaticByteArrayMatcher("needle"); +//! [0] + +//! [1] +static const auto matcher = qMakeStaticByteArrayMatcher("needle"); +//! [1] diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qlocale.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qlocale.cpp new file mode 100644 index 0000000000..aed14c379f --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_text_qlocale.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QLocale egyptian(QLocale::Arabic, QLocale::Egypt); +QString s1 = egyptian.toString(1.571429E+07, 'e'); +QString s2 = egyptian.toString(10); + +double d = egyptian.toDouble(s1); +int i = egyptian.toInt(s2); +//! [0] + + +//! [1] +QLocale::setDefault(QLocale(QLocale::Hebrew, QLocale::Israel)); +QLocale hebrew; // Constructs a default QLocale +QString s1 = hebrew.toString(15714.3, 'e'); + +bool ok; +double d; + +QLocale::setDefault(QLocale::C); +d = QString("1234,56").toDouble(&ok); // ok == false +d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 + +QLocale::setDefault(QLocale::German); +d = QString("1234,56").toDouble(&ok); // ok == true, d == 1234.56 +d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 + +QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); +str = QString("%1 %L2 %L3") + .arg(12345).arg(12345).arg(12345, 0, 16); +// str == "12345 12,345 3039" +//! [1] + + +//! [2] +QLocale korean("ko"); +QLocale swiss("de_CH"); +//! [2] + + +//! [3] +bool ok; +double d; + +QLocale c(QLocale::C); +d = c.toDouble( "1234.56", &ok ); // ok == true, d == 1234.56 +d = c.toDouble( "1,234.56", &ok ); // ok == true, d == 1234.56 +d = c.toDouble( "1234,56", &ok ); // ok == false + +QLocale german(QLocale::German); +d = german.toDouble( "1234,56", &ok ); // ok == true, d == 1234.56 +d = german.toDouble( "1.234,56", &ok ); // ok == true, d == 1234.56 +d = german.toDouble( "1234.56", &ok ); // ok == false + +d = german.toDouble( "1.234", &ok ); // ok == true, d == 1234.0 +//! [3] + +//! [3-qstringview] +bool ok; +double d; + +QLocale c(QLocale::C); +d = c.toDouble(u"1234.56", &ok); // ok == true, d == 1234.56 +d = c.toDouble(u"1,234.56", &ok); // ok == true, d == 1234.56 +d = c.toDouble(u"1234,56", &ok); // ok == false + +QLocale german(QLocale::German); +d = german.toDouble(u"1234,56", &ok); // ok == true, d == 1234.56 +d = german.toDouble(u"1.234,56", &ok); // ok == true, d == 1234.56 +d = german.toDouble(u"1234.56", &ok); // ok == false + +d = german.toDouble(u"1.234", &ok); // ok == true, d == 1234.0 +//! [3-qstringview] diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qregexp.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qregexp.cpp new file mode 100644 index 0000000000..8339ea413e --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_text_qregexp.cpp @@ -0,0 +1,243 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QRegExp rx("(\\d+)"); +QString str = "Offsets: 12 14 99 231 7"; +QStringList list; +int pos = 0; + +while ((pos = rx.indexIn(str, pos)) != -1) { + list << rx.cap(1); + pos += rx.matchedLength(); +} +// list: ["12", "14", "99", "231", "7"] +//! [0] + + +//! [1] +QRegExp rx("*.txt"); +rx.setPatternSyntax(QRegExp::Wildcard); +rx.exactMatch("README.txt"); // returns true +rx.exactMatch("welcome.txt.bak"); // returns false +//! [1] + + +//! [2] +QRegExp rx("ro+m"); +rx.setMinimal(true); +//! [2] + + +//! [3] +QRegExp mark("\\b" // word boundary + "[Mm]ark" // the word we want to match + ); +//! [3] + + +//! [4] +QRegExp rx("^\\d\\d?$"); // match integers 0 to 99 +rx.indexIn("123"); // returns -1 (no match) +rx.indexIn("-6"); // returns -1 (no match) +rx.indexIn("6"); // returns 0 (matched at position 0) +//! [4] + + +//! [5] +QRegExp rx("^\\S+$"); // match strings without whitespace +rx.indexIn("Hello world"); // returns -1 (no match) +rx.indexIn("This_is-OK"); // returns 0 (matched at position 0) +//! [5] + + +//! [6] +QRegExp rx("\\b(mail|letter|correspondence)\\b"); +rx.indexIn("I sent you an email"); // returns -1 (no match) +rx.indexIn("Please write the letter"); // returns 17 +//! [6] + + +//! [7] +QString captured = rx.cap(1); // captured == "letter" +//! [7] + + +//! [8] +QRegExp rx("&(?!amp;)"); // match ampersands but not & +QString line1 = "This & that"; +line1.replace(rx, "&"); +// line1 == "This & that" +QString line2 = "His & hers & theirs"; +line2.replace(rx, "&"); +// line2 == "His & hers & theirs" +//! [8] + + +//! [9] +QString str = "One Eric another Eirik, and an Ericsson. " + "How many Eiriks, Eric?"; +QRegExp rx("\\b(Eric|Eirik)\\b"); // match Eric or Eirik +int pos = 0; // where we are in the string +int count = 0; // how many Eric and Eirik's we've counted +while (pos >= 0) { + pos = rx.indexIn(str, pos); + if (pos >= 0) { + ++pos; // move along in str + ++count; // count our Eric or Eirik + } +} +//! [9] + + +//! [10] +str = "The Qt Company Ltd\tqt.io\tFinland"; +QString company, web, country; +rx.setPattern("^([^\t]+)\t([^\t]+)\t([^\t]+)$"); +if (rx.indexIn(str) != -1) { + company = rx.cap(1); + web = rx.cap(2); + country = rx.cap(3); +} +//! [10] + + +//! [11] +QStringList field = str.split("\t"); +//! [11] + + +//! [12] +QRegExp rx("*.html"); +rx.setPatternSyntax(QRegExp::Wildcard); +rx.exactMatch("index.html"); // returns true +rx.exactMatch("default.htm"); // returns false +rx.exactMatch("readme.txt"); // returns false +//! [12] + + +//! [13] +QString str = "offsets: 1.23 .50 71.00 6.00"; +QRegExp rx("\\d*\\.\\d+"); // primitive floating point matching +int count = 0; +int pos = 0; +while ((pos = rx.indexIn(str, pos)) != -1) { + ++count; + pos += rx.matchedLength(); +} +// pos will be 9, 14, 18 and finally 24; count will end up as 4 +//! [13] + + +//! [14] +QRegExp rx("(\\d+)(\\s*)(cm|inch(es)?)"); +int pos = rx.indexIn("Length: 36 inches"); +QStringList list = rx.capturedTexts(); +// list is now ("36 inches", "36", " ", "inches", "es") +//! [14] + + +//! [15] +QRegExp rx("(\\d+)(?:\\s*)(cm|inch(?:es)?)"); +int pos = rx.indexIn("Length: 36 inches"); +QStringList list = rx.capturedTexts(); +// list is now ("36 inches", "36", "inches") +//! [15] + + +//! [16] +QStringList list = rx.capturedTexts(); +QStringList::iterator it = list.begin(); +while (it != list.end()) { + myProcessing(*it); + ++it; +} +//! [16] + + +//! [17] +QRegExp rxlen("(\\d+)(?:\\s*)(cm|inch)"); +int pos = rxlen.indexIn("Length: 189cm"); +if (pos > -1) { + QString value = rxlen.cap(1); // "189" + QString unit = rxlen.cap(2); // "cm" + // ... +} +//! [17] + + +//! [18] +QRegExp rx("/([a-z]+)/([a-z]+)"); +rx.indexIn("Output /dev/null"); // returns 7 (position of /dev/null) +rx.pos(0); // returns 7 (position of /dev/null) +rx.pos(1); // returns 8 (position of dev) +rx.pos(2); // returns 12 (position of null) +//! [18] + + +//! [19] +s1 = QRegExp::escape("bingo"); // s1 == "bingo" +s2 = QRegExp::escape("f(x)"); // s2 == "f\\(x\\)" +//! [19] + + +//! [20] +QRegExp rx("(" + QRegExp::escape(name) + + "|" + QRegExp::escape(alias) + ")"); +//! [20] + +{ +//! [21] +QString p("a .*|pattern"); + +// re matches exactly the pattern string p +QRegularExpression re(QRegularExpression::anchoredPattern(p)); +//! [21] +} diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qregularexpression.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qregularexpression.cpp new file mode 100644 index 0000000000..b451ed5253 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_text_qregularexpression.cpp @@ -0,0 +1,358 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Giuseppe D'Angelo . +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +int main() { + +{ +//! [0] +QRegularExpression re("a pattern"); +//! [0] +} + +{ +//! [1] +QRegularExpression re; +re.setPattern("another pattern"); +//! [1] +} + +{ +//! [2] +// matches two digits followed by a space and a word +QRegularExpression re("\\d\\d \\w+"); + +// matches a backslash +QRegularExpression re2("\\\\"); +//! [2] +} + +{ +//! [3] +QRegularExpression re("a third pattern"); +QString pattern = re.pattern(); // pattern == "a third pattern" +//! [3] +} + +{ +//! [4] +// matches "Qt rocks", but also "QT rocks", "QT ROCKS", "qT rOcKs", etc. +QRegularExpression re("Qt rocks", QRegularExpression::CaseInsensitiveOption); +//! [4] +} + +{ +//! [5] +QRegularExpression re("^\\d+$"); +re.setPatternOptions(QRegularExpression::MultilineOption); +// re matches any line in the subject string that contains only digits (but at least one) +//! [5] +} + +{ +//! [6] +QRegularExpression re = QRegularExpression("^two.*words$", QRegularExpression::MultilineOption + | QRegularExpression::DotMatchesEverythingOption); + +QRegularExpression::PatternOptions options = re.patternOptions(); +// options == QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption +//! [6] +} + +{ +//! [7] +// match two digits followed by a space and a word +QRegularExpression re("\\d\\d \\w+"); +QRegularExpressionMatch match = re.match("abc123 def"); +bool hasMatch = match.hasMatch(); // true +//! [7] +} + +{ +//! [8] +QRegularExpression re("\\d\\d \\w+"); +QRegularExpressionMatch match = re.match("abc123 def"); +if (match.hasMatch()) { + QString matched = match.captured(0); // matched == "23 def" + // ... +} +//! [8] +} + +{ +//! [9] +QRegularExpression re("\\d\\d \\w+"); +QRegularExpressionMatch match = re.match("12 abc 45 def", 1); +if (match.hasMatch()) { + QString matched = match.captured(0); // matched == "45 def" + // ... +} +//! [9] +} + +{ +//! [10] +QRegularExpression re("^(\\d\\d)/(\\d\\d)/(\\d\\d\\d\\d)$"); +QRegularExpressionMatch match = re.match("08/12/1985"); +if (match.hasMatch()) { + QString day = match.captured(1); // day == "08" + QString month = match.captured(2); // month == "12" + QString year = match.captured(3); // year == "1985" + // ... +} +//! [10] +} + +{ +//! [11] +QRegularExpression re("abc(\\d+)def"); +QRegularExpressionMatch match = re.match("XYZabc123defXYZ"); +if (match.hasMatch()) { + int startOffset = match.capturedStart(1); // startOffset == 6 + int endOffset = match.capturedEnd(1); // endOffset == 9 + // ... +} +//! [11] +} + +{ +//! [12] +QRegularExpression re("^(?\\d\\d)/(?\\d\\d)/(?\\d\\d\\d\\d)$"); +QRegularExpressionMatch match = re.match("08/12/1985"); +if (match.hasMatch()) { + QString date = match.captured("date"); // date == "08" + QString month = match.captured("month"); // month == "12" + QString year = match.captured("year"); // year == 1985 +} +//! [12] +} + +{ +//! [13] +QRegularExpression re("(\\w+)"); +QRegularExpressionMatchIterator i = re.globalMatch("the quick fox"); +//! [13] + +//! [14] +QStringList words; +while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + QString word = match.captured(1); + words << word; +} +// words contains "the", "quick", "fox" +//! [14] +} + +{ +//! [15] +QString pattern("^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d?, \\d\\d\\d\\d$"); +QRegularExpression re(pattern); + +QString input("Jan 21,"); +QRegularExpressionMatch match = re.match(input, 0, QRegularExpression::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [15] +} + +{ +QString pattern("^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d?, \\d\\d\\d\\d$"); +QRegularExpression re(pattern); +//! [16] +QString input("Dec 8, 1985"); +QRegularExpressionMatch match = re.match(input, 0, QRegularExpression::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // true +bool hasPartialMatch = match.hasPartialMatch(); // false +//! [16] +} + +{ +//! [17] +QRegularExpression re("abc\\w+X|def"); +QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpression::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // true +bool hasPartialMatch = match.hasPartialMatch(); // false +QString captured = match.captured(0); // captured == "def" +//! [17] +} + +{ +//! [18] +QRegularExpression re("abc\\w+X|defY"); +QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpression::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +QString captured = match.captured(0); // captured == "abcdef" +//! [18] +} + +{ +//! [19] +QRegularExpression re("abc|ab"); +QRegularExpressionMatch match = re.match("ab", 0, QRegularExpression::PartialPreferFirstMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [19] +} + +{ +//! [20] +QRegularExpression re("abc(def)?"); +QRegularExpressionMatch match = re.match("abc", 0, QRegularExpression::PartialPreferFirstMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [20] +} + +{ +//! [21] +QRegularExpression re("(abc)*"); +QRegularExpressionMatch match = re.match("abc", 0, QRegularExpression::PartialPreferFirstMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [21] +} + +{ +//! [22] +QRegularExpression invalidRe("(unmatched|parenthesis"); +bool isValid = invalidRe.isValid(); // false +//! [22] +} + +{ +//! [23] +QRegularExpression invalidRe("(unmatched|parenthesis"); +if (!invalidRe.isValid()) { + QString errorString = invalidRe.errorString(); // errorString == "missing )" + int errorOffset = invalidRe.patternErrorOffset(); // errorOffset == 22 + // ... +} +//! [23] +} + +{ +//! [26] +QString escaped = QRegularExpression::escape("a(x) = f(x) + g(x)"); +// escaped == "a\\(x\\)\\ \\=\\ f\\(x\\)\\ \\+\\ g\\(x\\)" +//! [26] +} + +{ +QString name; +QString nickname; +//! [27] +QString pattern = "(" + QRegularExpression::escape(name) + + "|" + QRegularExpression::escape(nickname) + ")"; +QRegularExpression re(pattern); +//! [27] +} + +{ +QString string; +QRegularExpression re; +//! [28] +QRegularExpressionMatch match = re.match(string); +for (int i = 0; i <= match.lastCapturedIndex(); ++i) { + QString captured = match.captured(i); + // ... +} +//! [28] +} + +{ +//! [29] +QRegularExpression re("(\\d\\d) (?\\w+)"); +QRegularExpressionMatch match = re.match("23 Jordan"); +if (match.hasMatch()) { + QString number = match.captured(1); // first == "23" + QString name = match.captured("name"); // name == "Jordan" +} +//! [29] +} + +{ +//! [30] +// extracts the words +QRegularExpression re("(\\w+)"); +QString subject("the quick fox"); +QRegularExpressionMatchIterator i = re.globalMatch(subject); +while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + // ... +} +//! [30] +} + +{ +//! [31] +QString wildcard = QRegularExpression::wildcardToRegularExpression("*.jpeg"); +// Will match files with names like: +// foo.jpeg +// f_o_o.jpeg +// föö.jpeg +//! [31] +} + +//! [32] + (?\d\d)-(?\d\d)-(?\d\d\d\d) (\w+) (?\w+) +//! [32] + +//! [33] + ("", "day", "month", "year", "", "name") +//! [33] + +} diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qstring.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qstring.cpp new file mode 100644 index 0000000000..4e79d1e27a --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_text_qstring.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +DEFINES += QT_NO_CAST_FROM_ASCII \ + QT_NO_CAST_TO_ASCII +//! [0] + + +//! [1] +QString url = QLatin1String("http://www.unicode.org/"); +//! [1] + + +//! [2] +double d = 12.34; +QString str = QString("delta: %1").arg(d, 0, 'E', 3); +// str == "delta: 1.234E+01" +//! [2] + + +//! [3] +if (str == "auto" || str == "extern" + || str == "static" || str == "register") { + ... +} +//! [3] + + +//! [4] +if (str == QString("auto") || str == QString("extern") + || str == QString("static") || str == QString("register")) { + ... +} +//! [4] + + +//! [5] +if (str == QLatin1String("auto") + || str == QLatin1String("extern") + || str == QLatin1String("static") + || str == QLatin1String("register") { + ... +} +//! [5] + + +//! [6] +QLabel *label = new QLabel(QLatin1String("MOD"), this); +//! [6] + + +//! [7] +QString plain = "#include " +QString html = plain.toHtmlEscaped(); +// html == "#include <QtCore>" +//! [7] + +//! [8] +QString str("ab"); +str.repeated(4); // returns "abababab" +//! [8] + +//! [9] +// hasAttribute takes a QString argument +if (node.hasAttribute("http-contents-length")) //... +//! [9] + +//! [10] +if (node.hasAttribute(QStringLiteral(u"http-contents-length"))) //... +//! [10] + +//! [11] +if (attribute.name() == QLatin1String("http-contents-length")) //... +//! [11] diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qstringiterator.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qstringiterator.cpp new file mode 100644 index 0000000000..8085e32787 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_text_qstringiterator.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +int main() +{ + +{ +//! [0] +QString string(QStringLiteral("a string")); +QStringIterator i(string); // implicitly converted to QStringView +//! [0] + +//! [1] +while (i.hasNext()) + qDebug() << i.next(); +//! [1] +} + +{ +//! [2] +QStringIterator i(u"𝄞 is the G clef"); +qDebug() << Qt::hex << i.next(); // will print '𝄞' (U+1D11E, MUSICAL SYMBOL G CLEF) +qDebug() << Qt::hex << i.next(); // will print ' ' (U+0020, SPACE) +qDebug() << Qt::hex << i.next(); // will print 'i' (U+0069, LATIN SMALL LETTER I) +//! [2] +} + +} diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qstringview.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qstringview.cpp new file mode 100644 index 0000000000..fc426e1977 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_text_qstringview.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + void myfun1(QStringView sv); // preferred + void myfun2(const QStringView &sv); // compiles and works, but slower +//! [0] + +//! [1] + void fun(QChar ch) { fun(QStringView(&ch, 1)); } +//! [1] + +//! [2] + auto sv = QStringView(array, std::size(array)); // using C++17 std::size() +//! [2] diff --git a/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp b/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp new file mode 100644 index 0000000000..a477e91548 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp @@ -0,0 +1,218 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QDate d1(1995, 5, 17); // May 17, 1995 +QDate d2(1995, 5, 20); // May 20, 1995 +d1.daysTo(d2); // returns 3 +d2.daysTo(d1); // returns -3 +//! [0] + + +//! [1] +QDate date = QDate::fromString("1MM12car2003", "d'MM'MMcaryyyy"); +// date is 1 December 2003 +//! [1] + + +//! [2] +QDate date = QDate::fromString("130", "Md"); // invalid +//! [2] + + +//! [3] +QDate::fromString("1.30", "M.d"); // January 30 1900 +QDate::fromString("20000110", "yyyyMMdd"); // January 10, 2000 +QDate::fromString("20000110", "yyyyMd"); // January 10, 2000 +//! [3] + + +//! [4] +QDate::isValid(2002, 5, 17); // true +QDate::isValid(2002, 2, 30); // false (Feb 30 does not exist) +QDate::isValid(2004, 2, 29); // true (2004 is a leap year) +QDate::isValid(2000, 2, 29); // true (2000 is a leap year) +QDate::isValid(2006, 2, 29); // false (2006 is not a leap year) +QDate::isValid(2100, 2, 29); // false (2100 is not a leap year) +QDate::isValid(1202, 6, 6); // true (even though 1202 is pre-Gregorian) +//! [4] + + +//! [5] +QTime n(14, 0, 0); // n == 14:00:00 +QTime t; +t = n.addSecs(70); // t == 14:01:10 +t = n.addSecs(-70); // t == 13:58:50 +t = n.addSecs(10 * 60 * 60 + 5); // t == 00:00:05 +t = n.addSecs(-15 * 60 * 60); // t == 23:00:00 +//! [5] + + +//! [6] +QTime time = QTime::fromString("1mm12car00", "m'mm'hcarss"); +// time is 12:01.00 +//! [6] + + +//! [7] +QTime time = QTime::fromString("00:710", "hh:ms"); // invalid +//! [7] + + +//! [8] +QTime time = QTime::fromString("1.30", "m.s"); +// time is 00:01:30.000 +//! [8] + + +//! [9] +QTime::isValid(21, 10, 30); // returns true +QTime::isValid(22, 5, 62); // returns false +//! [9] + + +//! [10] +QTime t; +t.start(); +some_lengthy_task(); +qDebug("Time elapsed: %d ms", t.elapsed()); +//! [10] + + +//! [11] +QDateTime now = QDateTime::currentDateTime(); +QDateTime xmas(QDate(now.date().year(), 12, 25).startOfDay()); +qDebug("There are %d seconds to Christmas", now.secsTo(xmas)); +//! [11] + + +//! [12] +QTime time1 = QTime::fromString("131", "HHh"); +// time1 is 13:00:00 +QTime time1 = QTime::fromString("1apA", "1amAM"); +// time1 is 01:00:00 + +QDateTime dateTime2 = QDateTime::fromString("M1d1y9800:01:02", + "'M'M'd'd'y'yyhh:mm:ss"); +// dateTime is 1 January 1998 00:01:02 +//! [12] + + +//! [13] +QDateTime dateTime = QDateTime::fromString("130", "Mm"); // invalid +//! [13] + + +//! [14] +QDateTime dateTime = QDateTime::fromString("1.30.1", "M.d.s"); +// dateTime is January 30 in 1900 at 00:00:01. +dateTime = QDateTime::fromString("12", "yy"); +// dateTime is January 1 in 1912 at 00:00:00. +//! [14] + +//! [15] +QDateTime startDate(QDate(2012, 7, 6), QTime(8, 30, 0)); +QDateTime endDate(QDate(2012, 7, 7), QTime(16, 30, 0)); +qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); + +startDate = QDateTime(QDate(2012, 7, 6), QTime(23, 55, 0)); +endDate = QDateTime(QDate(2012, 7, 7), QTime(0, 5, 0)); +qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); + +qSwap(startDate, endDate); // Make endDate before startDate. +qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); +//! [15] + +//! [16] +QDateTime local(QDateTime::currentDateTime()); +QDateTime UTC(local.toTimeSpec(Qt::UTC)); +qDebug() << "Local time is:" << local; +qDebug() << "UTC time is:" << UTC; +qDebug() << "No difference between times:" << local.secsTo(UTC); +//! [16] + +//! [17] +QDateTime UTC(QDateTime::currentDateTimeUtc()); +QDateTime local(UTC.toLocalTime()); +qDebug() << "UTC time is:" << UTC; +qDebug() << "Local time is:" << local; +qDebug() << "No difference between times:" << UTC.secsTo(local); +//! [17] + +//! [18] +QDateTime local(QDateTime::currentDateTime()); +QDateTime UTC(local.toUTC()); +qDebug() << "Local time is:" << local; +qDebug() << "UTC time is:" << UTC; +qDebug() << "No difference between times:" << local.secsTo(UTC); +//! [18] + +//! [19] +QDateTime local(QDateTime::currentDateTime()); +qDebug() << "Local time is:" << local; + +QDateTime UTC(local); +UTC.setTimeSpec(Qt::UTC); +qDebug() << "UTC time is:" << UTC; + +qDebug() << "There are" << local.secsTo(UTC) << "seconds difference between the datetimes."; +//! [19] + +//! [20] +QString string = "Monday, 23 April 12 22:51:41"; +QString format = "dddd, d MMMM yy hh:mm:ss"; +QDateTime invalid = QDateTime::fromString(string, format); +//! [20] + +//! [21] +QString string = "Tuesday, 23 April 12 22:51:41"; +QString format = "dddd, d MMMM yy hh:mm:ss"; +QDateTime valid = QDateTime::fromString(string, format); +//! [21] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp deleted file mode 100644 index 9c07a2e92c..0000000000 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp +++ /dev/null @@ -1,509 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -void wrapInFunction() -{ - -//! [0] -QByteArray ba("Hello"); -//! [0] - - -//! [1] -QByteArray ba; -ba.resize(5); -ba[0] = 0x3c; -ba[1] = 0xb8; -ba[2] = 0x64; -ba[3] = 0x18; -ba[4] = 0xca; -//! [1] - - -//! [2] -for (int i = 0; i < ba.size(); ++i) { - if (ba.at(i) >= 'a' && ba.at(i) <= 'f') - cout << "Found character in range [a-f]" << Qt::endl; -} -//! [2] - - -//! [3] -QByteArray x("and"); -x.prepend("rock "); // x == "rock and" -x.append(" roll"); // x == "rock and roll" -x.replace(5, 3, "&"); // x == "rock & roll" -//! [3] - - -//! [4] -QByteArray ba("We must be bold, very bold"); -int j = 0; -while ((j = ba.indexOf("", j)) != -1) { - cout << "Found tag at index position " << j << Qt::endl; - ++j; -} -//! [4] - - -//! [5] -QByteArray().isNull(); // returns true -QByteArray().isEmpty(); // returns true - -QByteArray("").isNull(); // returns false -QByteArray("").isEmpty(); // returns true - -QByteArray("abc").isNull(); // returns false -QByteArray("abc").isEmpty(); // returns false -//! [5] - - -//! [6] -QByteArray ba("Hello"); -int n = ba.size(); // n == 5 -ba.data()[0]; // returns 'H' -ba.data()[4]; // returns 'o' -ba.data()[5]; // returns '\0' -//! [6] - - -//! [7] -QByteArray().isEmpty(); // returns true -QByteArray("").isEmpty(); // returns true -QByteArray("abc").isEmpty(); // returns false -//! [7] - - -//! [8] -QByteArray ba("Hello world"); -char *data = ba.data(); -while (*data) { - cout << "[" << *data << "]" << Qt::endl; - ++data; -} -//! [8] - - -//! [9] -QByteArray ba("Hello, world"); -cout << ba[0]; // prints H -ba[7] = 'W'; -// ba == "Hello, World" -//! [9] - - -//! [10] -QByteArray ba("Stockholm"); -ba.truncate(5); // ba == "Stock" -//! [10] - - -//! [11] -QByteArray ba("STARTTLS\r\n"); -ba.chop(2); // ba == "STARTTLS" -//! [11] - - -//! [12] -QByteArray x("free"); -QByteArray y("dom"); -x += y; -// x == "freedom" -//! [12] - - -//! [13] -QByteArray().isNull(); // returns true -QByteArray("").isNull(); // returns false -QByteArray("abc").isNull(); // returns false -//! [13] - - -//! [14] -QByteArray ba("Istambul"); -ba.fill('o'); -// ba == "oooooooo" - -ba.fill('X', 2); -// ba == "XX" -//! [14] - - -//! [15] -QByteArray x("ship"); -QByteArray y("air"); -x.prepend(y); -// x == "airship" -//! [15] - - -//! [16] -QByteArray x("free"); -QByteArray y("dom"); -x.append(y); -// x == "freedom" -//! [16] - - -//! [17] -QByteArray ba("Meal"); -ba.insert(1, QByteArray("ontr")); -// ba == "Montreal" -//! [17] - - -//! [18] -QByteArray ba("Montreal"); -ba.remove(1, 4); -// ba == "Meal" -//! [18] - - -//! [19] -QByteArray x("Say yes!"); -QByteArray y("no"); -x.replace(4, 3, y); -// x == "Say no!" -//! [19] - - -//! [20] -QByteArray ba("colour behaviour flavour neighbour"); -ba.replace(QByteArray("ou"), QByteArray("o")); -// ba == "color behavior flavor neighbor" -//! [20] - - -//! [21] -QByteArray x("sticky question"); -QByteArray y("sti"); -x.indexOf(y); // returns 0 -x.indexOf(y, 1); // returns 10 -x.indexOf(y, 10); // returns 10 -x.indexOf(y, 11); // returns -1 -//! [21] - - -//! [22] -QByteArray ba("ABCBA"); -ba.indexOf("B"); // returns 1 -ba.indexOf("B", 1); // returns 1 -ba.indexOf("B", 2); // returns 3 -ba.indexOf("X"); // returns -1 -//! [22] - - -//! [23] -QByteArray x("crazy azimuths"); -QByteArray y("az"); -x.lastIndexOf(y); // returns 6 -x.lastIndexOf(y, 6); // returns 6 -x.lastIndexOf(y, 5); // returns 2 -x.lastIndexOf(y, 1); // returns -1 -//! [23] - - -//! [24] -QByteArray ba("ABCBA"); -ba.lastIndexOf("B"); // returns 3 -ba.lastIndexOf("B", 3); // returns 3 -ba.lastIndexOf("B", 2); // returns 1 -ba.lastIndexOf("X"); // returns -1 -//! [24] - - -//! [25] -QByteArray url("ftp://ftp.qt-project.org/"); -if (url.startsWith("ftp:")) - ... -//! [25] - - -//! [26] -QByteArray url("http://qt-project.org/doc/qt-5.0/qtdoc/index.html"); -if (url.endsWith(".html")) - ... -//! [26] - - -//! [27] -QByteArray x("Pineapple"); -QByteArray y = x.left(4); -// y == "Pine" -//! [27] - - -//! [28] -QByteArray x("Pineapple"); -QByteArray y = x.right(5); -// y == "apple" -//! [28] - - -//! [29] -QByteArray x("Five pineapples"); -QByteArray y = x.mid(5, 4); // y == "pine" -QByteArray z = x.mid(5); // z == "pineapples" -//! [29] - - -//! [30] -QByteArray x("Qt by THE QT COMPANY"); -QByteArray y = x.toLower(); -// y == "qt by the qt company" -//! [30] - - -//! [31] -QByteArray x("Qt by THE QT COMPANY"); -QByteArray y = x.toUpper(); -// y == "QT BY THE QT COMPANY" -//! [31] - - -//! [32] -QByteArray ba(" lots\t of\nwhitespace\r\n "); -ba = ba.simplified(); -// ba == "lots of whitespace"; -//! [32] - - -//! [33] -QByteArray ba(" lots\t of\nwhitespace\r\n "); -ba = ba.trimmed(); -// ba == "lots\t of\nwhitespace"; -//! [33] - - -//! [34] -QByteArray x("apple"); -QByteArray y = x.leftJustified(8, '.'); // y == "apple..." -//! [34] - - -//! [35] -QByteArray x("apple"); -QByteArray y = x.rightJustified(8, '.'); // y == "...apple" -//! [35] - - -//! [36] -QByteArray str("FF"); -bool ok; -int hex = str.toInt(&ok, 16); // hex == 255, ok == true -int dec = str.toInt(&ok, 10); // dec == 0, ok == false -//! [36] - - -//! [37] -QByteArray str("FF"); -bool ok; -long hex = str.toLong(&ok, 16); // hex == 255, ok == true -long dec = str.toLong(&ok, 10); // dec == 0, ok == false -//! [37] - - -//! [38] -QByteArray string("1234.56"); -bool ok; -double a = string.toDouble(&ok); // a == 1234.56, ok == true - -string = "1234.56 Volt"; -a = str.toDouble(&ok); // a == 0, ok == false -//! [38] - -//! [38float] -QByteArray string("1234.56"); -bool ok; -float a = string.toFloat(&ok); // a == 1234.56, ok == true - -string = "1234.56 Volt"; -a = str.toFloat(&ok); // a == 0, ok == false -//! [38float] - -//! [39] -QByteArray text("Qt is great!"); -text.toBase64(); // returns "UXQgaXMgZ3JlYXQh" - -QByteArray text("

Hello?

"); -text.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals); // returns "PHA+SGVsbG8/PC9wPg" -text.toBase64(QByteArray::Base64Encoding); // returns "PHA+SGVsbG8/PC9wPg==" -text.toBase64(QByteArray::Base64UrlEncoding); // returns "PHA-SGVsbG8_PC9wPg==" -text.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); // returns "PHA-SGVsbG8_PC9wPg" -//! [39] - -//! [40] -QByteArray ba; -int n = 63; -ba.setNum(n); // ba == "63" -ba.setNum(n, 16); // ba == "3f" -//! [40] - - -//! [41] -int n = 63; -QByteArray::number(n); // returns "63" -QByteArray::number(n, 16); // returns "3f" -QByteArray::number(n, 16).toUpper(); // returns "3F" -//! [41] - - -//! [42] -QByteArray ba = QByteArray::number(12.3456, 'E', 3); -// ba == 1.235E+01 -//! [42] - - -//! [43] - static const char mydata[] = { - '\x00', '\x00', '\x03', '\x84', '\x78', '\x9c', '\x3b', '\x76', - '\xec', '\x18', '\xc3', '\x31', '\x0a', '\xf1', '\xcc', '\x99', - ... - '\x6d', '\x5b' -}; - -QByteArray data = QByteArray::fromRawData(mydata, sizeof(mydata)); -QDataStream in(&data, QIODevice::ReadOnly); -... -//! [43] - - -//! [44] -QByteArray text = QByteArray::fromBase64("UXQgaXMgZ3JlYXQh"); -text.data(); // returns "Qt is great!" - -QByteArray::fromBase64("PHA+SGVsbG8/PC9wPg==", QByteArray::Base64Encoding); // returns "

Hello?

" -QByteArray::fromBase64("PHA-SGVsbG8_PC9wPg==", QByteArray::Base64UrlEncoding); // returns "

Hello?

" -//! [44bis] - -//! [44ter] -void process(const QByteArray &); - -if (auto result = QByteArray::fromBase64Encoding(encodedData)) - process(*result); -//! [44ter] - -//! [44quater] -auto result = QByteArray::fromBase64Encoding(encodedData); -if (result.decodingStatus == QByteArray::Base64DecodingStatus::Ok) - process(result.decoded); -//! [44quater] - -//! [45] -QByteArray text = QByteArray::fromHex("517420697320677265617421"); -text.data(); // returns "Qt is great!" -//! [45] - -//! [46] -QString tmp = "test"; -QByteArray text = tmp.toLocal8Bit(); -char *data = new char[text.size()]; -strcpy(data, text.data()); -delete [] data; -//! [46] - -//! [47] -QString tmp = "test"; -QByteArray text = tmp.toLocal8Bit(); -char *data = new char[text.size() + 1]; -strcpy(data, text.data()); -delete [] data; -//! [47] - -//! [48] -QByteArray ba1("ca\0r\0t"); -ba1.size(); // Returns 2. -ba1.constData(); // Returns "ca" with terminating \0. - -QByteArray ba2("ca\0r\0t", 3); -ba2.size(); // Returns 3. -ba2.constData(); // Returns "ca\0" with terminating \0. - -QByteArray ba3("ca\0r\0t", 4); -ba3.size(); // Returns 4. -ba3.constData(); // Returns "ca\0r" with terminating \0. - -const char cart[] = {'c', 'a', '\0', 'r', '\0', 't'}; -QByteArray ba4(QByteArray::fromRawData(cart, 6)); -ba4.size(); // Returns 6. -ba4.constData(); // Returns "ca\0r\0t" without terminating \0. -//! [48] - -//! [49] -QByteArray ba("ab"); -ba.repeated(4); // returns "abababab" -//! [49] - -//! [50] -QByteArray macAddress = QByteArray::fromHex("123456abcdef"); -macAddress.toHex(':'); // returns "12:34:56:ab:cd:ef" -macAddress.toHex(0); // returns "123456abcdef" -//! [50] - -//! [51] -QByteArray text = QByteArray::fromPercentEncoding("Qt%20is%20great%33"); -text.data(); // returns "Qt is great!" -//! [51] - -//! [52] -QByteArray text = "{a fishy string?}"; -QByteArray ba = text.toPercentEncoding("{}", "s"); -qDebug(ba.constData()); -// prints "{a fi%73hy %73tring%3F}" -//! [52] - -//! [53] -QByteArray ba = QByteArrayLiteral("byte array contents"); -//! [53] - -} - - diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearraymatcher.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearraymatcher.cpp deleted file mode 100644 index 9cf94f0494..0000000000 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearraymatcher.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//! [0] -static const auto matcher = qMakeStaticByteArrayMatcher("needle"); -//! [0] - -//! [1] -static const auto matcher = qMakeStaticByteArrayMatcher("needle"); -//! [1] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp deleted file mode 100644 index a477e91548..0000000000 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//! [0] -QDate d1(1995, 5, 17); // May 17, 1995 -QDate d2(1995, 5, 20); // May 20, 1995 -d1.daysTo(d2); // returns 3 -d2.daysTo(d1); // returns -3 -//! [0] - - -//! [1] -QDate date = QDate::fromString("1MM12car2003", "d'MM'MMcaryyyy"); -// date is 1 December 2003 -//! [1] - - -//! [2] -QDate date = QDate::fromString("130", "Md"); // invalid -//! [2] - - -//! [3] -QDate::fromString("1.30", "M.d"); // January 30 1900 -QDate::fromString("20000110", "yyyyMMdd"); // January 10, 2000 -QDate::fromString("20000110", "yyyyMd"); // January 10, 2000 -//! [3] - - -//! [4] -QDate::isValid(2002, 5, 17); // true -QDate::isValid(2002, 2, 30); // false (Feb 30 does not exist) -QDate::isValid(2004, 2, 29); // true (2004 is a leap year) -QDate::isValid(2000, 2, 29); // true (2000 is a leap year) -QDate::isValid(2006, 2, 29); // false (2006 is not a leap year) -QDate::isValid(2100, 2, 29); // false (2100 is not a leap year) -QDate::isValid(1202, 6, 6); // true (even though 1202 is pre-Gregorian) -//! [4] - - -//! [5] -QTime n(14, 0, 0); // n == 14:00:00 -QTime t; -t = n.addSecs(70); // t == 14:01:10 -t = n.addSecs(-70); // t == 13:58:50 -t = n.addSecs(10 * 60 * 60 + 5); // t == 00:00:05 -t = n.addSecs(-15 * 60 * 60); // t == 23:00:00 -//! [5] - - -//! [6] -QTime time = QTime::fromString("1mm12car00", "m'mm'hcarss"); -// time is 12:01.00 -//! [6] - - -//! [7] -QTime time = QTime::fromString("00:710", "hh:ms"); // invalid -//! [7] - - -//! [8] -QTime time = QTime::fromString("1.30", "m.s"); -// time is 00:01:30.000 -//! [8] - - -//! [9] -QTime::isValid(21, 10, 30); // returns true -QTime::isValid(22, 5, 62); // returns false -//! [9] - - -//! [10] -QTime t; -t.start(); -some_lengthy_task(); -qDebug("Time elapsed: %d ms", t.elapsed()); -//! [10] - - -//! [11] -QDateTime now = QDateTime::currentDateTime(); -QDateTime xmas(QDate(now.date().year(), 12, 25).startOfDay()); -qDebug("There are %d seconds to Christmas", now.secsTo(xmas)); -//! [11] - - -//! [12] -QTime time1 = QTime::fromString("131", "HHh"); -// time1 is 13:00:00 -QTime time1 = QTime::fromString("1apA", "1amAM"); -// time1 is 01:00:00 - -QDateTime dateTime2 = QDateTime::fromString("M1d1y9800:01:02", - "'M'M'd'd'y'yyhh:mm:ss"); -// dateTime is 1 January 1998 00:01:02 -//! [12] - - -//! [13] -QDateTime dateTime = QDateTime::fromString("130", "Mm"); // invalid -//! [13] - - -//! [14] -QDateTime dateTime = QDateTime::fromString("1.30.1", "M.d.s"); -// dateTime is January 30 in 1900 at 00:00:01. -dateTime = QDateTime::fromString("12", "yy"); -// dateTime is January 1 in 1912 at 00:00:00. -//! [14] - -//! [15] -QDateTime startDate(QDate(2012, 7, 6), QTime(8, 30, 0)); -QDateTime endDate(QDate(2012, 7, 7), QTime(16, 30, 0)); -qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); - -startDate = QDateTime(QDate(2012, 7, 6), QTime(23, 55, 0)); -endDate = QDateTime(QDate(2012, 7, 7), QTime(0, 5, 0)); -qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); - -qSwap(startDate, endDate); // Make endDate before startDate. -qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); -//! [15] - -//! [16] -QDateTime local(QDateTime::currentDateTime()); -QDateTime UTC(local.toTimeSpec(Qt::UTC)); -qDebug() << "Local time is:" << local; -qDebug() << "UTC time is:" << UTC; -qDebug() << "No difference between times:" << local.secsTo(UTC); -//! [16] - -//! [17] -QDateTime UTC(QDateTime::currentDateTimeUtc()); -QDateTime local(UTC.toLocalTime()); -qDebug() << "UTC time is:" << UTC; -qDebug() << "Local time is:" << local; -qDebug() << "No difference between times:" << UTC.secsTo(local); -//! [17] - -//! [18] -QDateTime local(QDateTime::currentDateTime()); -QDateTime UTC(local.toUTC()); -qDebug() << "Local time is:" << local; -qDebug() << "UTC time is:" << UTC; -qDebug() << "No difference between times:" << local.secsTo(UTC); -//! [18] - -//! [19] -QDateTime local(QDateTime::currentDateTime()); -qDebug() << "Local time is:" << local; - -QDateTime UTC(local); -UTC.setTimeSpec(Qt::UTC); -qDebug() << "UTC time is:" << UTC; - -qDebug() << "There are" << local.secsTo(UTC) << "seconds difference between the datetimes."; -//! [19] - -//! [20] -QString string = "Monday, 23 April 12 22:51:41"; -QString format = "dddd, d MMMM yy hh:mm:ss"; -QDateTime invalid = QDateTime::fromString(string, format); -//! [20] - -//! [21] -QString string = "Tuesday, 23 April 12 22:51:41"; -QString format = "dddd, d MMMM yy hh:mm:ss"; -QDateTime valid = QDateTime::fromString(string, format); -//! [21] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp deleted file mode 100644 index aed14c379f..0000000000 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//! [0] -QLocale egyptian(QLocale::Arabic, QLocale::Egypt); -QString s1 = egyptian.toString(1.571429E+07, 'e'); -QString s2 = egyptian.toString(10); - -double d = egyptian.toDouble(s1); -int i = egyptian.toInt(s2); -//! [0] - - -//! [1] -QLocale::setDefault(QLocale(QLocale::Hebrew, QLocale::Israel)); -QLocale hebrew; // Constructs a default QLocale -QString s1 = hebrew.toString(15714.3, 'e'); - -bool ok; -double d; - -QLocale::setDefault(QLocale::C); -d = QString("1234,56").toDouble(&ok); // ok == false -d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 - -QLocale::setDefault(QLocale::German); -d = QString("1234,56").toDouble(&ok); // ok == true, d == 1234.56 -d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 - -QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); -str = QString("%1 %L2 %L3") - .arg(12345).arg(12345).arg(12345, 0, 16); -// str == "12345 12,345 3039" -//! [1] - - -//! [2] -QLocale korean("ko"); -QLocale swiss("de_CH"); -//! [2] - - -//! [3] -bool ok; -double d; - -QLocale c(QLocale::C); -d = c.toDouble( "1234.56", &ok ); // ok == true, d == 1234.56 -d = c.toDouble( "1,234.56", &ok ); // ok == true, d == 1234.56 -d = c.toDouble( "1234,56", &ok ); // ok == false - -QLocale german(QLocale::German); -d = german.toDouble( "1234,56", &ok ); // ok == true, d == 1234.56 -d = german.toDouble( "1.234,56", &ok ); // ok == true, d == 1234.56 -d = german.toDouble( "1234.56", &ok ); // ok == false - -d = german.toDouble( "1.234", &ok ); // ok == true, d == 1234.0 -//! [3] - -//! [3-qstringview] -bool ok; -double d; - -QLocale c(QLocale::C); -d = c.toDouble(u"1234.56", &ok); // ok == true, d == 1234.56 -d = c.toDouble(u"1,234.56", &ok); // ok == true, d == 1234.56 -d = c.toDouble(u"1234,56", &ok); // ok == false - -QLocale german(QLocale::German); -d = german.toDouble(u"1234,56", &ok); // ok == true, d == 1234.56 -d = german.toDouble(u"1.234,56", &ok); // ok == true, d == 1234.56 -d = german.toDouble(u"1234.56", &ok); // ok == false - -d = german.toDouble(u"1.234", &ok); // ok == true, d == 1234.0 -//! [3-qstringview] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qregexp.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qregexp.cpp deleted file mode 100644 index 8339ea413e..0000000000 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qregexp.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//! [0] -QRegExp rx("(\\d+)"); -QString str = "Offsets: 12 14 99 231 7"; -QStringList list; -int pos = 0; - -while ((pos = rx.indexIn(str, pos)) != -1) { - list << rx.cap(1); - pos += rx.matchedLength(); -} -// list: ["12", "14", "99", "231", "7"] -//! [0] - - -//! [1] -QRegExp rx("*.txt"); -rx.setPatternSyntax(QRegExp::Wildcard); -rx.exactMatch("README.txt"); // returns true -rx.exactMatch("welcome.txt.bak"); // returns false -//! [1] - - -//! [2] -QRegExp rx("ro+m"); -rx.setMinimal(true); -//! [2] - - -//! [3] -QRegExp mark("\\b" // word boundary - "[Mm]ark" // the word we want to match - ); -//! [3] - - -//! [4] -QRegExp rx("^\\d\\d?$"); // match integers 0 to 99 -rx.indexIn("123"); // returns -1 (no match) -rx.indexIn("-6"); // returns -1 (no match) -rx.indexIn("6"); // returns 0 (matched at position 0) -//! [4] - - -//! [5] -QRegExp rx("^\\S+$"); // match strings without whitespace -rx.indexIn("Hello world"); // returns -1 (no match) -rx.indexIn("This_is-OK"); // returns 0 (matched at position 0) -//! [5] - - -//! [6] -QRegExp rx("\\b(mail|letter|correspondence)\\b"); -rx.indexIn("I sent you an email"); // returns -1 (no match) -rx.indexIn("Please write the letter"); // returns 17 -//! [6] - - -//! [7] -QString captured = rx.cap(1); // captured == "letter" -//! [7] - - -//! [8] -QRegExp rx("&(?!amp;)"); // match ampersands but not & -QString line1 = "This & that"; -line1.replace(rx, "&"); -// line1 == "This & that" -QString line2 = "His & hers & theirs"; -line2.replace(rx, "&"); -// line2 == "His & hers & theirs" -//! [8] - - -//! [9] -QString str = "One Eric another Eirik, and an Ericsson. " - "How many Eiriks, Eric?"; -QRegExp rx("\\b(Eric|Eirik)\\b"); // match Eric or Eirik -int pos = 0; // where we are in the string -int count = 0; // how many Eric and Eirik's we've counted -while (pos >= 0) { - pos = rx.indexIn(str, pos); - if (pos >= 0) { - ++pos; // move along in str - ++count; // count our Eric or Eirik - } -} -//! [9] - - -//! [10] -str = "The Qt Company Ltd\tqt.io\tFinland"; -QString company, web, country; -rx.setPattern("^([^\t]+)\t([^\t]+)\t([^\t]+)$"); -if (rx.indexIn(str) != -1) { - company = rx.cap(1); - web = rx.cap(2); - country = rx.cap(3); -} -//! [10] - - -//! [11] -QStringList field = str.split("\t"); -//! [11] - - -//! [12] -QRegExp rx("*.html"); -rx.setPatternSyntax(QRegExp::Wildcard); -rx.exactMatch("index.html"); // returns true -rx.exactMatch("default.htm"); // returns false -rx.exactMatch("readme.txt"); // returns false -//! [12] - - -//! [13] -QString str = "offsets: 1.23 .50 71.00 6.00"; -QRegExp rx("\\d*\\.\\d+"); // primitive floating point matching -int count = 0; -int pos = 0; -while ((pos = rx.indexIn(str, pos)) != -1) { - ++count; - pos += rx.matchedLength(); -} -// pos will be 9, 14, 18 and finally 24; count will end up as 4 -//! [13] - - -//! [14] -QRegExp rx("(\\d+)(\\s*)(cm|inch(es)?)"); -int pos = rx.indexIn("Length: 36 inches"); -QStringList list = rx.capturedTexts(); -// list is now ("36 inches", "36", " ", "inches", "es") -//! [14] - - -//! [15] -QRegExp rx("(\\d+)(?:\\s*)(cm|inch(?:es)?)"); -int pos = rx.indexIn("Length: 36 inches"); -QStringList list = rx.capturedTexts(); -// list is now ("36 inches", "36", "inches") -//! [15] - - -//! [16] -QStringList list = rx.capturedTexts(); -QStringList::iterator it = list.begin(); -while (it != list.end()) { - myProcessing(*it); - ++it; -} -//! [16] - - -//! [17] -QRegExp rxlen("(\\d+)(?:\\s*)(cm|inch)"); -int pos = rxlen.indexIn("Length: 189cm"); -if (pos > -1) { - QString value = rxlen.cap(1); // "189" - QString unit = rxlen.cap(2); // "cm" - // ... -} -//! [17] - - -//! [18] -QRegExp rx("/([a-z]+)/([a-z]+)"); -rx.indexIn("Output /dev/null"); // returns 7 (position of /dev/null) -rx.pos(0); // returns 7 (position of /dev/null) -rx.pos(1); // returns 8 (position of dev) -rx.pos(2); // returns 12 (position of null) -//! [18] - - -//! [19] -s1 = QRegExp::escape("bingo"); // s1 == "bingo" -s2 = QRegExp::escape("f(x)"); // s2 == "f\\(x\\)" -//! [19] - - -//! [20] -QRegExp rx("(" + QRegExp::escape(name) + - "|" + QRegExp::escape(alias) + ")"); -//! [20] - -{ -//! [21] -QString p("a .*|pattern"); - -// re matches exactly the pattern string p -QRegularExpression re(QRegularExpression::anchoredPattern(p)); -//! [21] -} diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qregularexpression.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qregularexpression.cpp deleted file mode 100644 index b451ed5253..0000000000 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qregularexpression.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Giuseppe D'Angelo . -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -int main() { - -{ -//! [0] -QRegularExpression re("a pattern"); -//! [0] -} - -{ -//! [1] -QRegularExpression re; -re.setPattern("another pattern"); -//! [1] -} - -{ -//! [2] -// matches two digits followed by a space and a word -QRegularExpression re("\\d\\d \\w+"); - -// matches a backslash -QRegularExpression re2("\\\\"); -//! [2] -} - -{ -//! [3] -QRegularExpression re("a third pattern"); -QString pattern = re.pattern(); // pattern == "a third pattern" -//! [3] -} - -{ -//! [4] -// matches "Qt rocks", but also "QT rocks", "QT ROCKS", "qT rOcKs", etc. -QRegularExpression re("Qt rocks", QRegularExpression::CaseInsensitiveOption); -//! [4] -} - -{ -//! [5] -QRegularExpression re("^\\d+$"); -re.setPatternOptions(QRegularExpression::MultilineOption); -// re matches any line in the subject string that contains only digits (but at least one) -//! [5] -} - -{ -//! [6] -QRegularExpression re = QRegularExpression("^two.*words$", QRegularExpression::MultilineOption - | QRegularExpression::DotMatchesEverythingOption); - -QRegularExpression::PatternOptions options = re.patternOptions(); -// options == QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption -//! [6] -} - -{ -//! [7] -// match two digits followed by a space and a word -QRegularExpression re("\\d\\d \\w+"); -QRegularExpressionMatch match = re.match("abc123 def"); -bool hasMatch = match.hasMatch(); // true -//! [7] -} - -{ -//! [8] -QRegularExpression re("\\d\\d \\w+"); -QRegularExpressionMatch match = re.match("abc123 def"); -if (match.hasMatch()) { - QString matched = match.captured(0); // matched == "23 def" - // ... -} -//! [8] -} - -{ -//! [9] -QRegularExpression re("\\d\\d \\w+"); -QRegularExpressionMatch match = re.match("12 abc 45 def", 1); -if (match.hasMatch()) { - QString matched = match.captured(0); // matched == "45 def" - // ... -} -//! [9] -} - -{ -//! [10] -QRegularExpression re("^(\\d\\d)/(\\d\\d)/(\\d\\d\\d\\d)$"); -QRegularExpressionMatch match = re.match("08/12/1985"); -if (match.hasMatch()) { - QString day = match.captured(1); // day == "08" - QString month = match.captured(2); // month == "12" - QString year = match.captured(3); // year == "1985" - // ... -} -//! [10] -} - -{ -//! [11] -QRegularExpression re("abc(\\d+)def"); -QRegularExpressionMatch match = re.match("XYZabc123defXYZ"); -if (match.hasMatch()) { - int startOffset = match.capturedStart(1); // startOffset == 6 - int endOffset = match.capturedEnd(1); // endOffset == 9 - // ... -} -//! [11] -} - -{ -//! [12] -QRegularExpression re("^(?\\d\\d)/(?\\d\\d)/(?\\d\\d\\d\\d)$"); -QRegularExpressionMatch match = re.match("08/12/1985"); -if (match.hasMatch()) { - QString date = match.captured("date"); // date == "08" - QString month = match.captured("month"); // month == "12" - QString year = match.captured("year"); // year == 1985 -} -//! [12] -} - -{ -//! [13] -QRegularExpression re("(\\w+)"); -QRegularExpressionMatchIterator i = re.globalMatch("the quick fox"); -//! [13] - -//! [14] -QStringList words; -while (i.hasNext()) { - QRegularExpressionMatch match = i.next(); - QString word = match.captured(1); - words << word; -} -// words contains "the", "quick", "fox" -//! [14] -} - -{ -//! [15] -QString pattern("^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d?, \\d\\d\\d\\d$"); -QRegularExpression re(pattern); - -QString input("Jan 21,"); -QRegularExpressionMatch match = re.match(input, 0, QRegularExpression::PartialPreferCompleteMatch); -bool hasMatch = match.hasMatch(); // false -bool hasPartialMatch = match.hasPartialMatch(); // true -//! [15] -} - -{ -QString pattern("^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d?, \\d\\d\\d\\d$"); -QRegularExpression re(pattern); -//! [16] -QString input("Dec 8, 1985"); -QRegularExpressionMatch match = re.match(input, 0, QRegularExpression::PartialPreferCompleteMatch); -bool hasMatch = match.hasMatch(); // true -bool hasPartialMatch = match.hasPartialMatch(); // false -//! [16] -} - -{ -//! [17] -QRegularExpression re("abc\\w+X|def"); -QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpression::PartialPreferCompleteMatch); -bool hasMatch = match.hasMatch(); // true -bool hasPartialMatch = match.hasPartialMatch(); // false -QString captured = match.captured(0); // captured == "def" -//! [17] -} - -{ -//! [18] -QRegularExpression re("abc\\w+X|defY"); -QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpression::PartialPreferCompleteMatch); -bool hasMatch = match.hasMatch(); // false -bool hasPartialMatch = match.hasPartialMatch(); // true -QString captured = match.captured(0); // captured == "abcdef" -//! [18] -} - -{ -//! [19] -QRegularExpression re("abc|ab"); -QRegularExpressionMatch match = re.match("ab", 0, QRegularExpression::PartialPreferFirstMatch); -bool hasMatch = match.hasMatch(); // false -bool hasPartialMatch = match.hasPartialMatch(); // true -//! [19] -} - -{ -//! [20] -QRegularExpression re("abc(def)?"); -QRegularExpressionMatch match = re.match("abc", 0, QRegularExpression::PartialPreferFirstMatch); -bool hasMatch = match.hasMatch(); // false -bool hasPartialMatch = match.hasPartialMatch(); // true -//! [20] -} - -{ -//! [21] -QRegularExpression re("(abc)*"); -QRegularExpressionMatch match = re.match("abc", 0, QRegularExpression::PartialPreferFirstMatch); -bool hasMatch = match.hasMatch(); // false -bool hasPartialMatch = match.hasPartialMatch(); // true -//! [21] -} - -{ -//! [22] -QRegularExpression invalidRe("(unmatched|parenthesis"); -bool isValid = invalidRe.isValid(); // false -//! [22] -} - -{ -//! [23] -QRegularExpression invalidRe("(unmatched|parenthesis"); -if (!invalidRe.isValid()) { - QString errorString = invalidRe.errorString(); // errorString == "missing )" - int errorOffset = invalidRe.patternErrorOffset(); // errorOffset == 22 - // ... -} -//! [23] -} - -{ -//! [26] -QString escaped = QRegularExpression::escape("a(x) = f(x) + g(x)"); -// escaped == "a\\(x\\)\\ \\=\\ f\\(x\\)\\ \\+\\ g\\(x\\)" -//! [26] -} - -{ -QString name; -QString nickname; -//! [27] -QString pattern = "(" + QRegularExpression::escape(name) + - "|" + QRegularExpression::escape(nickname) + ")"; -QRegularExpression re(pattern); -//! [27] -} - -{ -QString string; -QRegularExpression re; -//! [28] -QRegularExpressionMatch match = re.match(string); -for (int i = 0; i <= match.lastCapturedIndex(); ++i) { - QString captured = match.captured(i); - // ... -} -//! [28] -} - -{ -//! [29] -QRegularExpression re("(\\d\\d) (?\\w+)"); -QRegularExpressionMatch match = re.match("23 Jordan"); -if (match.hasMatch()) { - QString number = match.captured(1); // first == "23" - QString name = match.captured("name"); // name == "Jordan" -} -//! [29] -} - -{ -//! [30] -// extracts the words -QRegularExpression re("(\\w+)"); -QString subject("the quick fox"); -QRegularExpressionMatchIterator i = re.globalMatch(subject); -while (i.hasNext()) { - QRegularExpressionMatch match = i.next(); - // ... -} -//! [30] -} - -{ -//! [31] -QString wildcard = QRegularExpression::wildcardToRegularExpression("*.jpeg"); -// Will match files with names like: -// foo.jpeg -// f_o_o.jpeg -// föö.jpeg -//! [31] -} - -//! [32] - (?\d\d)-(?\d\d)-(?\d\d\d\d) (\w+) (?\w+) -//! [32] - -//! [33] - ("", "day", "month", "year", "", "name") -//! [33] - -} diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp deleted file mode 100644 index 4e79d1e27a..0000000000 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//! [0] -DEFINES += QT_NO_CAST_FROM_ASCII \ - QT_NO_CAST_TO_ASCII -//! [0] - - -//! [1] -QString url = QLatin1String("http://www.unicode.org/"); -//! [1] - - -//! [2] -double d = 12.34; -QString str = QString("delta: %1").arg(d, 0, 'E', 3); -// str == "delta: 1.234E+01" -//! [2] - - -//! [3] -if (str == "auto" || str == "extern" - || str == "static" || str == "register") { - ... -} -//! [3] - - -//! [4] -if (str == QString("auto") || str == QString("extern") - || str == QString("static") || str == QString("register")) { - ... -} -//! [4] - - -//! [5] -if (str == QLatin1String("auto") - || str == QLatin1String("extern") - || str == QLatin1String("static") - || str == QLatin1String("register") { - ... -} -//! [5] - - -//! [6] -QLabel *label = new QLabel(QLatin1String("MOD"), this); -//! [6] - - -//! [7] -QString plain = "#include " -QString html = plain.toHtmlEscaped(); -// html == "#include <QtCore>" -//! [7] - -//! [8] -QString str("ab"); -str.repeated(4); // returns "abababab" -//! [8] - -//! [9] -// hasAttribute takes a QString argument -if (node.hasAttribute("http-contents-length")) //... -//! [9] - -//! [10] -if (node.hasAttribute(QStringLiteral(u"http-contents-length"))) //... -//! [10] - -//! [11] -if (attribute.name() == QLatin1String("http-contents-length")) //... -//! [11] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp deleted file mode 100644 index 8085e32787..0000000000 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include - -int main() -{ - -{ -//! [0] -QString string(QStringLiteral("a string")); -QStringIterator i(string); // implicitly converted to QStringView -//! [0] - -//! [1] -while (i.hasNext()) - qDebug() << i.next(); -//! [1] -} - -{ -//! [2] -QStringIterator i(u"𝄞 is the G clef"); -qDebug() << Qt::hex << i.next(); // will print '𝄞' (U+1D11E, MUSICAL SYMBOL G CLEF) -qDebug() << Qt::hex << i.next(); // will print ' ' (U+0020, SPACE) -qDebug() << Qt::hex << i.next(); // will print 'i' (U+0069, LATIN SMALL LETTER I) -//! [2] -} - -} diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qstringview.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qstringview.cpp deleted file mode 100644 index fc426e1977..0000000000 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qstringview.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//! [0] - void myfun1(QStringView sv); // preferred - void myfun2(const QStringView &sv); // compiles and works, but slower -//! [0] - -//! [1] - void fun(QChar ch) { fun(QStringView(&ch, 1)); } -//! [1] - -//! [2] - auto sv = QStringView(array, std::size(array)); // using C++17 std::size() -//! [2] -- cgit v1.2.3