diff options
author | Neil <nyamatongwe@gmail.com> | 2015-01-13 09:44:35 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2015-01-13 09:44:35 +1100 |
commit | bcdda18c2aa062fea2f754cb600f0b4ef94b300b (patch) | |
tree | 2220dee16cde5dd5394521436e000a02a7d0d2df | |
parent | ae17fbc86661c895d08fad5416a1452bdef04d32 (diff) | |
download | scintilla-mirror-bcdda18c2aa062fea2f754cb600f0b4ef94b300b.tar.gz |
Using size_t instead of unsigned int for conversions to UTF16 for 64-bit
compatibility and to lessen the number of casts.
-rw-r--r-- | src/UniConversion.cxx | 14 | ||||
-rw-r--r-- | src/UniConversion.h | 4 | ||||
-rw-r--r-- | win32/PlatWin.cxx | 4 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 22 |
4 files changed, 22 insertions, 22 deletions
diff --git a/src/UniConversion.cxx b/src/UniConversion.cxx index d19828a52..dea069843 100644 --- a/src/UniConversion.cxx +++ b/src/UniConversion.cxx @@ -82,10 +82,10 @@ unsigned int UTF8CharLength(unsigned char ch) { } } -unsigned int UTF16Length(const char *s, unsigned int len) { - unsigned int ulen = 0; - unsigned int charLen; - for (unsigned int i=0; i<len;) { +size_t UTF16Length(const char *s, size_t len) { + size_t ulen = 0; + size_t charLen; + for (size_t i = 0; i<len;) { unsigned char ch = static_cast<unsigned char>(s[i]); if (ch < 0x80) { charLen = 1; @@ -103,10 +103,10 @@ unsigned int UTF16Length(const char *s, unsigned int len) { return ulen; } -unsigned int UTF16FromUTF8(const char *s, unsigned int len, wchar_t *tbuf, unsigned int tlen) { - unsigned int ui=0; +size_t UTF16FromUTF8(const char *s, size_t len, wchar_t *tbuf, size_t tlen) { + size_t ui = 0; const unsigned char *us = reinterpret_cast<const unsigned char *>(s); - unsigned int i=0; + size_t i = 0; while ((i<len) && (ui<tlen)) { unsigned char ch = us[i++]; if (ch < 0x80) { diff --git a/src/UniConversion.h b/src/UniConversion.h index 760f50476..8c7ac4a27 100644 --- a/src/UniConversion.h +++ b/src/UniConversion.h @@ -19,8 +19,8 @@ const int unicodeReplacementChar = 0xFFFD; unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen); void UTF8FromUTF16(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len); unsigned int UTF8CharLength(unsigned char ch); -unsigned int UTF16Length(const char *s, unsigned int len); -unsigned int UTF16FromUTF8(const char *s, unsigned int len, wchar_t *tbuf, unsigned int tlen); +size_t UTF16Length(const char *s, size_t len); +size_t UTF16FromUTF8(const char *s, size_t len, wchar_t *tbuf, size_t tlen); unsigned int UTF32FromUTF8(const char *s, unsigned int len, unsigned int *tbuf, unsigned int tlen); unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf); diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index b0a5fb512..853473e11 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -331,7 +331,7 @@ FontCached::FontCached(const FontParameters &fp) : IDWriteTextFormat *pTextFormat; const int faceSize = 200; WCHAR wszFace[faceSize]; - UTF16FromUTF8(fp.faceName, static_cast<unsigned int>(strlen(fp.faceName))+1, wszFace, faceSize); + UTF16FromUTF8(fp.faceName, strlen(fp.faceName)+1, wszFace, faceSize); FLOAT fHeight = fp.size; DWRITE_FONT_STYLE style = fp.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL; HRESULT hr = pIDWriteFactory->CreateTextFormat(wszFace, NULL, @@ -486,7 +486,7 @@ public: TextWide(const char *s, int len, bool unicodeMode, int codePage=0) : VarBuffer<wchar_t, stackBufferLength>(len) { if (unicodeMode) { - tlen = UTF16FromUTF8(s, len, buffer, len); + tlen = static_cast<int>(UTF16FromUTF8(s, len, buffer, len)); } else { // Support Asian string display in 9x English tlen = ::MultiByteToWideChar(codePage, 0, s, len, buffer, len); diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 3bafee4bf..100361a1b 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -1020,12 +1020,12 @@ sptr_t ScintillaWin::GetText(uptr_t wParam, sptr_t lParam) { std::vector<char> docBytes(pdoc->Length(), '\0'); pdoc->GetCharRange(&docBytes[0], 0, pdoc->Length()); if (IsUnicodeMode()) { - unsigned int lengthUTF16 = UTF16Length(&docBytes[0], static_cast<unsigned int>(docBytes.size())); + size_t lengthUTF16 = UTF16Length(&docBytes[0], static_cast<unsigned int>(docBytes.size())); if (lParam == 0) return lengthUTF16; if (wParam == 0) return 0; - unsigned int uLen = UTF16FromUTF8(&docBytes[0], static_cast<unsigned int>(docBytes.size()), + size_t uLen = UTF16FromUTF8(&docBytes[0], docBytes.size(), ptr, static_cast<int>(wParam) - 1); ptr[uLen] = L'\0'; return uLen; @@ -1847,8 +1847,8 @@ public: if (foldedUTF8) { // Maximum length of a case conversion is 6 bytes, 3 characters wchar_t wFolded[20]; - unsigned int charsConverted = UTF16FromUTF8(foldedUTF8, - static_cast<unsigned int>(strlen(foldedUTF8)), + size_t charsConverted = UTF16FromUTF8(foldedUTF8, + strlen(foldedUTF8), wFolded, ELEMENTS(wFolded)); for (size_t j=0; j<charsConverted; j++) utf16Folded[lenFlat++] = wFolded[j]; @@ -1893,13 +1893,13 @@ CaseFolder *ScintillaWin::CaseFolderForEncoding() { const char *caseFolded = CaseConvert(wCharacter[0], CaseConversionFold); if (caseFolded) { wchar_t wLower[20]; - unsigned int charsConverted = UTF16FromUTF8(caseFolded, - static_cast<unsigned int>(strlen(caseFolded)), + size_t charsConverted = UTF16FromUTF8(caseFolded, + strlen(caseFolded), wLower, ELEMENTS(wLower)); if (charsConverted == 1) { char sCharacterLowered[20]; unsigned int lengthConverted = ::WideCharToMultiByte(cpDoc, 0, - wLower, charsConverted, + wLower, static_cast<int>(charsConverted), sCharacterLowered, ELEMENTS(sCharacterLowered), NULL, 0); if ((lengthConverted == 1) && (sCharacter[0] != sCharacterLowered[0])) { pcf->SetTranslation(sCharacter[0], sCharacterLowered[0]); @@ -2538,11 +2538,11 @@ void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) { // Default Scintilla behaviour in Unicode mode if (IsUnicodeMode()) { - int uchars = UTF16Length(selectedText.Data(), + size_t uchars = UTF16Length(selectedText.Data(), static_cast<int>(selectedText.LengthWithTerminator())); uniText.Allocate(2 * uchars); if (uniText) { - UTF16FromUTF8(selectedText.Data(), static_cast<int>(selectedText.LengthWithTerminator()), + UTF16FromUTF8(selectedText.Data(), selectedText.LengthWithTerminator(), static_cast<wchar_t *>(uniText.ptr), uchars); } } else { @@ -2915,10 +2915,10 @@ STDMETHODIMP ScintillaWin::GetData(FORMATETC *pFEIn, STGMEDIUM *pSTM) { GlobalMemory text; if (pFEIn->cfFormat == CF_UNICODETEXT) { - int uchars = UTF16Length(drag.Data(), static_cast<int>(drag.LengthWithTerminator())); + size_t uchars = UTF16Length(drag.Data(), static_cast<int>(drag.LengthWithTerminator())); text.Allocate(2 * uchars); if (text) { - UTF16FromUTF8(drag.Data(), static_cast<int>(drag.LengthWithTerminator()), + UTF16FromUTF8(drag.Data(), drag.LengthWithTerminator(), static_cast<wchar_t *>(text.ptr), uchars); } } else { |