| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qlocale_icu.cpp | 
| Source code | Switch to Preprocessed file | 
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 | - | |||||||||||||
| 43 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | typedef 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 | - | ||||||||||||
| 48 | static 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)
 
  | 0-8 | ||||||||||||
| 63 |         return false; never executed:  return false; | 0 | ||||||||||||
| 64 | - | |||||||||||||
| 65 |     if (size < result.size()) {
  | 0-8 | ||||||||||||
| 66 | result.resize(size); | - | ||||||||||||
| 67 |     } else if (size > result.size()) { never executed:  end of block
  | 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))
  | 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())
  | 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: 
  | 8 | ||||||||||||
| 86 | } | - | ||||||||||||
| 87 | - | |||||||||||||
| 88 | QString 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)
  | 0-3 | ||||||||||||
| 93 |         *ok = err; executed 3 times by 1 test:  *ok = err;Executed by: 
  | 3 | ||||||||||||
| 94 |     return out; executed 3 times by 1 test:  return out;Executed by: 
  | 3 | ||||||||||||
| 95 | } | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | QString 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)
  | 0-5 | ||||||||||||
| 102 |         *ok = err; executed 5 times by 1 test:  *ok = err;Executed by: 
  | 5 | ||||||||||||
| 103 |     return out; executed 5 times by 1 test:  return out;Executed by: 
  | 5 | ||||||||||||
| 104 | } | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |