~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/corelib/tools/qlocale.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
2
**
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
5
6
**
6
7
** This file is part of the QtCore module of the Qt Toolkit.
7
8
**
8
9
** $QT_BEGIN_LICENSE:LGPL$
9
 
** Commercial Usage
10
 
** Licensees holding valid Qt Commercial licenses may use this file in
11
 
** accordance with the Qt Commercial License Agreement provided with the
12
 
** Software or, alternatively, in accordance with the terms contained in
13
 
** a written agreement between you and Nokia.
 
10
** No Commercial Usage
 
11
** This file contains pre-release code and may not be distributed.
 
12
** You may use this file in accordance with the terms and conditions
 
13
** contained in the Technology Preview License Agreement accompanying
 
14
** this package.
14
15
**
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22
23
**
23
 
** In addition, as a special exception, Nokia gives you certain
24
 
** additional rights. These rights are described in the Nokia Qt LGPL
25
 
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26
 
** package.
27
 
**
28
 
** GNU General Public License Usage
29
 
** Alternatively, this file may be used under the terms of the GNU
30
 
** General Public License version 3.0 as published by the Free Software
31
 
** Foundation and appearing in the file LICENSE.GPL included in the
32
 
** packaging of this file.  Please review the following information to
33
 
** ensure the GNU General Public License version 3.0 requirements will be
34
 
** met: http://www.gnu.org/copyleft/gpl.html.
35
 
**
36
 
** If you are unsure which license is appropriate for your use, please
37
 
** contact the sales department at http://www.qtsoftware.com/contact.
 
24
** In addition, as a special exception, Nokia gives you certain additional
 
25
** rights.  These rights are described in the Nokia Qt LGPL Exception
 
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
27
**
 
28
** If you have questions regarding the use of this file, please contact
 
29
** Nokia at qt-info@nokia.com.
 
30
**
 
31
**
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
38
38
** $QT_END_LICENSE$
39
39
**
40
40
****************************************************************************/
42
42
#include "qglobal.h"
43
43
 
44
44
#ifndef QT_NO_SYSTEMLOCALE
45
 
#define QLOCALE_CPP
46
45
QT_BEGIN_NAMESPACE
47
46
class QSystemLocale;
48
47
static QSystemLocale *QSystemLocale_globalSystemLocale();
120
119
Q_CORE_EXPORT char *qdtoa(double d, int mode, int ndigits, int *decpt,
121
120
                        int *sign, char **rve, char **digits_str);
122
121
Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok);
123
 
Q_CORE_EXPORT qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok);
 
122
static qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok);
124
123
static qulonglong qstrtoull(const char *nptr, const char **endptr, register int base, bool *ok);
125
124
 
 
125
#if defined(Q_CC_MWERKS) && defined(Q_OS_WIN32)
 
126
inline bool isascii(int c)
 
127
{
 
128
        return (c >= 0 && c <=127);
 
129
}
 
130
#endif
 
131
 
126
132
/******************************************************************************
127
133
** Helpers for accessing Qt locale database
128
134
*/
186
192
 
187
193
    const unsigned char *c = language_code_list + 3*(uint(language));
188
194
 
189
 
    QString code;
190
 
    code.resize(c[2] == 0 ? 2 : 3);
 
195
    QString code(c[2] == 0 ? 2 : 3, Qt::Uninitialized);
191
196
 
192
197
    code[0] = ushort(c[0]);
193
198
    code[1] = ushort(c[1]);
202
207
    if (country == QLocale::AnyCountry)
203
208
        return QString();
204
209
 
205
 
    QString code;
206
 
    code.resize(2);
 
210
    QString code(2, Qt::Uninitialized);
207
211
    const unsigned char *c = country_code_list + 2*(uint(country));
208
212
    code[0] = ushort(c[0]);
209
213
    code[1] = ushort(c[1]);
291
295
    return lang_len == 2 || lang_len == 3;
292
296
}
293
297
 
294
 
static void getLangAndCountry(const QString &name, QLocale::Language &lang, QLocale::Country &cntry)
 
298
void getLangAndCountry(const QString &name, QLocale::Language &lang, QLocale::Country &cntry)
295
299
{
296
300
    lang = QLocale::C;
297
301
    cntry = QLocale::AnyCountry;
321
325
{
322
326
    int &i = *idx;
323
327
 
324
 
    Q_ASSERT(format.at(i).unicode() == '\'');
 
328
    Q_ASSERT(format.at(i) == QLatin1Char('\''));
325
329
    ++i;
326
330
    if (i == format.size())
327
331
        return QString();
389
393
 
390
394
static QString getWinLocaleInfo(LCTYPE type)
391
395
{
392
 
    int cnt = 0;
393
 
 
394
396
    LCID id = GetUserDefaultLCID();
395
 
 
396
 
    QT_WA({
397
 
        cnt = GetLocaleInfoW(id, type, 0, 0)*2;
398
 
    } , {
399
 
        cnt = GetLocaleInfoA(id, type, 0, 0);
400
 
    });
 
397
    int cnt = GetLocaleInfo(id, type, 0, 0) * 2;
401
398
 
402
399
    if (cnt == 0) {
403
400
        qWarning("QLocale: empty windows locale info (%d)", (int)type);
406
403
 
407
404
    QByteArray buff(cnt, 0);
408
405
 
409
 
    QT_WA({
410
 
        cnt = GetLocaleInfoW(id, type,
411
 
                                reinterpret_cast<wchar_t*>(buff.data()),
412
 
                                buff.size()/2);
413
 
    } , {
414
 
        cnt = GetLocaleInfoA(id, type,
415
 
                                buff.data(), buff.size());
416
 
    });
 
406
    cnt = GetLocaleInfo(id, type, reinterpret_cast<wchar_t*>(buff.data()), buff.size() / 2);
417
407
 
418
408
    if (cnt == 0) {
419
409
        qWarning("QLocale: empty windows locale info (%d)", (int)type);
420
410
        return QString();
421
411
    }
422
412
 
423
 
    QString result;
424
 
    QT_WA({
425
 
        result = QString::fromUtf16(reinterpret_cast<ushort*>(buff.data()));
426
 
    } , {
427
 
        result = QString::fromLocal8Bit(buff.data());
428
 
    });
429
 
    return result;
 
413
    return QString::fromWCharArray(reinterpret_cast<const wchar_t *>(buff.data()));
430
414
}
431
415
 
432
416
QByteArray getWinLocaleName(LCID id = LOCALE_USER_DEFAULT)
436
420
        result = envVarLocale();
437
421
        QChar lang[3];
438
422
        QChar cntry[2];
439
 
        if ( result == "C" || !result.isEmpty()
440
 
                && splitLocaleName(QString::fromLocal8Bit(result), lang, cntry) ) {
 
423
        if ( result == "C" || (!result.isEmpty()
 
424
                && splitLocaleName(QString::fromLocal8Bit(result), lang, cntry)) ) {
441
425
            long id = 0;
442
426
            bool ok = false;
443
427
            id = qstrtoll(result.data(), 0, 0, &ok);
448
432
        }
449
433
    }
450
434
 
451
 
    if (QSysInfo::WindowsVersion == QSysInfo::WV_95
452
 
        || (QSysInfo::WindowsVersion & QSysInfo::WV_CE_based)) {
453
 
        result = winLangCodeToIsoName(id != LOCALE_USER_DEFAULT ? id : GetUserDefaultLCID());
454
 
    } else {
455
 
        if (id == LOCALE_USER_DEFAULT)
456
 
            id = GetUserDefaultLCID();
457
 
        QString resultuage = winIso639LangName(id);
458
 
        QString country = winIso3116CtryName(id);
459
 
        result = resultuage.toLatin1();
460
 
        if (!country.isEmpty()) {
461
 
            result += '_';
462
 
            result += country.toLatin1();
463
 
        }
 
435
#if defined(Q_OS_WINCE)
 
436
    result = winLangCodeToIsoName(id != LOCALE_USER_DEFAULT ? id : GetUserDefaultLCID());
 
437
#else
 
438
    if (id == LOCALE_USER_DEFAULT)
 
439
        id = GetUserDefaultLCID();
 
440
    QString resultuage = winIso639LangName(id);
 
441
    QString country = winIso3116CtryName(id);
 
442
    result = resultuage.toLatin1();
 
443
    if (!country.isEmpty()) {
 
444
        result += '_';
 
445
        result += country.toLatin1();
464
446
    }
 
447
#endif
465
448
 
466
449
    return result;
467
450
}
547
530
 
548
531
    LCID id = GetUserDefaultLCID();
549
532
 
550
 
    QT_WA({
551
 
        TCHAR buf[255];
552
 
        if (GetDateFormatW(id, flags, &st, 0, buf, 255))
553
 
            return QString::fromUtf16((ushort*)buf);
554
 
    } , {
555
 
        char buf[255];
556
 
        if (GetDateFormatA(id, flags, &st, 0, (char*)&buf, 255))
557
 
            return QString::fromLocal8Bit(buf);
558
 
    });
 
533
    wchar_t buf[255];
 
534
    if (GetDateFormat(id, flags, &st, 0, buf, 255))
 
535
        return QString::fromWCharArray(buf);
559
536
 
560
537
    return QString();
561
538
}
572
549
    DWORD flags = 0;
573
550
    LCID id = GetUserDefaultLCID();
574
551
 
575
 
    QT_WA({
576
 
        TCHAR buf[255];
577
 
        if (GetTimeFormatW(id, flags, &st, 0, buf, 255))
578
 
            return QString::fromUtf16((ushort*)buf);
579
 
    } , {
580
 
        char buf[255];
581
 
        if (GetTimeFormatA(id, flags, &st, 0, (char*)&buf, 255))
582
 
            return QString::fromLocal8Bit(buf);
583
 
    });
 
552
    wchar_t buf[255];
 
553
    if (GetTimeFormat(id, flags, &st, 0, buf, 255))
 
554
        return QString::fromWCharArray(buf);
584
555
 
585
556
    return QString();
586
557
}
629
600
static QLocale::MeasurementSystem winSystemMeasurementSystem()
630
601
{
631
602
    LCID id = GetUserDefaultLCID();
632
 
    TCHAR output[2];
 
603
    wchar_t output[2];
633
604
 
634
605
    if (GetLocaleInfo(id, LOCALE_IMEASURE, output, 2)) {
635
 
        QString iMeasure = QT_WA_INLINE(
636
 
                QString::fromUtf16(reinterpret_cast<ushort*>(output)),
637
 
                QString::fromLocal8Bit(reinterpret_cast<char*>(output)));
638
 
        if (iMeasure == QString::fromLatin1("1")) {
 
606
        QString iMeasure = QString::fromWCharArray(output);
 
607
        if (iMeasure == QLatin1String("1")) {
639
608
            return QLocale::ImperialSystem;
640
609
        }
641
610
    }
646
615
static QString winSystemAMText()
647
616
{
648
617
    LCID id = GetUserDefaultLCID();
649
 
    TCHAR output[15]; // maximum length including  terminating zero character for Win2003+
 
618
    wchar_t output[15]; // maximum length including  terminating zero character for Win2003+
650
619
 
651
620
    if (GetLocaleInfo(id, LOCALE_S1159, output, 15)) {
652
 
        return QT_WA_INLINE(
653
 
                QString::fromUtf16(reinterpret_cast<ushort*>(output)),
654
 
                QString::fromLocal8Bit(reinterpret_cast<char*>(output)));
 
621
        return QString::fromWCharArray(output);
655
622
    }
656
623
 
657
624
    return QString();
660
627
static QString winSystemPMText()
661
628
{
662
629
    LCID id = GetUserDefaultLCID();
663
 
    TCHAR output[15]; // maximum length including  terminating zero character for Win2003+
 
630
    wchar_t output[15]; // maximum length including  terminating zero character for Win2003+
664
631
 
665
632
    if (GetLocaleInfo(id, LOCALE_S2359, output, 15)) {
666
 
        return QT_WA_INLINE(
667
 
                QString::fromUtf16(reinterpret_cast<ushort*>(output)),
668
 
                QString::fromLocal8Bit(reinterpret_cast<char*>(output)));
 
633
        return QString::fromWCharArray(output);
669
634
    }
670
635
 
671
636
    return QString();
672
637
}
673
638
 
 
639
/*!
 
640
    \since 4.6
 
641
    Returns the fallback locale obtained from the system.
 
642
 */
674
643
QLocale QSystemLocale::fallbackLocale() const
675
644
{
676
645
    return QLocale(QString::fromLatin1(getWinLocaleName()));
769
738
    return QVariant();
770
739
}
771
740
 
772
 
/* Win95 doesn't have a function to return the ISO lang/country name of the user's locale.
773
 
   Instead it can return a "Windows code". This maps windows codes to ISO country names. */
774
 
 
775
741
struct WindowsToISOListElt {
776
 
    int windows_code;
 
742
    ushort windows_code;
777
743
    char iso_name[6];
778
744
};
779
745
 
927
893
    // Windows returns the wrong ISO639 for some languages, we need to detect them here using
928
894
    // the language code
929
895
    QString lang_code;
930
 
    QT_WA({
931
 
        TCHAR out[256];
932
 
        if (GetLocaleInfoW(id, LOCALE_ILANGUAGE, out, 255))
933
 
            lang_code = QString::fromUtf16((ushort*)out);
934
 
    } , {
935
 
        char out[256];
936
 
        if (GetLocaleInfoA(id, LOCALE_ILANGUAGE, out, 255))
937
 
            lang_code = QString::fromLocal8Bit(out);
938
 
    });
 
896
    wchar_t out[256];
 
897
    if (GetLocaleInfo(id, LOCALE_ILANGUAGE, out, 255))
 
898
        lang_code = QString::fromWCharArray(out);
939
899
 
940
900
    if (!lang_code.isEmpty()) {
941
901
        const char *endptr;
957
917
        return result;
958
918
 
959
919
    // not one of the problematic languages - do the usual lookup
960
 
    QT_WA({
961
 
        TCHAR out[256];
962
 
        if (GetLocaleInfoW(id, LOCALE_SISO639LANGNAME , out, 255))
963
 
            result = QString::fromUtf16((ushort*)out);
964
 
    } , {
965
 
        char out[256];
966
 
        if (GetLocaleInfoA(id, LOCALE_SISO639LANGNAME, out, 255))
967
 
            result = QString::fromLocal8Bit(out);
968
 
    });
 
920
    if (GetLocaleInfo(id, LOCALE_SISO639LANGNAME , out, 255))
 
921
        result = QString::fromWCharArray(out);
969
922
 
970
923
    return result;
971
924
}
974
927
{
975
928
    QString result;
976
929
 
977
 
    QT_WA({
978
 
        TCHAR out[256];
979
 
        if (GetLocaleInfoW(id, LOCALE_SISO3166CTRYNAME, out, 255))
980
 
            result = QString::fromUtf16((ushort*)out);
981
 
    } , {
982
 
        char out[256];
983
 
        if (GetLocaleInfoA(id, LOCALE_SISO3166CTRYNAME, out, 255))
984
 
            result = QString::fromLocal8Bit(out);
985
 
    });
 
930
    wchar_t out[256];
 
931
    if (GetLocaleInfo(id, LOCALE_SISO3166CTRYNAME, out, 255))
 
932
        result = QString::fromWCharArray(out);
986
933
 
987
934
    return result;
988
935
}
1014
961
    if (month < 0 || month > 11)
1015
962
        return QString();
1016
963
 
1017
 
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
1018
 
    if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
1019
 
        QCFType<CFDateFormatterRef> formatter
1020
 
            = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()),
1021
 
                                    kCFDateFormatterNoStyle,  kCFDateFormatterNoStyle);
1022
 
        QCFType<CFArrayRef> values
1023
 
            = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter,
1024
 
                                      short_format ? kCFDateFormatterShortMonthSymbols
1025
 
                                                   : kCFDateFormatterMonthSymbols));
1026
 
        if (values != 0) {
1027
 
            CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, month));
1028
 
            return QCFString::toQString(cfstring);
1029
 
        }
 
964
    QCFType<CFDateFormatterRef> formatter
 
965
        = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()),
 
966
                                kCFDateFormatterNoStyle,  kCFDateFormatterNoStyle);
 
967
    QCFType<CFArrayRef> values
 
968
        = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter,
 
969
                                  short_format ? kCFDateFormatterShortMonthSymbols
 
970
                                               : kCFDateFormatterMonthSymbols));
 
971
    if (values != 0) {
 
972
        CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, month));
 
973
        return QCFString::toQString(cfstring);
1030
974
    }
1031
 
#endif
1032
975
    return QString();
1033
976
}
1034
977
 
1038
981
    if (day < 1 || day > 7)
1039
982
        return QString();
1040
983
 
1041
 
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
1042
 
    if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
1043
 
        QCFType<CFDateFormatterRef> formatter
1044
 
            = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()),
1045
 
                                    kCFDateFormatterNoStyle,  kCFDateFormatterNoStyle);
1046
 
        QCFType<CFArrayRef> values = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter,
1047
 
                                                short_format ? kCFDateFormatterShortWeekdaySymbols
1048
 
                                                             : kCFDateFormatterWeekdaySymbols));
