[Scummvm-git-logs] scummvm master -> 02c09a8ed600ad4874d45f53809f87dfb537622e
sev-
sev at scummvm.org
Sat Sep 12 09:59:28 UTC 2020
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
6e0c93dc46 COMMON: Add helper functions for converting strings
da978f3a2f WIN32: Simplify string conversion
02c09a8ed6 WIN32: Replace strToInt with wcstol
Commit: 6e0c93dc46c268648461fb43a73e5ebce1e9644c
https://github.com/scummvm/scummvm/commit/6e0c93dc46c268648461fb43a73e5ebce1e9644c
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2020-09-12T11:59:23+02:00
Commit Message:
COMMON: Add helper functions for converting strings
Changed paths:
common/encoding.h
common/str-enc.cpp
common/text-to-speech.h
diff --git a/common/encoding.h b/common/encoding.h
index 7a41b2980f..503fbf5ab8 100644
--- a/common/encoding.h
+++ b/common/encoding.h
@@ -78,6 +78,14 @@ class Encoding {
*/
static char *convert(const String &to, const String &from, const char *string, size_t length);
+ static char *convert(const String &to, const String &from, const String &s) {
+ return convert(to, from, s.c_str(), s.size());
+ }
+
+ static char *convert(const String &to, const U32String &s) {
+ return convert(to, "UTF-32", (const char *)s.c_str(), s.size() * 4);
+ }
+
/**
* @return The encoding, which is currently being converted from
*/
diff --git a/common/str-enc.cpp b/common/str-enc.cpp
index 3a099e48ef..42ba83d9ce 100644
--- a/common/str-enc.cpp
+++ b/common/str-enc.cpp
@@ -345,7 +345,7 @@ U32String String::decode(CodePage page) const {
page >= ARRAYSIZE(g_codePageMap)) {
error("Invalid codepage");
}
- char *result = Encoding::convert("UTF-32", g_codePageMap[page], _str, _size);
+ char *result = Encoding::convert("UTF-32", g_codePageMap[page], *this);
if (result) {
U32String unicodeString((uint32 *)result);
free(result);
@@ -419,7 +419,7 @@ String U32String::encode(CodePage page) const {
page >= ARRAYSIZE(g_codePageMap)) {
error("Invalid codepage");
}
- char *result = Encoding::convert(g_codePageMap[page], "UTF-32", (const char *)_str, _size * 4);
+ char *result = Encoding::convert(g_codePageMap[page], *this);
if (result) {
// Encodings in CodePage all use '\0' as string ending
// That would be problematic if CodePage has UTF-16 or UTF-32
diff --git a/common/text-to-speech.h b/common/text-to-speech.h
index e158864225..041842aa85 100644
--- a/common/text-to-speech.h
+++ b/common/text-to-speech.h
@@ -175,9 +175,8 @@ public:
* It will convert to UTF-32 before passing along to the intended method.
*/
bool say(const String &str, Action action, String charset = "UTF-8") {
- Encoding speakWithCustomCharset("UTF-32", charset);
- char *res = speakWithCustomCharset.convert(str.c_str(), str.size());
- U32String textToSpeak(reinterpret_cast<uint32*>(res));
+ uint32 *res = (uint32 *)Encoding::convert("UTF-32", charset, str);
+ U32String textToSpeak(res);
free(res);
return say(textToSpeak, action);
Commit: da978f3a2fc09c94e277e416e40bc64c1b3131ad
https://github.com/scummvm/scummvm/commit/da978f3a2fc09c94e277e416e40bc64c1b3131ad
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2020-09-12T11:59:23+02:00
Commit Message:
WIN32: Simplify string conversion
Changed paths:
backends/dialogs/win32/win32-dialogs.cpp
backends/platform/sdl/win32/win32_wrapper.cpp
backends/platform/sdl/win32/win32_wrapper.h
backends/text-to-speech/windows/windows-text-to-speech.cpp
diff --git a/backends/dialogs/win32/win32-dialogs.cpp b/backends/dialogs/win32/win32-dialogs.cpp
index 49546182c4..100ed720b1 100644
--- a/backends/dialogs/win32/win32-dialogs.cpp
+++ b/backends/dialogs/win32/win32-dialogs.cpp
@@ -67,6 +67,7 @@
#include "backends/platform/sdl/win32/win32-window.h"
#include "common/config-manager.h"
+#include "common/encoding.h"
#include "common/translation.h"
Win32DialogManager::Win32DialogManager(SdlWindow_Win32 *window) : _window(window) {
@@ -130,11 +131,11 @@ Common::DialogManager::DialogResult Win32DialogManager::showFileBrowser(const Co
hr = dialog->SetOptions(dwOptions);
}
- LPWSTR dialogTitle = Win32::UTF8ToUnicode(title.encode().c_str());
+ LPWSTR dialogTitle = (LPWSTR)Common::Encoding::convert("UTF-16", title);
hr = dialog->SetTitle(dialogTitle);
free(dialogTitle);
- LPWSTR okTitle = Win32::UTF8ToUnicode(_("Choose").encode().c_str());
+ LPWSTR okTitle = (LPWSTR)Common::Encoding::convert("UTF-16", _("Choose"));
hr = dialog->SetOkButtonLabel(okTitle);
free(okTitle);
diff --git a/backends/platform/sdl/win32/win32_wrapper.cpp b/backends/platform/sdl/win32/win32_wrapper.cpp
index 0ac9d07705..2764453dc1 100644
--- a/backends/platform/sdl/win32/win32_wrapper.cpp
+++ b/backends/platform/sdl/win32/win32_wrapper.cpp
@@ -105,16 +105,4 @@ char *unicodeToAnsi(const wchar_t *s, uint codePage) {
return NULL;
}
-wchar_t *UTF8ToUnicode(const char *s) {
- DWORD size = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
-
- if (size > 0) {
- LPWSTR result = (LPWSTR)calloc(size, sizeof(WCHAR));
- if (MultiByteToWideChar(CP_UTF8, 0, s, -1, result, size) != 0)
- return result;
- }
-
- return NULL;
-}
-
}
diff --git a/backends/platform/sdl/win32/win32_wrapper.h b/backends/platform/sdl/win32/win32_wrapper.h
index 0b46cae648..ee3b77bed6 100644
--- a/backends/platform/sdl/win32/win32_wrapper.h
+++ b/backends/platform/sdl/win32/win32_wrapper.h
@@ -61,17 +61,6 @@ wchar_t *ansiToUnicode(const char *s, uint codePage = CP_ACP);
*/
char *unicodeToAnsi(const wchar_t *s, uint codePage = CP_ACP);
-/**
- * Converts a C string encoded in UTF8-multibyte char into a Windows wide-character string.
- * Used to interact with Win32 Unicode APIs with no ANSI fallback.
- *
- * @param s Source string, encoded in UTF8
- * @return Converted string
- *
- * @note Return value must be freed by the caller.
- */
-wchar_t *UTF8ToUnicode(const char *s);
-
}
#endif
diff --git a/backends/text-to-speech/windows/windows-text-to-speech.cpp b/backends/text-to-speech/windows/windows-text-to-speech.cpp
index c534544067..9dc79451ee 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -183,15 +183,11 @@ bool WindowsTextToSpeechManager::say(const Common::U32String &str, Action action
if (isSpeaking() && action == DROP)
return true;
- Common::String strToSpeak = str.encode();
- Common::String charset = "UTF-8";
-
// We have to set the pitch by prepending xml code at the start of the said string;
- Common::String pitch = Common::String::format("<pitch absmiddle=\"%d\">", _ttsState->_pitch / 10);
- strToSpeak.replace((uint32)0, 0, pitch);
- WCHAR *strW = (WCHAR *) Common::Encoding::convert("UTF-16", charset, strToSpeak.c_str(), strToSpeak.size());
+ Common::U32String pitch = Common::U32String::format(Common::U32String("<pitch absmiddle=\"%d\">%S"), _ttsState->_pitch / 10, str.c_str());
+ WCHAR *strW = (WCHAR *) Common::Encoding::convert("UTF-16", pitch);
if (strW == nullptr) {
- warning("Cannot convert from %s encoding for text to speech", charset.c_str());
+ warning("Cannot convert from UTF-32 encoding for text to speech");
return true;
}
Commit: 02c09a8ed600ad4874d45f53809f87dfb537622e
https://github.com/scummvm/scummvm/commit/02c09a8ed600ad4874d45f53809f87dfb537622e
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2020-09-12T11:59:23+02:00
Commit Message:
WIN32: Replace strToInt with wcstol
Changed paths:
backends/text-to-speech/windows/windows-text-to-speech.cpp
backends/text-to-speech/windows/windows-text-to-speech.h
diff --git a/backends/text-to-speech/windows/windows-text-to-speech.cpp b/backends/text-to-speech/windows/windows-text-to-speech.cpp
index 9dc79451ee..974d677978 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -380,7 +380,7 @@ void WindowsTextToSpeechManager::createVoice(void *cpVoiceToken) {
warning("Could not get the language attribute for voice: %s", desc.c_str());
return;
}
- Common::String language = lcidToLocale(data);
+ Common::String language = lcidToLocale(wcstol(data, NULL, 16));
CoTaskMemFree(data);
// only get the voices for the current language
@@ -412,20 +412,7 @@ void WindowsTextToSpeechManager::createVoice(void *cpVoiceToken) {
_ttsState->_availableVoices.push_back(Common::TTSVoice(gender, age, (void *) voiceToken, desc));
}
-int strToInt(WCHAR *str) {
- int result = 0;
- for (unsigned i = 0; i < wcslen(str); i++) {
- WCHAR c = towupper(str[i]);
- if (c < L'0' || (c > L'9' && c < L'A') || c > L'F')
- break;
- int num = (c <= L'9') ? c - L'0' : c - 55;
- result = result * 16 + num;
- }
- return result;
-}
-
-Common::String WindowsTextToSpeechManager::lcidToLocale(WCHAR *lcid) {
- LCID locale = strToInt(lcid);
+Common::String WindowsTextToSpeechManager::lcidToLocale(LCID locale) {
int nchars = GetLocaleInfoA(locale, LOCALE_SISO639LANGNAME, NULL, 0);
char *languageCode = new char[nchars];
GetLocaleInfoA(locale, LOCALE_SISO639LANGNAME, languageCode, nchars);
diff --git a/backends/text-to-speech/windows/windows-text-to-speech.h b/backends/text-to-speech/windows/windows-text-to-speech.h
index 9005142215..c07f286a9c 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.h
+++ b/backends/text-to-speech/windows/windows-text-to-speech.h
@@ -78,7 +78,7 @@ private:
void init();
virtual void updateVoices() override;
void createVoice(void *cpVoiceToken);
- Common::String lcidToLocale(WCHAR *lcid);
+ Common::String lcidToLocale(LCID locale);
SpeechState _speechState;
Common::String _lastSaid;
HANDLE _thread;
More information about the Scummvm-git-logs
mailing list