Commit 0b2190dad38cbe4c8245d500a0fc7cf6f69cc0da
- Diff rendering mode:
- inline
- side by side
|   | |||
| 399 | 399 | return s; | |
| 400 | 400 | } | |
| 401 | 401 | ||
| 402 | QByteArray QWindowsLocalCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *) const | ||
| 402 | QByteArray QWindowsLocalCodec::convertFromUnicode(const QChar *ch, int uclen, ConverterState *) const | ||
| 403 | 403 | { | |
| 404 | return qt_winQString2MB(uc, len); | ||
| 404 | if (!ch) | ||
| 405 | return QByteArray(); | ||
| 406 | if (uclen == 0) | ||
| 407 | return QByteArray(""); | ||
| 408 | BOOL used_def; | ||
| 409 | QByteArray mb(4096, 0); | ||
| 410 | int len; | ||
| 411 | while (!(len=WideCharToMultiByte(CP_ACP, 0, (const wchar_t*)ch, uclen, | ||
| 412 | mb.data(), mb.size()-1, 0, &used_def))) | ||
| 413 | { | ||
| 414 | int r = GetLastError(); | ||
| 415 | if (r == ERROR_INSUFFICIENT_BUFFER) { | ||
| 416 | mb.resize(1+WideCharToMultiByte(CP_ACP, 0, | ||
| 417 | (const wchar_t*)ch, uclen, | ||
| 418 | 0, 0, 0, &used_def)); | ||
| 419 | // and try again... | ||
| 420 | } else { | ||
| 421 | #ifndef QT_NO_DEBUG | ||
| 422 | // Fail. | ||
| 423 | qWarning("WideCharToMultiByte: Cannot convert multibyte text (error %d): %s (UTF-8)", | ||
| 424 | r, QString(ch, uclen).toLocal8Bit().data()); | ||
| 425 | #endif | ||
| 426 | break; | ||
| 427 | } | ||
| 428 | } | ||
| 429 | mb.resize(len); | ||
| 430 | return mb; | ||
| 405 | 431 | } | |
| 406 | 432 | ||
| 407 | 433 |
src/corelib/tools/qstring.cpp
(6 / 94)
|   | |||
| 3827 | 3827 | ||
| 3828 | 3828 | #endif | |
| 3829 | 3829 | ||
| 3830 | QT_END_NAMESPACE | ||
| 3831 | |||
| 3832 | #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) | ||
| 3833 | #include "qt_windows.h" | ||
| 3834 | |||
| 3835 | QT_BEGIN_NAMESPACE | ||
| 3836 | |||
| 3837 | QByteArray qt_winQString2MB(const QString& s, int uclen) | ||
| 3838 | { | ||
| 3839 | if (uclen < 0) | ||
| 3840 | uclen = s.length(); | ||
| 3841 | if (s.isNull()) | ||
| 3842 | return QByteArray(); | ||
| 3843 | if (uclen == 0) | ||
| 3844 | return QByteArray(""); | ||
| 3845 | return qt_winQString2MB(s.constData(), uclen); | ||
| 3846 | } | ||
| 3847 | |||
| 3848 | QByteArray qt_winQString2MB(const QChar *ch, int uclen) | ||
| 3849 | { | ||
| 3850 | if (!ch) | ||
| 3851 | return QByteArray(); | ||
| 3852 | if (uclen == 0) | ||
| 3853 | return QByteArray(""); | ||
| 3854 | BOOL used_def; | ||
| 3855 | QByteArray mb(4096, 0); | ||
| 3856 | int len; | ||
| 3857 | while (!(len=WideCharToMultiByte(CP_ACP, 0, (const wchar_t*)ch, uclen, | ||
| 3858 | mb.data(), mb.size()-1, 0, &used_def))) | ||
| 3859 | { | ||
| 3860 | int r = GetLastError(); | ||
| 3861 | if (r == ERROR_INSUFFICIENT_BUFFER) { | ||
| 3862 | mb.resize(1+WideCharToMultiByte(CP_ACP, 0, | ||
| 3863 | (const wchar_t*)ch, uclen, | ||
| 3864 | 0, 0, 0, &used_def)); | ||
| 3865 | // and try again... | ||
| 3866 | } else { | ||
| 3867 | #ifndef QT_NO_DEBUG | ||
| 3868 | // Fail. | ||
| 3869 | qWarning("WideCharToMultiByte: Cannot convert multibyte text (error %d): %s (UTF-8)", | ||
| 3870 | r, QString(ch, uclen).toLocal8Bit().data()); | ||
| 3871 | #endif | ||
| 3872 | break; | ||
| 3873 | } | ||
| 3874 | } | ||
| 3875 | mb.resize(len); | ||
| 3876 | return mb; | ||
| 3877 | } | ||
| 3878 | |||
| 3879 | QString qt_winMB2QString(const char *mb, int mblen) | ||
| 3880 | { | ||
| 3881 | if (!mb || !mblen) | ||
| 3882 | return QString(); | ||
| 3883 | const int wclen_auto = 4096; | ||
| 3884 | wchar_t wc_auto[wclen_auto]; | ||
| 3885 | int wclen = wclen_auto; | ||
| 3886 | wchar_t *wc = wc_auto; | ||
| 3887 | int len; | ||
| 3888 | while (!(len=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, | ||
| 3889 | mb, mblen, wc, wclen))) | ||
| 3890 | { | ||
| 3891 | int r = GetLastError(); | ||
| 3892 | if (r == ERROR_INSUFFICIENT_BUFFER) { | ||
| 3893 | if (wc != wc_auto) { | ||
| 3894 | qWarning("MultiByteToWideChar: Size changed"); | ||
| 3895 | break; | ||
| 3896 | } else { | ||
| 3897 | wclen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, | ||
| 3898 | mb, mblen, 0, 0); | ||
| 3899 | wc = new wchar_t[wclen]; | ||
| 3900 | // and try again... | ||
| 3901 | } | ||
| 3902 | } else { | ||
| 3903 | // Fail. | ||
| 3904 | qWarning("MultiByteToWideChar: Cannot convert multibyte text"); | ||
| 3905 | break; | ||
| 3906 | } | ||
| 3907 | } | ||
| 3908 | if (len <= 0) | ||
| 3909 | return QString(); | ||
| 3910 | if (wc[len-1] == 0) // len - 1: we don't want terminator | ||
| 3911 | --len; | ||
| 3912 | QString s((QChar*)wc, len); | ||
| 3913 | if (wc != wc_auto) | ||
| 3914 | delete [] wc; | ||
| 3915 | return s; | ||
| 3916 | } | ||
| 3917 | |||
| 3918 | QT_END_NAMESPACE | ||
| 3919 | |||
| 3920 | #endif // Q_OS_WIN32 | ||
| 3921 | |||
| 3922 | QT_BEGIN_NAMESPACE | ||
| 3923 | |||
| 3924 | 3830 | /*! | |
| 3925 | 3831 | Returns a QString initialized with the first \a size characters | |
| 3926 | 3832 | of the 8-bit string \a str. | |
| … | … | ||
| 4720 | 4720 | { | |
| 4721 | 4721 | return localeAwareCompare_helper(constData(), length(), other.constData(), other.length()); | |
| 4722 | 4722 | } | |
| 4723 | |||
| 4724 | #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) | ||
| 4725 | QT_END_NAMESPACE | ||
| 4726 | #include "qt_windows.h" | ||
| 4727 | QT_BEGIN_NAMESPACE | ||
| 4728 | #endif | ||
| 4723 | 4729 | ||
| 4724 | 4730 | /*! | |
| 4725 | 4731 | \internal |
src/corelib/tools/qstring.h
(0 / 6)
|   | |||
| 1096 | 1096 | Q_DECLARE_SHARED(QString) | |
| 1097 | 1097 | Q_DECLARE_OPERATORS_FOR_FLAGS(QString::SectionFlags) | |
| 1098 | 1098 | ||
| 1099 | #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) | ||
| 1100 | extern Q_CORE_EXPORT QByteArray qt_winQString2MB(const QString& s, int len=-1); | ||
| 1101 | extern Q_CORE_EXPORT QByteArray qt_winQString2MB(const QChar *ch, int len); | ||
| 1102 | extern Q_CORE_EXPORT QString qt_winMB2QString(const char* mb, int len=-1); | ||
| 1103 | #endif | ||
| 1104 | |||
| 1105 | 1099 | ||
| 1106 | 1100 | class Q_CORE_EXPORT QStringRef { | |
| 1107 | 1101 | const QString *m_string; |

