tools/qlocale_icu.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qglobal.h" -
43#include "qlibrary.h" -
44#include "qdebug.h" -
45#include "qlocale_p.h" -
46#include "qmutex.h" -
47 -
48#include "unicode/uloc.h" -
49#include "unicode/ustring.h" -
50 -
51QT_BEGIN_NAMESPACE -
52 -
53typedef int32_t (*Ptr_u_strToCase)(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, const char *locale, UErrorCode *pErrorCode); -
54 -
55// caseFunc can either be u_strToUpper or u_strToLower -
56static bool qt_u_strToCase(const QString &str, QString *out, const char *localeID, Ptr_u_strToCase caseFunc) -
57{ -
58 Q_ASSERT(out);
executed (the execution status of this line is deduced): qt_noop();
-
59 -
60 int32_t size = str.size();
executed (the execution status of this line is deduced): int32_t size = str.size();
-
61 size += size >> 2; // add 25% for possible expansions
executed (the execution status of this line is deduced): size += size >> 2;
-
62 QString result(size, Qt::Uninitialized);
executed (the execution status of this line is deduced): QString result(size, Qt::Uninitialized);
-
63 -
64 UErrorCode status = U_ZERO_ERROR;
executed (the execution status of this line is deduced): UErrorCode status = U_ZERO_ERROR;
-
65 -
66 size = caseFunc(reinterpret_cast<UChar *>(result.data()), result.size(),
executed (the execution status of this line is deduced): size = caseFunc(reinterpret_cast<UChar *>(result.data()), result.size(),
-
67 reinterpret_cast<const UChar *>(str.constData()), str.size(),
executed (the execution status of this line is deduced): reinterpret_cast<const UChar *>(str.constData()), str.size(),
-
68 localeID, &status);
executed (the execution status of this line is deduced): localeID, &status);
-
69 -
70 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR)
partially evaluated: U_FAILURE(status)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
never evaluated: status != U_BUFFER_OVERFLOW_ERROR
0-8
71 return false;
never executed: return false;
0
72 -
73 if (size < result.size()) {
partially evaluated: size < result.size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
74 result.resize(size);
never executed (the execution status of this line is deduced): result.resize(size);
-
75 } else if (size > result.size()) {
never executed: }
partially evaluated: size > result.size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
76 // the resulting string is larger than our source string -
77 result.resize(size);
never executed (the execution status of this line is deduced): result.resize(size);
-
78 -
79 status = U_ZERO_ERROR;
never executed (the execution status of this line is deduced): status = U_ZERO_ERROR;
-
80 size = caseFunc(reinterpret_cast<UChar *>(result.data()), result.size(),
never executed (the execution status of this line is deduced): size = caseFunc(reinterpret_cast<UChar *>(result.data()), result.size(),
-
81 reinterpret_cast<const UChar *>(str.constData()), str.size(),
never executed (the execution status of this line is deduced): reinterpret_cast<const UChar *>(str.constData()), str.size(),
-
82 localeID, &status);
never executed (the execution status of this line is deduced): localeID, &status);
-
83 -
84 if (U_FAILURE(status))
never evaluated: U_FAILURE(status)
0
85 return false;
never executed: return false;
0
86 -
87 // if the sizes don't match now, we give up. -
88 if (size != result.size())
never evaluated: size != result.size()
0
89 return false;
never executed: return false;
0
90 }
never executed: }
0
91 -
92 *out = result;
executed (the execution status of this line is deduced): *out = result;
-
93 return true;
executed: return true;
Execution Count:8
8
94} -
95 -
96QString QIcu::toUpper(const QByteArray &localeID, const QString &str, bool *ok) -
97{ -
98 QString out;
executed (the execution status of this line is deduced): QString out;
-
99 bool err = qt_u_strToCase(str, &out, localeID, u_strToUpper);
executed (the execution status of this line is deduced): bool err = qt_u_strToCase(str, &out, localeID, u_strToUpper_44);
-
100 if (ok)
partially evaluated: ok
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
101 *ok = err;
executed: *ok = err;
Execution Count:3
3
102 return out;
executed: return out;
Execution Count:3
3
103} -
104 -
105QString QIcu::toLower(const QByteArray &localeID, const QString &str, bool *ok) -
106{ -
107 QString out;
executed (the execution status of this line is deduced): QString out;
-
108 bool err = qt_u_strToCase(str, &out, localeID, u_strToLower);
executed (the execution status of this line is deduced): bool err = qt_u_strToCase(str, &out, localeID, u_strToLower_44);
-
109 if (ok)
partially evaluated: ok
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-5
110 *ok = err;
executed: *ok = err;
Execution Count:5
5
111 return out;
executed: return out;
Execution Count:5
5
112} -
113 -
114QT_END_NAMESPACE -
115 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial