| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qlocale_unix.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | struct QSystemLocaleData | - | ||||||||||||||||||
| 7 | { | - | ||||||||||||||||||
| 8 | QSystemLocaleData() | - | ||||||||||||||||||
| 9 | : lc_numeric(QLocale::C) | - | ||||||||||||||||||
| 10 | ,lc_time(QLocale::C) | - | ||||||||||||||||||
| 11 | ,lc_monetary(QLocale::C) | - | ||||||||||||||||||
| 12 | ,lc_messages(QLocale::C) | - | ||||||||||||||||||
| 13 | { | - | ||||||||||||||||||
| 14 | readEnvironment(); | - | ||||||||||||||||||
| 15 | } | - | ||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | void readEnvironment(); | - | ||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | QReadWriteLock lock; | - | ||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | QLocale lc_numeric; | - | ||||||||||||||||||
| 22 | QLocale lc_time; | - | ||||||||||||||||||
| 23 | QLocale lc_monetary; | - | ||||||||||||||||||
| 24 | QLocale lc_messages; | - | ||||||||||||||||||
| 25 | QByteArray lc_messages_var; | - | ||||||||||||||||||
| 26 | QByteArray lc_measurement_var; | - | ||||||||||||||||||
| 27 | QStringList uiLanguages; | - | ||||||||||||||||||
| 28 | }; | - | ||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | void QSystemLocaleData::readEnvironment() | - | ||||||||||||||||||
| 31 | { | - | ||||||||||||||||||
| 32 | QWriteLocker locker(&lock); | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | QByteArray all = qgetenv("LC_ALL"); | - | ||||||||||||||||||
| 35 | QByteArray numeric = all.isEmpty() ? qgetenv("LC_NUMERIC") : all; | - | ||||||||||||||||||
| 36 | QByteArray time = all.isEmpty() ? qgetenv("LC_TIME") : all; | - | ||||||||||||||||||
| 37 | QByteArray monetary = all.isEmpty() ? qgetenv("LC_MONETARY") : all; | - | ||||||||||||||||||
| 38 | lc_messages_var = all.isEmpty() ? qgetenv("LC_MESSAGES") : all; | - | ||||||||||||||||||
| 39 | lc_measurement_var = all.isEmpty() ? qgetenv("LC_MEASUREMENT") : all; | - | ||||||||||||||||||
| 40 | QByteArray lang = qgetenv("LANG"); | - | ||||||||||||||||||
| 41 | if (lang.isEmpty()) | - | ||||||||||||||||||
| 42 | lang = QByteArray("C"); | - | ||||||||||||||||||
| 43 | if (numeric.isEmpty()) | - | ||||||||||||||||||
| 44 | numeric = lang; | - | ||||||||||||||||||
| 45 | if (time.isEmpty()) | - | ||||||||||||||||||
| 46 | time = lang; | - | ||||||||||||||||||
| 47 | if (monetary.isEmpty()) | - | ||||||||||||||||||
| 48 | monetary = lang; | - | ||||||||||||||||||
| 49 | if (lc_messages_var.isEmpty()) | - | ||||||||||||||||||
| 50 | lc_messages_var = lang; | - | ||||||||||||||||||
| 51 | if (lc_measurement_var.isEmpty()) | - | ||||||||||||||||||
| 52 | lc_measurement_var = lang; | - | ||||||||||||||||||
| 53 | lc_numeric = QLocale(QString::fromLatin1(numeric)); | - | ||||||||||||||||||
| 54 | lc_time = QLocale(QString::fromLatin1(time)); | - | ||||||||||||||||||
| 55 | lc_monetary = QLocale(QString::fromLatin1(monetary)); | - | ||||||||||||||||||
| 56 | lc_messages = QLocale(QString::fromLatin1(lc_messages_var)); | - | ||||||||||||||||||
| 57 | } | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | namespace { namespace Q_QGS_qSystemLocaleData { typedef QSystemLocaleData Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QSystemLocaleData, Q_QGS_qSystemLocaleData::innerFunction, Q_QGS_qSystemLocaleData::guard> qSystemLocaleData; | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | - | |||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | QLocale QSystemLocale::fallbackUiLocale() const | - | ||||||||||||||||||
| 66 | { | - | ||||||||||||||||||
| 67 | QByteArray lang = qgetenv("LC_ALL"); | - | ||||||||||||||||||
| 68 | if (lang.isEmpty()
| 0-1015 | ||||||||||||||||||
| 69 | lang = qgetenv("LC_MESSAGES"); executed 1015 times by 12 tests: lang = qgetenv("LC_MESSAGES");Executed by:
| 1015 | ||||||||||||||||||
| 70 | if (lang.isEmpty()
| 0-1015 | ||||||||||||||||||
| 71 | lang = qgetenv("LANG"); executed 1015 times by 12 tests: lang = qgetenv("LANG");Executed by:
| 1015 | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | if (lang.isEmpty()
| 0-789 | ||||||||||||||||||
| 74 | return executed 789 times by 1 test: QLocale(QString::fromLatin1(lang));return QLocale(QString::fromLatin1(lang));Executed by:
executed 789 times by 1 test: return QLocale(QString::fromLatin1(lang));Executed by:
| 789 | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | - | |||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | QByteArray language = qgetenv("LANGUAGE"); | - | ||||||||||||||||||
| 79 | if (!language.isEmpty()
| 0-226 | ||||||||||||||||||
| 80 | language = language.split(':').firstconstFirst(); | - | ||||||||||||||||||
| 81 | if (!language.isEmpty()
| 0-226 | ||||||||||||||||||
| 82 | return executed 226 times by 11 tests: QLocale(QString::fromLatin1(language));return QLocale(QString::fromLatin1(language));Executed by:
executed 226 times by 11 tests: return QLocale(QString::fromLatin1(language));Executed by:
| 226 | ||||||||||||||||||
| 83 | } never executed: end of block | 0 | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | return never executed: QLocale(QString::fromLatin1(lang));return QLocale(QString::fromLatin1(lang));never executed: return QLocale(QString::fromLatin1(lang)); | 0 | ||||||||||||||||||
| 86 | } | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | QVariant QSystemLocale::query(QueryType type, QVariant in) const | - | ||||||||||||||||||
| 89 | { | - | ||||||||||||||||||
| 90 | QSystemLocaleData *d = qSystemLocaleData(); | - | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | if (type == LocaleChanged) { | - | ||||||||||||||||||
| 93 | d->readEnvironment(); | - | ||||||||||||||||||
| 94 | return QVariant(); | - | ||||||||||||||||||
| 95 | } | - | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | QReadLocker locker(&d->lock); | - | ||||||||||||||||||
| 98 | - | |||||||||||||||||||
| 99 | const QLocale &lc_numeric = d->lc_numeric; | - | ||||||||||||||||||
| 100 | const QLocale &lc_time = d->lc_time; | - | ||||||||||||||||||
| 101 | const QLocale &lc_monetary = d->lc_monetary; | - | ||||||||||||||||||
| 102 | const QLocale &lc_messages = d->lc_messages; | - | ||||||||||||||||||
| 103 | - | |||||||||||||||||||
| 104 | switch (type) { | - | ||||||||||||||||||
| 105 | case DecimalPoint: | - | ||||||||||||||||||
| 106 | return lc_numeric.decimalPoint(); | - | ||||||||||||||||||
| 107 | case GroupSeparator: | - | ||||||||||||||||||
| 108 | return lc_numeric.groupSeparator(); | - | ||||||||||||||||||
| 109 | case ZeroDigit: | - | ||||||||||||||||||
| 110 | return lc_numeric.zeroDigit(); | - | ||||||||||||||||||
| 111 | case NegativeSign: | - | ||||||||||||||||||
| 112 | return lc_numeric.negativeSign(); | - | ||||||||||||||||||
| 113 | case DateFormatLong: | - | ||||||||||||||||||
| 114 | return lc_time.dateFormat(QLocale::LongFormat); | - | ||||||||||||||||||
| 115 | case DateFormatShort: | - | ||||||||||||||||||
| 116 | return lc_time.dateFormat(QLocale::ShortFormat); | - | ||||||||||||||||||
| 117 | case TimeFormatLong: | - | ||||||||||||||||||
| 118 | return lc_time.timeFormat(QLocale::LongFormat); | - | ||||||||||||||||||
| 119 | case TimeFormatShort: | - | ||||||||||||||||||
| 120 | return lc_time.timeFormat(QLocale::ShortFormat); | - | ||||||||||||||||||
| 121 | case DayNameLong: | - | ||||||||||||||||||
| 122 | return lc_time.dayName(in.toInt(), QLocale::LongFormat); | - | ||||||||||||||||||
| 123 | case DayNameShort: | - | ||||||||||||||||||
| 124 | return lc_time.dayName(in.toInt(), QLocale::ShortFormat); | - | ||||||||||||||||||
| 125 | case MonthNameLong: | - | ||||||||||||||||||
| 126 | return lc_time.monthName(in.toInt(), QLocale::LongFormat); | - | ||||||||||||||||||
| 127 | case MonthNameShort: | - | ||||||||||||||||||
| 128 | return lc_time.monthName(in.toInt(), QLocale::ShortFormat); | - | ||||||||||||||||||
| 129 | case StandaloneMonthNameLong: | - | ||||||||||||||||||
| 130 | return lc_time.standaloneMonthName(in.toInt(), QLocale::LongFormat); | - | ||||||||||||||||||
| 131 | case StandaloneMonthNameShort: | - | ||||||||||||||||||
| 132 | return lc_time.standaloneMonthName(in.toInt(), QLocale::ShortFormat); | - | ||||||||||||||||||
| 133 | case DateToStringLong: | - | ||||||||||||||||||
| 134 | return lc_time.toString(in.toDate(), QLocale::LongFormat); | - | ||||||||||||||||||
| 135 | case DateToStringShort: | - | ||||||||||||||||||
| 136 | return lc_time.toString(in.toDate(), QLocale::ShortFormat); | - | ||||||||||||||||||
| 137 | case TimeToStringLong: | - | ||||||||||||||||||
| 138 | return lc_time.toString(in.toTime(), QLocale::LongFormat); | - | ||||||||||||||||||
| 139 | case TimeToStringShort: | - | ||||||||||||||||||
| 140 | return lc_time.toString(in.toTime(), QLocale::ShortFormat); | - | ||||||||||||||||||
| 141 | case DateTimeFormatLong: | - | ||||||||||||||||||
| 142 | return lc_time.dateTimeFormat(QLocale::LongFormat); | - | ||||||||||||||||||
| 143 | case DateTimeFormatShort: | - | ||||||||||||||||||
| 144 | return lc_time.dateTimeFormat(QLocale::ShortFormat); | - | ||||||||||||||||||
| 145 | case DateTimeToStringLong: | - | ||||||||||||||||||
| 146 | return lc_time.toString(in.toDateTime(), QLocale::LongFormat); | - | ||||||||||||||||||
| 147 | case DateTimeToStringShort: | - | ||||||||||||||||||
| 148 | return lc_time.toString(in.toDateTime(), QLocale::ShortFormat); | - | ||||||||||||||||||
| 149 | case PositiveSign: | - | ||||||||||||||||||
| 150 | return lc_numeric.positiveSign(); | - | ||||||||||||||||||
| 151 | case AMText: | - | ||||||||||||||||||
| 152 | return lc_time.amText(); | - | ||||||||||||||||||
| 153 | case PMText: | - | ||||||||||||||||||
| 154 | return lc_time.pmText(); | - | ||||||||||||||||||
| 155 | case FirstDayOfWeek: | - | ||||||||||||||||||
| 156 | return lc_time.firstDayOfWeek(); | - | ||||||||||||||||||
| 157 | case CurrencySymbol: | - | ||||||||||||||||||
| 158 | return lc_monetary.currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt())); | - | ||||||||||||||||||
| 159 | case CurrencyToString: { | - | ||||||||||||||||||
| 160 | switch (in.type()) { | - | ||||||||||||||||||
| 161 | case QVariant::Int: | - | ||||||||||||||||||
| 162 | return lc_monetary.toCurrencyString(in.toInt()); | - | ||||||||||||||||||
| 163 | case QVariant::UInt: | - | ||||||||||||||||||
| 164 | return lc_monetary.toCurrencyString(in.toUInt()); | - | ||||||||||||||||||
| 165 | case QVariant::Double: | - | ||||||||||||||||||
| 166 | return lc_monetary.toCurrencyString(in.toDouble()); | - | ||||||||||||||||||
| 167 | case QVariant::LongLong: | - | ||||||||||||||||||
| 168 | return lc_monetary.toCurrencyString(in.toLongLong()); | - | ||||||||||||||||||
| 169 | case QVariant::ULongLong: | - | ||||||||||||||||||
| 170 | return lc_monetary.toCurrencyString(in.toULongLong()); | - | ||||||||||||||||||
| 171 | default: | - | ||||||||||||||||||
| 172 | break; | - | ||||||||||||||||||
| 173 | } | - | ||||||||||||||||||
| 174 | return QString(); | - | ||||||||||||||||||
| 175 | } | - | ||||||||||||||||||
| 176 | case MeasurementSystem: { | - | ||||||||||||||||||
| 177 | const QString meas_locale = QString::fromLatin1(d->lc_measurement_var.constData(), d->lc_measurement_var.size()); | - | ||||||||||||||||||
| 178 | if (meas_locale.compare(QLatin1String("Metric"), Qt::CaseInsensitive) == 0) | - | ||||||||||||||||||
| 179 | return QLocale::MetricSystem; | - | ||||||||||||||||||
| 180 | if (meas_locale.compare(QLatin1String("Other"), Qt::CaseInsensitive) == 0) | - | ||||||||||||||||||
| 181 | return QLocale::MetricSystem; | - | ||||||||||||||||||
| 182 | return QVariant((int)QLocale(meas_locale).measurementSystem()); | - | ||||||||||||||||||
| 183 | } | - | ||||||||||||||||||
| 184 | case UILanguages: { | - | ||||||||||||||||||
| 185 | if (!d->uiLanguages.isEmpty()) | - | ||||||||||||||||||
| 186 | return d->uiLanguages; | - | ||||||||||||||||||
| 187 | QString languages = QString::fromLatin1(qgetenv("LANGUAGE")); | - | ||||||||||||||||||
| 188 | QStringList lst; | - | ||||||||||||||||||
| 189 | if (languages.isEmpty()) | - | ||||||||||||||||||
| 190 | lst.append(QString::fromLatin1(d->lc_messages_var)); | - | ||||||||||||||||||
| 191 | else | - | ||||||||||||||||||
| 192 | lst = languages.split(QLatin1Char(':')); | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | for (int i = 0; i < lst.size(); ++i) { | - | ||||||||||||||||||
| 195 | const QString &name = lst.at(i); | - | ||||||||||||||||||
| 196 | QString lang, script, cntry; | - | ||||||||||||||||||
| 197 | if (qt_splitLocaleName(name, lang, script, cntry)) { | - | ||||||||||||||||||
| 198 | if (!cntry.length()) | - | ||||||||||||||||||
| 199 | d->uiLanguages.append(lang); | - | ||||||||||||||||||
| 200 | else | - | ||||||||||||||||||
| 201 | d->uiLanguages.append(lang % QLatin1Char('-') % cntry); | - | ||||||||||||||||||
| 202 | } | - | ||||||||||||||||||
| 203 | } | - | ||||||||||||||||||
| 204 | return d->uiLanguages.isEmpty() ? QVariant() : QVariant(d->uiLanguages); | - | ||||||||||||||||||
| 205 | } | - | ||||||||||||||||||
| 206 | case StringToStandardQuotation: | - | ||||||||||||||||||
| 207 | return lc_messages.quoteString(in.value<QStringRef>()); | - | ||||||||||||||||||
| 208 | case StringToAlternateQuotation: | - | ||||||||||||||||||
| 209 | return lc_messages.quoteString(in.value<QStringRef>(), QLocale::AlternateQuotation); | - | ||||||||||||||||||
| 210 | case ListToSeparatedString: | - | ||||||||||||||||||
| 211 | return lc_messages.createSeparatedList(in.toStringList()); | - | ||||||||||||||||||
| 212 | case LocaleChanged: | - | ||||||||||||||||||
| 213 | ((!(false)) ? qt_assert("false",__FILE__,252258) : qt_noop()); | - | ||||||||||||||||||
| 214 | default: | - | ||||||||||||||||||
| 215 | break; | - | ||||||||||||||||||
| 216 | } | - | ||||||||||||||||||
| 217 | return QVariant(); | - | ||||||||||||||||||
| 218 | } | - | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | - | |||||||||||||||||||
| 221 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |