Docs: Use Qt::SplitBehavior in preference to QString::SplitBehavior
The Qt version was added in 5.14 "for use as eventual replacement for QString::SplitBehavior." Move another step closer to that goal. Applied suitable wrapping round various char and string literals, since docs are meant to show best practice. Change-Id: Ie061905fad26f9b4dda3eedba4612704f0a19126 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
8de66e1f24
commit
c158f881b3
@ -61,7 +61,7 @@ Message::Message(const QString &body, const QStringList &headers)
|
|||||||
QDebug operator<<(QDebug dbg, const Message &message)
|
QDebug operator<<(QDebug dbg, const Message &message)
|
||||||
{
|
{
|
||||||
const QString body = message.body();
|
const QString body = message.body();
|
||||||
QVector<QStringRef> pieces = body.splitRef("\r\n", QString::SkipEmptyParts);
|
QVector<QStringRef> pieces = body.splitRef(QLatin1String("\r\n"), Qt::SkipEmptyParts);
|
||||||
if (pieces.isEmpty())
|
if (pieces.isEmpty())
|
||||||
dbg.nospace() << "Message()";
|
dbg.nospace() << "Message()";
|
||||||
else if (pieces.size() == 1)
|
else if (pieces.size() == 1)
|
||||||
|
@ -86,7 +86,7 @@ void Dialog::submit()
|
|||||||
int albumId = addNewAlbum(title, artistId);
|
int albumId = addNewAlbum(title, artistId);
|
||||||
|
|
||||||
QStringList tracks;
|
QStringList tracks;
|
||||||
tracks = tracksEditor->text().split(',', QString::SkipEmptyParts);
|
tracks = tracksEditor->text().split(QLatin1Char(','), Qt::SkipEmptyParts);
|
||||||
addTracks(albumId, tracks);
|
addTracks(albumId, tracks);
|
||||||
|
|
||||||
increaseAlbumCount(indexOfArtist(artist));
|
increaseAlbumCount(indexOfArtist(artist));
|
||||||
|
@ -113,7 +113,7 @@ void DragWidget::dropEvent(QDropEvent *event)
|
|||||||
if (event->mimeData()->hasText()) {
|
if (event->mimeData()->hasText()) {
|
||||||
const QMimeData *mime = event->mimeData();
|
const QMimeData *mime = event->mimeData();
|
||||||
QStringList pieces = mime->text().split(QRegularExpression(QStringLiteral("\\s+")),
|
QStringList pieces = mime->text().split(QRegularExpression(QStringLiteral("\\s+")),
|
||||||
QString::SkipEmptyParts);
|
Qt::SkipEmptyParts);
|
||||||
QPoint position = event->pos();
|
QPoint position = event->pos();
|
||||||
QPoint hotSpot;
|
QPoint hotSpot;
|
||||||
|
|
||||||
|
@ -163,8 +163,8 @@ void DragWidget::dropEvent(QDropEvent *event)
|
|||||||
}
|
}
|
||||||
//! [11] //! [12]
|
//! [11] //! [12]
|
||||||
} else if (event->mimeData()->hasText()) {
|
} else if (event->mimeData()->hasText()) {
|
||||||
QStringList pieces = event->mimeData()->text().split(QRegularExpression(QStringLiteral("\\s+")),
|
QStringList pieces = event->mimeData()->text().split(
|
||||||
QString::SkipEmptyParts);
|
QRegularExpression(QStringLiteral("\\s+")), Qt::SkipEmptyParts);
|
||||||
QPoint position = event->pos();
|
QPoint position = event->pos();
|
||||||
|
|
||||||
for (const QString &piece : pieces) {
|
for (const QString &piece : pieces) {
|
||||||
|
@ -59,7 +59,7 @@ Window::Window(QGraphicsItem *parent) : QGraphicsWidget(parent, Qt::Window)
|
|||||||
FlowLayout *lay = new FlowLayout;
|
FlowLayout *lay = new FlowLayout;
|
||||||
const QString sentence(QLatin1String("I am not bothered by the fact that I am unknown."
|
const QString sentence(QLatin1String("I am not bothered by the fact that I am unknown."
|
||||||
" I am bothered when I do not know others. (Confucius)"));
|
" I am bothered when I do not know others. (Confucius)"));
|
||||||
const QVector<QStringRef> words = sentence.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
|
const QVector<QStringRef> words = sentence.splitRef(QLatin1Char(' '), Qt::SkipEmptyParts);
|
||||||
for (const QStringRef &word : words) {
|
for (const QStringRef &word : words) {
|
||||||
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
|
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
|
||||||
QLabel *label = new QLabel(word.toString());
|
QLabel *label = new QLabel(word.toString());
|
||||||
|
@ -134,7 +134,7 @@ void MainWindow::loadFile(const QString &fileName)
|
|||||||
if (!line.isEmpty()) {
|
if (!line.isEmpty()) {
|
||||||
model->insertRows(row, 1, QModelIndex());
|
model->insertRows(row, 1, QModelIndex());
|
||||||
|
|
||||||
const QStringList pieces = line.split(',', QString::SkipEmptyParts);
|
const QStringList pieces = line.split(QLatin1Char(','), Qt::SkipEmptyParts);
|
||||||
if (pieces.size() < 3)
|
if (pieces.size() < 3)
|
||||||
continue;
|
continue;
|
||||||
model->setData(model->index(row, 0, QModelIndex()),
|
model->setData(model->index(row, 0, QModelIndex()),
|
||||||
|
@ -267,7 +267,8 @@ void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
|
|||||||
|
|
||||||
if (!lineData.isEmpty()) {
|
if (!lineData.isEmpty()) {
|
||||||
// Read the column data from the rest of the line.
|
// Read the column data from the rest of the line.
|
||||||
const QStringList columnStrings = lineData.split('\t', QString::SkipEmptyParts);
|
const QStringList columnStrings =
|
||||||
|
lineData.split(QLatin1Char('\t'), Qt::SkipEmptyParts);
|
||||||
QVector<QVariant> columnData;
|
QVector<QVariant> columnData;
|
||||||
columnData.reserve(columnStrings.size());
|
columnData.reserve(columnStrings.size());
|
||||||
for (const QString &columnString : columnStrings)
|
for (const QString &columnString : columnStrings)
|
||||||
|
@ -194,7 +194,8 @@ void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
|
|||||||
|
|
||||||
if (!lineData.isEmpty()) {
|
if (!lineData.isEmpty()) {
|
||||||
// Read the column data from the rest of the line.
|
// Read the column data from the rest of the line.
|
||||||
const QStringList columnStrings = lineData.split('\t', QString::SkipEmptyParts);
|
const QStringList columnStrings =
|
||||||
|
lineData.split(QLatin1Char('\t'), Qt::SkipEmptyParts);
|
||||||
QVector<QVariant> columnData;
|
QVector<QVariant> columnData;
|
||||||
columnData.reserve(columnStrings.count());
|
columnData.reserve(columnStrings.count());
|
||||||
for (const QString &columnString : columnStrings)
|
for (const QString &columnString : columnStrings)
|
||||||
|
@ -413,7 +413,7 @@ void AddressBook::exportAsVCard()
|
|||||||
int index = name.indexOf(" ");
|
int index = name.indexOf(" ");
|
||||||
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
nameList = name.split(QRegularExpression("\\s+"), QString::SkipEmptyParts);
|
nameList = name.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
||||||
firstName = nameList.first();
|
firstName = nameList.first();
|
||||||
lastName = nameList.last();
|
lastName = nameList.last();
|
||||||
} else {
|
} else {
|
||||||
|
@ -766,7 +766,7 @@ void Widget::splitFunction()
|
|||||||
|
|
||||||
//! [60]
|
//! [60]
|
||||||
str = "This time, a normal English sentence.";
|
str = "This time, a normal English sentence.";
|
||||||
list = str.split(QRegExp("\\W+"), QString::SkipEmptyParts);
|
list = str.split(QRegExp("\\W+"), Qt::SkipEmptyParts);
|
||||||
// list: [ "This", "time", "a", "normal", "English", "sentence" ]
|
// list: [ "This", "time", "a", "normal", "English", "sentence" ]
|
||||||
//! [60]
|
//! [60]
|
||||||
|
|
||||||
@ -787,7 +787,7 @@ void Widget::splitFunction()
|
|||||||
|
|
||||||
//! [91]
|
//! [91]
|
||||||
str = "This time, a normal English sentence.";
|
str = "This time, a normal English sentence.";
|
||||||
list = str.split(QRegularExpression("\\W+"), QString::SkipEmptyParts);
|
list = str.split(QRegularExpression("\\W+"), Qt::SkipEmptyParts);
|
||||||
// list: [ "This", "time", "a", "normal", "English", "sentence" ]
|
// list: [ "This", "time", "a", "normal", "English", "sentence" ]
|
||||||
//! [91]
|
//! [91]
|
||||||
|
|
||||||
@ -801,24 +801,24 @@ void Widget::splitFunction()
|
|||||||
void Widget::splitCaseSensitiveFunction()
|
void Widget::splitCaseSensitiveFunction()
|
||||||
{
|
{
|
||||||
//! [62]
|
//! [62]
|
||||||
QString str = "a,,b,c";
|
QString str = QStringLiteral("a,,b,c");
|
||||||
|
|
||||||
QStringList list1 = str.split(',');
|
QStringList list1 = str.split(QLatin1Char(','));
|
||||||
// list1: [ "a", "", "b", "c" ]
|
// list1: [ "a", "", "b", "c" ]
|
||||||
|
|
||||||
QStringList list2 = str.split(',', QString::SkipEmptyParts);
|
QStringList list2 = str.split(QLatin1Char(','), Qt::SkipEmptyParts);
|
||||||
// list2: [ "a", "b", "c" ]
|
// list2: [ "a", "b", "c" ]
|
||||||
//! [62]
|
//! [62]
|
||||||
|
|
||||||
//! [62-empty]
|
//! [62-empty]
|
||||||
QString str = "abc";
|
QString str = "abc";
|
||||||
auto parts = str.split("");
|
auto parts = str.split(QString());
|
||||||
// parts: {"", "a", "b", "c", ""}
|
// parts: {"", "a", "b", "c", ""}
|
||||||
//! [62-empty]
|
//! [62-empty]
|
||||||
|
|
||||||
//! [62-slashes]
|
//! [62-slashes]
|
||||||
QString str = "/a/b/c/";
|
QString str = "/a/b/c/";
|
||||||
auto parts = str.split('/');
|
auto parts = str.split(QLatin1Char('/'));
|
||||||
// parts: {"", "a", "b", "c", ""}
|
// parts: {"", "a", "b", "c", ""}
|
||||||
//! [62-slashes]
|
//! [62-slashes]
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ void MainWindow::setupContents()
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
QString line = titlesFile.readLine().trimmed();
|
QString line = titlesFile.readLine().trimmed();
|
||||||
QStringList parts = line.split("\t", QString::SkipEmptyParts);
|
QStringList parts = line.split(QLatin1Char('\t'), Qt::SkipEmptyParts);
|
||||||
if (parts.size() != 2)
|
if (parts.size() != 2)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user