qcollator_icu.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qcollator_icu.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org>-
5** Contact: https://www.qt.io/licensing/-
6**-
7** This file is part of the QtCore module of the Qt Toolkit.-
8**-
9** $QT_BEGIN_LICENSE:LGPL$-
10** Commercial License Usage-
11** Licensees holding valid commercial Qt licenses may use this file in-
12** accordance with the commercial license agreement provided with the-
13** Software or, alternatively, in accordance with the terms contained in-
14** a written agreement between you and The Qt Company. For licensing terms-
15** and conditions see https://www.qt.io/terms-conditions. For further-
16** information use the contact form at https://www.qt.io/contact-us.-
17**-
18** GNU Lesser General Public License Usage-
19** Alternatively, this file may be used under the terms of the GNU Lesser-
20** General Public License version 3 as published by the Free Software-
21** Foundation and appearing in the file LICENSE.LGPL3 included in the-
22** packaging of this file. Please review the following information to-
23** ensure the GNU Lesser General Public License version 3 requirements-
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
25**-
26** GNU General Public License Usage-
27** Alternatively, this file may be used under the terms of the GNU-
28** General Public License version 2.0 or (at your option) the GNU General-
29** Public license version 3 or any later version approved by the KDE Free-
30** Qt Foundation. The licenses are as published by the Free Software-
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
32** included in the packaging of this file. Please review the following-
33** information to ensure the GNU General Public License requirements will-
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
35** https://www.gnu.org/licenses/gpl-3.0.html.-
36**-
37** $QT_END_LICENSE$-
38**-
39****************************************************************************/-
40-
41#include "qcollator_p.h"-
42#include "qstringlist.h"-
43#include "qstring.h"-
44-
45#include <unicode/utypes.h>-
46#include <unicode/ucol.h>-
47#include <unicode/ustring.h>-
48#include <unicode/ures.h>-
49-
50#include "qdebug.h"-
51-
52QT_BEGIN_NAMESPACE-
53-
54void QCollatorPrivate::init()-
55{-
56 cleanup();-
57-
58 UErrorCode status = U_ZERO_ERROR;-
59 QByteArray name = locale.bcp47Name().replace(QLatin1Char('-'), QLatin1Char('_')).toLatin1();-
60 collator = ucol_open(name.constData(), &status);-
61 if (U_FAILURE(status)) {
U_FAILURE(status)Description
TRUEnever evaluated
FALSEevaluated 336 times by 13 tests
Evaluated by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
  • tst_languageChange
0-336
62 qWarning("Could not create collator: %d", status);-
63 collator = 0;-
64 dirty = false;-
65 return;
never executed: return;
0
66 }-
67-
68 // enable normalization by default-
69 ucol_setAttribute(collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);-
70-
71 // The strength attribute in ICU is rather badly documented. Basically UCOL_PRIMARY-
72 // ignores differences between base characters and accented characters as well as case.-
73 // So A and A-umlaut would compare equal.-
74 // UCOL_SECONDARY ignores case differences. UCOL_TERTIARY is the default in most languages-
75 // and does case sensitive comparison.-
76 // UCOL_QUATERNARY is used as default in a few languages such as Japanese to take care of some-
77 // additional differences in those languages.-
78 UColAttributeValue val = (caseSensitivity == Qt::CaseSensitive) ? UCOL_DEFAULT_STRENGTH : UCOL_SECONDARY;
(caseSensitivi...CaseSensitive)Description
TRUEevaluated 198 times by 13 tests
Evaluated by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
  • tst_languageChange
FALSEevaluated 138 times by 6 tests
Evaluated by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
138-198
79-
80 status = U_ZERO_ERROR;-
81 ucol_setAttribute(collator, UCOL_STRENGTH, val, &status);-
82 if (U_FAILURE(status))
U_FAILURE(status)Description
TRUEnever evaluated
FALSEevaluated 336 times by 13 tests
Evaluated by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
  • tst_languageChange
0-336
83 qWarning("ucol_setAttribute: Case First failed: %d", status);
never executed: QMessageLogger(__FILE__, 83, __PRETTY_FUNCTION__).warning("ucol_setAttribute: Case First failed: %d", status);
0
84-
85 status = U_ZERO_ERROR;-
86 ucol_setAttribute(collator, UCOL_NUMERIC_COLLATION, numericMode ? UCOL_ON : UCOL_OFF, &status);-
87 if (U_FAILURE(status))
U_FAILURE(status)Description
TRUEnever evaluated
FALSEevaluated 336 times by 13 tests
Evaluated by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
  • tst_languageChange
0-336
88 qWarning("ucol_setAttribute: numeric collation failed: %d", status);
never executed: QMessageLogger(__FILE__, 88, __PRETTY_FUNCTION__).warning("ucol_setAttribute: numeric collation failed: %d", status);
0
89-
90 status = U_ZERO_ERROR;-
91 ucol_setAttribute(collator, UCOL_ALTERNATE_HANDLING, ignorePunctuation ? UCOL_SHIFTED : UCOL_NON_IGNORABLE, &status);-
92 if (U_FAILURE(status))
U_FAILURE(status)Description
TRUEnever evaluated
FALSEevaluated 336 times by 13 tests
Evaluated by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
  • tst_languageChange
0-336
93 qWarning("ucol_setAttribute: Alternate handling failed: %d", status);
never executed: QMessageLogger(__FILE__, 93, __PRETTY_FUNCTION__).warning("ucol_setAttribute: Alternate handling failed: %d", status);
0
94-
95 dirty = false;-
96}
executed 336 times by 13 tests: end of block
Executed by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
  • tst_languageChange
