[dasher: 142/217] Fix stripping of the first 3 bytes of the string in WinUTF8::narrow when the explicit LTR or RTL mar
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 142/217] Fix stripping of the first 3 bytes of the string in WinUTF8::narrow when the explicit LTR or RTL mar
- Date: Sat, 27 Feb 2016 12:12:15 +0000 (UTC)
commit a0f19c7101038b170a7badf7d3017de20574e66e
Author: lbaudoin google com <lbaudoin google com>
Date: Fri Dec 11 06:16:27 2015 -0700
Fix stripping of the first 3 bytes of the string in WinUTF8::narrow when the explicit LTR or RTL markers
are not present
Src/DasherCore/XmlSettingsStore.cpp | 2 +-
Src/Win32/Common/WinUTF8.cpp | 19 ++++++++-----------
Src/Win32/Common/WinUTF8.h | 3 +--
3 files changed, 10 insertions(+), 14 deletions(-)
---
diff --git a/Src/DasherCore/XmlSettingsStore.cpp b/Src/DasherCore/XmlSettingsStore.cpp
index 02c212a..f305081 100644
--- a/Src/DasherCore/XmlSettingsStore.cpp
+++ b/Src/DasherCore/XmlSettingsStore.cpp
@@ -10,7 +10,7 @@
#if defined(_WIN32) || defined(_WIN64)
#include "WinUTF8.h"
#define strcasecmp _stricmp
-#define widen(a) WinUTF8::widen(a)
+#define widen(a) WinUTF8::UTF8string_to_wstring((a))
#else
#define widen((a)) (a)
#endif
diff --git a/Src/Win32/Common/WinUTF8.cpp b/Src/Win32/Common/WinUTF8.cpp
index 9e5b7d8..ea3a774 100644
--- a/Src/Win32/Common/WinUTF8.cpp
+++ b/Src/Win32/Common/WinUTF8.cpp
@@ -78,21 +78,18 @@ string WinUTF8::wstring_to_UTF8string(const wchar_t *Input) {
}
void WinUTF8::wstring_to_UTF8string(const wchar_t *Input, string &Output) {
- size_t len = wcslen(Input);
- int size_needed = WideCharToMultiByte(CP_UTF8, 0, Input, len, nullptr, 0, nullptr, nullptr);
+ size_t len = wcslen(Input);
+ auto size_needed = WideCharToMultiByte(CP_UTF8, 0, Input, len, nullptr, 0, nullptr, nullptr);
Output.resize(size_needed);
WideCharToMultiByte(CP_UTF8, 0, Input, (int)Output.size(), &Output[0], size_needed, NULL, NULL);
return;
}
-std::wstring_convert<std::codecvt_utf8<wchar_t, 0x10ffff, std::consume_header>, wchar_t> utf16conv;
-std::wstring WinUTF8::widen(const char* utf8) {
- return utf16conv.from_bytes(utf8);
-}
-std::wstring WinUTF8::widen(const std::string& utf8) {
- return utf16conv.from_bytes(utf8);
-}
-
std::string WinUTF8::narrow(const wchar_t* wide) {
- return utf16conv.to_bytes(wide).substr(3); // Remove the BOM.
+ auto result = wstring_to_UTF8string(wide);
+ // Remove the explicit left to right or right to left mark if present.
+ if (result.size() >= 3 && (result.find("\xE2\x80\xAA") == 0 || result.find("\xE2\x80\xAB") == 0)) {
+ return result.substr(3);
+ }
+ return result;
}
diff --git a/Src/Win32/Common/WinUTF8.h b/Src/Win32/Common/WinUTF8.h
index cef6543..7abaad8 100644
--- a/Src/Win32/Common/WinUTF8.h
+++ b/Src/Win32/Common/WinUTF8.h
@@ -26,8 +26,7 @@ namespace WinUTF8 {
void wstring_to_UTF8string(const wchar_t *Input, std::string &Output);
std::string wstring_to_UTF8string(const wchar_t* Input);
- std::wstring widen(const char* utf8);
- std::wstring widen(const std::string& utf8);
+ // Remove the explicit left to right or right to left mark if present.
std::string narrow(const wchar_t* wide);
}
#endif /* #ifndef __WinUTF8_h__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]