1049
 
        if (values != 0) {
1050
 
            CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, day % 7));
1051
 
            return QCFString::toQString(cfstring);
1052
 
        }
 
984
    QCFType<CFDateFormatterRef> formatter
 
985
        = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()),
 
986
                                kCFDateFormatterNoStyle,  kCFDateFormatterNoStyle);
 
987
    QCFType<CFArrayRef> values = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter,
 
988
                                            short_format ? kCFDateFormatterShortWeekdaySymbols
 
989
                                                         : kCFDateFormatterWeekdaySymbols));
 
990
    if (values != 0) {
 
991
        CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, day % 7));
 
992
        return QCFString::toQString(cfstring);
1053
993
    }
1054
 
#endif
1055
994
    return QString();
1056
995
}
1057
996
 
1136
1075
                break;
1137
1076
            case 'S': // fractional second
1138
1077
                if (repeat < 3)
1139
 
                    result += QLatin1String("z");
 
1078
                    result += QLatin1Char('z');
1140
1079
                else
1141
1080
                    result += QLatin1String("zzz");
1142
1081
                break;
1150
1089
                if (repeat >= 2)
1151
1090
                    result += QLatin1String("dd");
1152
1091
                else
1153
 
                    result += QLatin1String("d");
 
1092
                    result += QLatin1Char('d');
