Skip to content

Commit

Permalink
Merge pull request #1887 from cfillion/normalizestring-winxp
Browse files Browse the repository at this point in the history
  • Loading branch information
cfillion authored Aug 14, 2024
2 parents e6d5d73 + 12f5534 commit 5d3511f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion ReaScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ Mode values:
* 1 = decomposition + canonical composition
- Bit 1 (decomposition mode):
* 0 = canonical decomposition
* 1 = compatibility decomposition)", },
* 1 = compatibility decomposition
Warning: this function is no-op on Windows XP (the input string is returned as-is).)", },

{ APIFUNC(CF_CreatePreview), "CF_Preview*", "PCM_source*", "source", R"(Create a new preview object. Does not take ownership of the source (don't forget to destroy it unless it came from a take!). See CF_Preview_Play and the others CF_Preview_* functions.
Expand Down
22 changes: 16 additions & 6 deletions cfillion/cfillion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@

#ifdef __APPLE__
# include <CoreFoundation/CFString.h>
#elif !defined(_WIN32)
#elif defined(_WIN32)
# include "Utility/win32-import.h"
#else
# include <glib.h>
#endif

Expand Down Expand Up @@ -602,6 +604,14 @@ void CF_NormalizeUTF8(const char *input, const unsigned int mode,

CFRelease(normalized);
#elif defined(_WIN32)
static win32::import<decltype(NormalizeString)> _NormalizeString
{"Normaliz.dll", "NormalizeString"}; // not available in XP

if(!_NormalizeString) {
snprintf(output, outputSize, "%s", input);
return;
}

constexpr NORM_FORM forms[] {
NormalizationD, // 0b00
NormalizationC, // 0b01
Expand All @@ -611,16 +621,16 @@ void CF_NormalizeUTF8(const char *input, const unsigned int mode,
const NORM_FORM form { forms[mode & 0b11] };

const std::wstring &utf16 { win32::widen(input) };
const int normalizedChars
{ NormalizeString(form, utf16.c_str(), utf16.size(), nullptr, 0) };
int normalizedChars
{ _NormalizeString(form, utf16.c_str(), utf16.size(), nullptr, 0) };
std::vector<wchar_t> normalized(normalizedChars);
NormalizeString(form, utf16.c_str(), utf16.size(),
normalizedChars = _NormalizeString(form, utf16.c_str(), utf16.size(),
normalized.data(), normalized.size());

const int normalizedSize { WideCharToMultiByte(CP_UTF8, 0,
normalized.data(), normalized.size(), nullptr, 0, nullptr, nullptr) };
normalized.data(), normalizedChars, nullptr, 0, nullptr, nullptr) };
if(realloc_cmd_ptr(&output, &outputSize, normalizedSize)) {
WideCharToMultiByte(CP_UTF8, 0, normalized.data(), normalized.size(),
WideCharToMultiByte(CP_UTF8, 0, normalized.data(), normalizedChars,
output, outputSize, nullptr, nullptr);
}
#else
Expand Down

0 comments on commit 5d3511f

Please sign in to comment.