336
97-
98void QCollatorPrivate::cleanup()-
99{-
100 if (collator)
collatorDescription
TRUEevaluated 336 times by 13 tests
Evaluated by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
  • tst_languageChange
  • tst_modeltest - unknown status
  • tst_qitemmodel - unknown status
  • tst_qlistwidget - unknown status
  • tst_qtablewidget - unknown status
  • tst_qtreewidget - unknown status
  • tst_qtreewidgetitemiterator - unknown status
FALSEevaluated 386 times by 13 tests
Evaluated by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
  • tst_languageChange
336-386
101 ucol_close(collator);
executed 336 times by 13 tests: ucol_close_52(collator);
Executed by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
  • tst_languageChange
  • tst_modeltest - unknown status
  • tst_qitemmodel - unknown status
  • tst_qlistwidget - unknown status
  • tst_qtablewidget - unknown status
  • tst_qtreewidget - unknown status
  • tst_qtreewidgetitemiterator - unknown status
336
102 collator = 0;-
103}
executed 722 times by 19 tests: end of block
Executed by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
  • tst_languageChange
  • tst_modeltest - unknown status
  • tst_qitemmodel - unknown status
  • tst_qlistwidget - unknown status
  • tst_qtablewidget - unknown status
  • tst_qtreewidget - unknown status
  • tst_qtreewidgetitemiterator - unknown status
722
104-
105int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const-
106{-
107 if (d->dirty)
d->dirtyDescription
TRUEevaluated 143 times by 6 tests
Evaluated by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
FALSEevaluated 18877 times by 12 tests
Evaluated by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
143-18877
108 d->init();
executed 143 times by 6 tests: d->init();
Executed by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
143
109-
110 if (d->collator)
d->collatorDescription
TRUEevaluated 19020 times by 12 tests
Evaluated by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
FALSEnever evaluated
0-19020
111 return ucol_strcoll(d->collator, (const UChar *)s1, len1, (const UChar *)s2, len2);
executed 19020 times by 12 tests: return ucol_strcoll_52(d->collator, (const UChar *)s1, len1, (const UChar *)s2, len2);
Executed by:
  • tst_ModelTest
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QItemModel
  • tst_QListWidget
  • tst_QPrinter
  • tst_QTableWidget
  • tst_QTreeWidget
  • tst_QTreeWidgetItemIterator
19020
112-
113 return QString::compare(QString(s1, len1), QString(s2, len2), d->caseSensitivity);
never executed: return QString::compare(QString(s1, len1), QString(s2, len2), d->caseSensitivity);
0
114}-
115-
116int QCollator::compare(const QString &s1, const QString &s2) const-
117{-
118 if (d->collator)
d->collatorDescription
TRUEevaluated 7625 times by 6 tests
Evaluated by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
FALSEnever evaluated
0-7625
119 return compare(s1.constData(), s1.size(), s2.constData(), s2.size());
executed 7625 times by 6 tests: return compare(s1.constData(), s1.size(), s2.constData(), s2.size());
Executed by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
7625
120-
121 return QString::compare(s1, s2, d->caseSensitivity);
never executed: return QString::compare(s1, s2, d->caseSensitivity);
0
122}-
123-
124int QCollator::compare(const QStringRef &s1, const QStringRef &s2) const-
125{-
126 if (d->collator)
d->collatorDescription
TRUEnever evaluated
FALSEnever evaluated
0
127 return compare(s1.constData(), s1.size(), s2.constData(), s2.size());
never executed: return compare(s1.constData(), s1.size(), s2.constData(), s2.size());
0
128-
129 return QStringRef::compare(s1, s2, d->caseSensitivity);
never executed: return QStringRef::compare(s1, s2, d->caseSensitivity);
0
130}-
131-
132QCollatorSortKey QCollator::sortKey(const QString &string) const-
133{-
134 if (d->dirty)
d->dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
135 d->init();
never executed: d->init();
0
136-
137 if (d->collator) {
d->collatorDescription
TRUEnever evaluated
FALSEnever evaluated
0
138 QByteArray result(16 + string.size() + (string.size() >> 2), Qt::Uninitialized);-
139 int size = ucol_getSortKey(d->collator, (const UChar *)string.constData(),-
140 string.size(), (uint8_t *)result.data(), result.size());-
141 if (size > result.size()) {
size > result.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
142 result.resize(size);-
143 size = ucol_getSortKey(d->collator, (const UChar *)string.constData(),-
144 string.size(), (uint8_t *)result.data(), result.size());-
145 }
never executed: end of block
0
146 result.truncate(size);-
147 return QCollatorSortKey(new QCollatorSortKeyPrivate(result));
never executed: return QCollatorSortKey(new QCollatorSortKeyPrivate(result));
0
148 }-
149-
150 return QCollatorSortKey(new QCollatorSortKeyPrivate(QByteArray()));
never executed: return QCollatorSortKey(new QCollatorSortKeyPrivate(QByteArray()));
0
151}-
152-
153int QCollatorSortKey::compare(const QCollatorSortKey &otherKey) const-
154{-
155 return qstrcmp(d->m_key, otherKey.d->m_key);
never executed: return qstrcmp(d->m_key, otherKey.d->m_key);
0
156}-
157-
158QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9