qlocale_icu.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qlocale_icu.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qglobal.h"-
35#include "qlibrary.h"-
36#include "qdebug.h"-
37#include "qlocale_p.h"-
38#include "qmutex.h"-
39-
40#include "unicode/uloc.h"-
41#include "unicode/ustring.h"-
42-
43QT_BEGIN_NAMESPACE-
44-
45typedef int32_t (*Ptr_u_strToCase)(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, const char *locale, UErrorCode *pErrorCode);-
46-
47// caseFunc can either be u_strToUpper or u_strToLower-
48static bool qt_u_strToCase(const QString &str, QString *out, const char *localeID, Ptr_u_strToCase caseFunc)-
49{-
50 Q_ASSERT(out);-
51-
52 int32_t size = str.size();-
53 size += size >> 2; // add 25% for possible expansions-
54 QString result(size, Qt::Uninitialized);-
55-
56 UErrorCode status = U_ZERO_ERROR;-
57-
58 size = caseFunc(reinterpret_cast<UChar *>(result.data()), result.size(),-
59 reinterpret_cast<const UChar *>(str.constData()), str.size(),-
60 localeID, &status);-
61-
62 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR)
U_FAILURE(status)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QString
status != U_BU...OVERFLOW_ERRORDescription
TRUEnever evaluated
FALSEnever evaluated
0-8
63 return false;
never executed: return false;
0
64-
65 if (size < result.size()) {
size < result.size()Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QString
0-8
66 result.resize(size);-
67 } else if (size > result.size()) {
never executed: end of block
size > result.size()Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QString
0-8
68 // the resulting string is larger than our source string-
69 result.resize(size);-
70-
71 status = U_ZERO_ERROR;-
72 size = caseFunc(reinterpret_cast<UChar *>(result.data()), result.size(),-
73 reinterpret_cast<const UChar *>(str.constData()), str.size(),-
74 localeID, &status);-
75-
76 if (U_FAILURE(status))
U_FAILURE(status)Description
TRUEnever evaluated
FALSEnever evaluated
0
77 return false;
never executed: return false;
0
78-
79 // if the sizes don't match now, we give up.-
80 if (size != result.size())
size != result.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
81 return false;
never executed: return false;
0
82 }
never executed: end of block
0
83-
84 *out = result;-
85 return true;
executed 8 times by 1 test: return true;
Executed by:
  • tst_QString
8
86}-
87-
88QString QIcu::toUpper(const QByteArray &localeID, const QString &str, bool *ok)-
89{-
90 QString out;-
91 bool err = qt_u_strToCase(str, &out, localeID, u_strToUpper);-
92 if (ok)
okDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QString
FALSEnever evaluated
0-3
93 *ok = err;
executed 3 times by 1 test: *ok = err;
Executed by:
  • tst_QString
3
94 return out;
executed 3 times by 1 test: return out;
Executed by:
  • tst_QString
3
95}-
96-
97QString QIcu::toLower(const QByteArray &localeID, const QString &str, bool *ok)-
98{-
99 QString out;-
100 bool err = qt_u_strToCase(str, &out, localeID, u_strToLower);-
101 if (ok)
okDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QString
FALSEnever evaluated
0-5
102 *ok = err;
executed 5 times by 1 test: *ok = err;
Executed by:
  • tst_QString
5
103 return out;
executed 5 times by 1 test: return out;
Executed by:
  • tst_QString
5
104}-
105-
106QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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