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) 2015 The Qt Company Ltd.-
4** Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org>-
5** Contact: http://www.qt.io/licensing/-
6**-
7** This file is part of the QtCore module of the Qt Toolkit.-
8**-
9** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
16** information use the contact form at http://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 2.1 or version 3 as published by the Free-
21** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
22** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
23** following information to ensure the GNU Lesser General Public License-
24** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
25** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
26**-
27** As a special exception, The Qt Company gives you certain additional-
28** rights. These rights are described in The Qt Company LGPL Exception-
29** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
30**-
31** $QT_END_LICENSE$-
32**-
33****************************************************************************/-
34-
35#include "qcollator_p.h"-
36#include "qstringlist.h"-
37#include "qstring.h"-
38-
39#include <unicode/utypes.h>-
40#include <unicode/ucol.h>-
41#include <unicode/ustring.h>-
42#include <unicode/ures.h>-
43-
44#include "qdebug.h"-
45-
46QT_BEGIN_NAMESPACE-
47-
48void QCollatorPrivate::init()-
49{-
50 cleanup();-
51-
52 UErrorCode status = U_ZERO_ERROR;-
53 QByteArray name = locale.bcp47Name().replace(QLatin1Char('-'), QLatin1Char('_')).toLatin1();-
54 collator = ucol_open(name.constData(), &status);-
55 if (U_FAILURE(status)) {
U_FAILURE(status)Description
TRUEnever evaluated
FALSEevaluated 332 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-332
56 qWarning("Could not create collator: %d", status);-
57 collator = 0;-
58 dirty = false;-
59 return;
never executed: return;
0
60 }-
61-
62 // enable normalization by default-
63 ucol_setAttribute(collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);-
64-
65 // The strength attribute in ICU is rather badly documented. Basically UCOL_PRIMARY-
66 // ignores differences between base characters and accented characters as well as case.-
67 // So A and A-umlaut would compare equal.-
68 // UCOL_SECONDARY ignores case differences. UCOL_TERTIARY is the default in most languages-
69 // and does case sensitive comparison.-
70 // UCOL_QUATERNARY is used as default in a few languages such as Japanese to take care of some-
71 // additional differences in those languages.-
72 UColAttributeValue val = (caseSensitivity == Qt::CaseSensitive) ? UCOL_DEFAULT_STRENGTH : UCOL_SECONDARY;
(caseSensitivi...CaseSensitive)Description
TRUEevaluated 196 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 136 times by 6 tests
Evaluated by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
136-196
73-
74 status = U_ZERO_ERROR;-
75 ucol_setAttribute(collator, UCOL_STRENGTH, val, &status);-
76 if (U_FAILURE(status))
U_FAILURE(status)Description
TRUEnever evaluated
FALSEevaluated 332 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-332
77 qWarning("ucol_setAttribute: Case First failed: %d", status);
never executed: QMessageLogger(__FILE__, 77, __PRETTY_FUNCTION__).warning("ucol_setAttribute: Case First failed: %d", status);
0
78-
79 status = U_ZERO_ERROR;-
80 ucol_setAttribute(collator, UCOL_NUMERIC_COLLATION, numericMode ? UCOL_ON : UCOL_OFF, &status);-
81 if (U_FAILURE(status))
U_FAILURE(status)Description
TRUEnever evaluated
FALSEevaluated 332 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-332
82 qWarning("ucol_setAttribute: numeric collation failed: %d", status);
never executed: QMessageLogger(__FILE__, 82, __PRETTY_FUNCTION__).warning("ucol_setAttribute: numeric collation failed: %d", status);
0
83-
84 status = U_ZERO_ERROR;-
85 ucol_setAttribute(collator, UCOL_ALTERNATE_HANDLING, ignorePunctuation ? UCOL_SHIFTED : UCOL_NON_IGNORABLE, &status);-
86 if (U_FAILURE(status))
U_FAILURE(status)Description
TRUEnever evaluated
FALSEevaluated 332 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-332
87 qWarning("ucol_setAttribute: Alternate handling failed: %d", status);
never executed: QMessageLogger(__FILE__, 87, __PRETTY_FUNCTION__).warning("ucol_setAttribute: Alternate handling failed: %d", status);
0
88-
89 dirty = false;-
90}
executed 332 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
332
91-
92void QCollatorPrivate::cleanup()-
93{-
94 if (collator)
collatorDescription
TRUEevaluated 332 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 382 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
332-382
95 ucol_close(collator);
executed 332 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
332
96 collator = 0;-
97}
executed 714 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
714
98-
99int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const-
100{-
101 if (d->dirty)
d->dirtyDescription
TRUEevaluated 141 times by 6 tests
Evaluated by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
FALSEevaluated 18739 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
141-18739
102 d->init();
executed 141 times by 6 tests: d->init();
Executed by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
141
103-
104 if (d->collator)
d->collatorDescription
TRUEevaluated 18880 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-18880
105 return ucol_strcoll(d->collator, (const UChar *)s1, len1, (const UChar *)s2, len2);
executed 18880 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
18880
106-
107 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
108}-
109-
110int QCollator::compare(const QString &s1, const QString &s2) const-
111{-
112 if (d->collator)
d->collatorDescription
TRUEevaluated 7485 times by 6 tests
Evaluated by:
  • tst_QCollator
  • tst_QCompleter
  • tst_QFileDialog2
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QPrinter
FALSEnever evaluated
0-7485
113 return compare(s1.constData(), s1.size(), s2.constData(), s2.size());
executed 7485 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
7485
114-
115 return QString::compare(s1, s2, d->caseSensitivity);
never executed: return QString::compare(s1, s2, d->caseSensitivity);
0
116}-
117-
118int QCollator::compare(const QStringRef &s1, const QStringRef &s2) const-
119{-
120 if (d->collator)
d->collatorDescription
TRUEnever evaluated
FALSEnever evaluated
0
121 return compare(s1.constData(), s1.size(), s2.constData(), s2.size());
never executed: return compare(s1.constData(), s1.size(), s2.constData(), s2.size());
0
122-
123 return QStringRef::compare(s1, s2, d->caseSensitivity);
never executed: return QStringRef::compare(s1, s2, d->caseSensitivity);
0
124}-
125-
126QCollatorSortKey QCollator::sortKey(const QString &string) const-
127{-
128 if (d->dirty)
d->dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
129 d->init();
never executed: d->init();
0
130-
131 if (d->collator) {
d->collatorDescription
TRUEnever evaluated
FALSEnever evaluated
0
132 QByteArray result(16 + string.size() + (string.size() >> 2), Qt::Uninitialized);-
133 int size = ucol_getSortKey(d->collator, (const UChar *)string.constData(),-
134 string.size(), (uint8_t *)result.data(), result.size());-
135 if (size > result.size()) {
size > result.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
136 result.resize(size);-
137 size = ucol_getSortKey(d->collator, (const UChar *)string.constData(),-
138 string.size(), (uint8_t *)result.data(), result.size());-
139 }
never executed: end of block
0
140 result.truncate(size);-
141 return QCollatorSortKey(new QCollatorSortKeyPrivate(result));
never executed: return QCollatorSortKey(new QCollatorSortKeyPrivate(result));
0
142 }-
143-
144 return QCollatorSortKey(new QCollatorSortKeyPrivate(QByteArray()));
never executed: return QCollatorSortKey(new QCollatorSortKeyPrivate(QByteArray()));
0
145}-
146-
147int QCollatorSortKey::compare(const QCollatorSortKey &otherKey) const-
148{-
149 return qstrcmp(d->m_key, otherKey.d->m_key);
never executed: return qstrcmp(d->m_key, otherKey.d->m_key);
0
150}-
151-
152QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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