1154
1093
                break;
1155
1094
            case 'a':
1156
1095
                result += QLatin1String("AP");
1211
1150
    }
1212
1151
}
1213
1152
 
 
1153
static void getMacPreferredLanguageAndCountry(QString *language, QString *country)
 
1154
{
 
1155
    QCFType<CFArrayRef> languages = (CFArrayRef)CFPreferencesCopyValue(
 
1156
             CFSTR("AppleLanguages"),
 
1157
             kCFPreferencesAnyApplication,
 
1158
             kCFPreferencesCurrentUser,
 
1159
             kCFPreferencesAnyHost);
 
1160
    if (languages && CFArrayGetCount(languages) > 0) {
 
1161
        QCFType<CFLocaleRef> locale = CFLocaleCreate(kCFAllocatorDefault,
 
1162
                                                     CFStringRef(CFArrayGetValueAtIndex(languages, 0)));
 
1163
        if (language)
 
1164
            *language = QCFString::toQString(CFStringRef(CFLocaleGetValue(locale, kCFLocaleLanguageCode)));
 
1165
        if (country)
 
1166
            *country = QCFString::toQString(CFStringRef(CFLocaleGetValue(locale, kCFLocaleCountryCode)));
 
1167
    }
 
1168
}
 
1169
 
1214
1170
QLocale QSystemLocale::fallbackLocale() const
1215
1171
{
1216
1172
    return QLocale(QString::fromUtf8(getMacLocaleName().constData()));
1255
1211
    case NegativeSign:
1256
1212
    case PositiveSign:
1257
1213
    case ZeroDigit:
 
1214
        break;
1258
1215
    case LanguageId:
1259
 
    case CountryId:
1260
 
        break;
 
1216
    case CountryId: {
 
1217
        QString preferredLanguage;
 
1218
        QString preferredCountry;
 
1219
        getMacPreferredLanguageAndCountry(&preferredLanguage, &preferredCountry);
 
1220
        QLocale::Language languageCode = (preferredLanguage.isEmpty() ? QLocale::C : codeToLanguage(preferredLanguage.data()));
 
1221
        QLocale::Country countryCode = (preferredCountry.isEmpty() ? QLocale::AnyCountry : codeToCountry(preferredCountry.data()));
 
1222
        const QLocalePrivate *d = findLocale(languageCode, countryCode);
 
1223
        if (type == LanguageId)
 
1224
            return (QLocale::Language)d->languageId();
 
1225
        return (QLocale::Country)d->countryId();
 
1226
    }
1261
1227
 
1262
1228
    case MeasurementSystem:
1263
1229
        return QVariant(static_cast<int>(macMeasurementSystem()));
1271
1237
    return QVariant();
1272
1238
}
1273
1239
 
1274
 
#elif defined(Q_OS_UNIX)
 
1240
#elif defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
1275
1241
 
1276
1242
static uint unixGetSystemMeasurementSystem()
1277
1243
{
1315
1281
    }
1316
1282
}
1317
1283
 
1318
 
#else
 
1284
#elif !defined(Q_OS_SYMBIAN)
1319
1285
 
1320
1286
/*!
 
1287
    \since 4.6
 
1288
 
1321
1289
    Returns a fallback locale, that will get used for everything that
1322
1290
    is not explicitly overridden by the system locale.
1323
1291
*/
1534
1502
    l = QLocale(s);
1535
1503
    return ds;
1536
1504
}
1537
 
#endif
 
1505
#endif // QT_NO_DATASTREAM
1538
1506
 
1539
1507
 
1540
1508
/*!
1544
1512
 
1545
1513
    \reentrant
1546
1514
    \ingroup i18n
1547
 
    \ingroup text
 
1515
    \ingroup string-processing
1548
1516
    \ingroup shared
1549
 
    \mainclass
 
1517
 
1550
1518
 
1551
1519
    QLocale is initialized with a language/country pair in its
1552
1520
    constructor and offers number-to-string and string-to-number
1602
1570
    This constructor converts the locale name to a language/country
1603
1571
    pair; it does not use the system locale database.
1604
1572
 
 
1573
    QLocale's data is based on Common Locale Data Repository v1.6.1.
 
1574
 
1605
1575
    The double-to-string and string-to-double conversion functions are
1606
1576
    covered by the following licenses:
1607
1577
 
1622
1592
    This product includes software developed by the University of
1623
1593
    California, Berkeley and its contributors.
1624
1594
 
1625
 
    QLocale's data is based on Common Locale Data Repository v1.6.1.
1626
 
 
1627
1595
    \sa QString::arg(), QString::toInt(), QString::toDouble()
1628
1596
*/
1629
1597
 
2700
2668
    DWORD res = GetTimeZoneInformation(&info);
2701
2669
    if (res == TIME_ZONE_ID_UNKNOWN)
2702
2670
        return QString();
2703
 
    return QString::fromUtf16(reinterpret_cast<const ushort *> (info.StandardName));
 
2671
    return QString::fromWCharArray(info.StandardName);
2704
2672
#elif defined(Q_OS_WIN)
2705
2673
    _tzset();
2706
2674
# if defined(_MSC_VER) && _MSC_VER >= 1400
2712
2680
# else
2713
2681
    return QString::fromLocal8Bit(_tzname[1]);
2714
2682
# endif
 
2683
#elif defined(Q_OS_VXWORKS)
 
2684
    return QString();
2715
2685
#else
2716
2686
    tzset();
2717
2687
    return QString::fromLocal8Bit(tzname[1]);
3947
3917
 
3948
3918
        char *rve = 0;
3949
3919
        char *buff = 0;
3950
 
        digits = QLatin1String(qdtoa(d, mode, pr, &decpt, &sign, &rve, &buff));
 
3920
        QT_TRY {
 
3921
            digits = QLatin1String(qdtoa(d, mode, pr, &decpt, &sign, &rve, &buff));
 
3922
        } QT_CATCH(...) {
 
3923
            if (buff != 0)
 
3924
                free(buff);
 
3925
            QT_RETHROW;
 
3926
        }
3951
3927
        if (buff != 0)
3952
3928
            free(buff);
3953
3929
#endif // QT_QLOCALE_USES_FCVT
4671
4647
 * Ignores `locale' stuff.  Assumes that the upper and lower case
4672
4648
 * alphabets and digits are each contiguous.
4673
4649
 */
4674
 
Q_CORE_EXPORT qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok)
 
4650
static qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok)
4675
4651
{
4676
4652
    register const char *s;
4677
4653
    register qulonglong acc;
5010
4986
#define Bletch 0x10
5011
4987
#define Bndry_mask  0xfffff
5012
4988
#define Bndry_mask1 0xfffff
 
4989
#if defined(LSB) && defined(Q_OS_VXWORKS)
 
4990
#undef LSB
 
4991
#endif
5013
4992
#define LSB 1
5014
4993
#define Sign_bit 0x80000000
5015
4994
#define Log2P 1
5117
5096
 
5118
5097
    x = 1 << k;
5119
5098
    rv = static_cast<Bigint *>(MALLOC(sizeof(Bigint) + (x-1)*sizeof(Long)));
 
5099
    Q_CHECK_PTR(rv);
5120
5100
    rv->k = k;
5121
5101
    rv->maxwds = x;
5122
5102
    rv->sign = rv->wds = 0;
5367
5347
 
5368
5348
static Bigint *p5s;
5369
5349
 
 
5350
struct p5s_deleter
 
5351
{
 
5352
    ~p5s_deleter()
 
5353
    {
 
5354
        while (p5s) {
 
5355
            Bigint *next = p5s->next;
 
5356
            Bfree(p5s);
 
5357
            p5s = next;
 
5358
        }
 
5359
    }
 
5360
};
 
5361
 
5370
5362
static Bigint *pow5mult(Bigint *b, int k)
5371
5363
{
5372
5364
    Bigint *b1, *p5, *p51;
5388
5380
        return b;
5389
5381
    if (!(p5 = p5s)) {
5390
5382
        /* first time */
 
5383
        static p5s_deleter deleter;
5391
5384
        p5 = p5s = i2b(625);
5392
5385
        p5->next = 0;
5393
5386
    }
6780
6773
        if (i <= 0)
6781
6774
            i = 1;
6782
6775
    }
6783
 
    *resultp = static_cast<char *>(malloc(i + 1));
 
6776
    QT_TRY {
 
6777
        *resultp = static_cast<char *>(malloc(i + 1));
 
6778
        Q_CHECK_PTR(*resultp);
 
6779
    } QT_CATCH(...) {
 
6780
        Bfree(b);
 
6781
        QT_RETHROW;
 
6782
    }
6784
6783
    s = s0 = *resultp;
6785
6784
 
6786
6785
    if (ilim >= 0 && ilim <= Quick_max && try_quick) {
7202
7201
        n = i + 1;
7203
7202
    }
7204
7203
    *resultp = static_cast<char*>(malloc(n + 1));
 
7204
    Q_CHECK_PTR(resultp);
7205
7205
    qstrncpy(*resultp, res, n + 1);
7206
7206
    return *resultp;
7207
7207
}
7211
7211
    double ret = strtod((char*)s00, (char**)se);
7212
7212
    if (ok) {
7213
7213
      if((ret == 0.0l && errno == ERANGE)
7214
 
         || ret == HUGE_VAL || ret == -HUGE_VAL)
7215
 
        *ok = false;
 
7214
         || ret == HUGE_VAL || ret == -HUGE_VAL)
 
7215
        *ok = false;
7216
7216
      else
7217
7217
        *ok = true; // the result will be that we don't report underflow in this case
7218
7218
    }