Merge pull request #12107 from keymanapp/chore/common/remove_codecvt

chore(common): replace codecvt in module u16 🐸
This commit is contained in:
SabineSIL 2024-08-13 21:18:05 +02:00 committed by GitHub
commit 777bf2e1cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 325 additions and 183 deletions

View file

@ -580,7 +580,7 @@ KMX_BOOL ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) {
//swprintf(tstr, "%d", fk->currentGroup);
/* Record a system store for the line number of the begin statement */
//wcscpy(tstr, DEBUGSTORE_MATCH);
u16sprintf(tstr, _countof(tstr), L"%ls%d ", u16fmt(DEBUGSTORE_MATCH).c_str(), (int) fk->currentGroup);
u16sprintf(tstr, _countof(tstr), L"%ls%d ", DEBUGSTORE_MATCH_L, (int) fk->currentGroup);
u16ncat(tstr, gp->szName, _countof(tstr));
AddDebugStore(fk, tstr);
@ -619,7 +619,7 @@ KMX_BOOL ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) {
{
KMX_WCHAR tstr[128];
/* Record a system store for the line number of the begin statement */
u16sprintf(tstr, _countof(tstr), L"%ls%d ", u16fmt(DEBUGSTORE_NOMATCH).c_str(), (int) fk->currentGroup);
u16sprintf(tstr, _countof(tstr), L"%ls%d ", DEBUGSTORE_NOMATCH_L, (int) fk->currentGroup);
u16ncat(tstr, gp->szName, _countof(tstr));
AddDebugStore(fk, tstr);
}
@ -683,7 +683,7 @@ KMX_BOOL ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p)
{
KMX_WCHAR tstr[128];
/* Record a system store for the line number of the begin statement */
u16sprintf(tstr, _countof(tstr), L"%ls%d ", u16fmt(DEBUGSTORE_GROUP).c_str(), fk->cxGroupArray - 1);
u16sprintf(tstr, _countof(tstr), L"%ls%d ", DEBUGSTORE_GROUP_L, fk->cxGroupArray - 1);
u16ncat(tstr, gp->szName, _countof(tstr));
AddDebugStore(fk, tstr);
}
@ -3761,7 +3761,7 @@ void kmcmp::RecordDeadkeyNames(PFILE_KEYBOARD fk)
KMX_DWORD i;
for (i = 0; i < fk->cxDeadKeyArray; i++)
{
u16sprintf(buf, _countof(buf), L"%ls%d ", u16fmt(DEBUGSTORE_DEADKEY).c_str(), (int)i);
u16sprintf(buf, _countof(buf), L"%ls%d ", DEBUGSTORE_DEADKEY_L, (int)i);
u16ncat(buf, fk->dpDeadKeyArray[i].szName, _countof(buf));
AddDebugStore(fk, buf);

View file

@ -18,7 +18,7 @@ namespace kmcmp {
std::wstringstream key;
key << kp->Key << "," << kp->ShiftFlags << ",";
if (kp->dpContext) {
std::wstring Context_ws = u16fmt((const PKMX_WCHAR) kp->dpContext);
std::wstring Context_ws = wstring_from_u16string((const PKMX_WCHAR) kp->dpContext);
key << Context_ws;
}
return key.str();

View file

@ -5,16 +5,16 @@
#define DEBUGSTORE_BEGIN u"B"
#define DEBUGSTORE_BEGIN_C u'B'
#define DEBUGSTORE_MATCH u"M"
#define DEBUGSTORE_MATCH_C u'M'
#define DEBUGSTORE_MATCH_U u"M"
#define DEBUGSTORE_MATCH_L L"M"
#define DEBUGSTORE_NOMATCH u"N"
#define DEBUGSTORE_NOMATCH_C u'N'
#define DEBUGSTORE_NOMATCH_U u"M"
#define DEBUGSTORE_NOMATCH_L L"M"
#define DEBUGSTORE_GROUP u"G"
#define DEBUGSTORE_GROUP_C u'G'
#define DEBUGSTORE_GROUP_U u"G"
#define DEBUGSTORE_GROUP_L L"G"
#define DEBUGSTORE_DEADKEY u"D"
#define DEBUGSTORE_DEADKEY_C u'D'
#define DEBUGSTORE_DEADKEY_U u"D"
#define DEBUGSTORE_DEADKEY_L L"D"
#endif /* DEBUGSTORE_H */

View file

@ -10,150 +10,201 @@
#include <locale>
#include <stdarg.h>
#include <algorithm>
#include "utfcodec.hpp"
//String <- wstring
std::string string_from_wstring(std::wstring const str) {
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
return converter.to_bytes(str);
/** string <- wstring
* @brief Obtain a std::string from a std::wstring
* @param wstr the std::wstring to be converted
* @return a std::string
*/
std::string string_from_wstring(std::wstring const wstr) {
return convert<wchar_t, char>((const std::wstring)wstr);
}
//wstring <- string
/** wstring <- string
* @brief Obtain a std::wstring from a std::string
* @param str the std::string to be converted
* @return a std::wstring
*/
std::wstring wstring_from_string(std::string const str) {
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
return converter.from_bytes(str);
return convert<char, wchar_t>((const std::string)str);
}
//u16String <- string
/** u16string <- string
* @brief Obtain a std::u16string from a std::string
* @param str the std::string to be converted
* @return a std::u16string
*/
std::u16string u16string_from_string(std::string const str) {
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
return converter.from_bytes(str);
return convert<char, char16_t>((const std::string)str);
}
//string <- u16string
std::string string_from_u16string(std::u16string const str) {
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
return converter.to_bytes(str);
/** string <- u16string
* @brief Obtain a std::string from a std::u16string
* @param str16 the std::u16string to be converted
* @return a std::string
*/
std::string string_from_u16string(std::u16string const str16) {
return convert<char16_t, char>((const std::u16string)str16);
}
// often used with c_str() e.g. u16fmt( DEBUGSTORE_MATCH).c_str()
// UTF16 (= const char16_t*) -> UTF8 (= std::string) -> UTF16 ( = std::wstring 16 bit)
std::wstring u16fmt(const KMX_WCHAR * str) {
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> convert_wstring;
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
// UTF16 (= const char16_t*) -> UTF8 (= std::string) -> UTF16 ( = std::wstring 16 bit)
std::string utf8str = convert.to_bytes(str); // UTF16 (= const char16_t*) -> UTF8 (= std::string)
std::wstring wstr = convert_wstring.from_bytes(utf8str); // UTF8 (= std::string) -> UTF16 ( = std::wstring 16 bit)
return wstr;
/** wstring <- u16string
* @brief Obtain a std::wstring from a std::u16string
* @param str16 the std::u16string to be converted
* @return a std::wstring
*/
std::wstring wstring_from_u16string(std::u16string const str16) {
return convert<char16_t, wchar_t>((const std::u16string)str16);
}
void u16sprintf(KMX_WCHAR * dst, const size_t sz, const wchar_t* fmt, ...) {
// UTF16 (=const wchar_t*) -> -> std::string -> std::u16string -> UTF16 ( = char16_t*)
wchar_t* wbuf = new wchar_t[sz];
va_list args;
va_start(args, fmt);
vswprintf(wbuf, sz, fmt, args);
va_end(args);
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> convert_wstring;
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
// UTF16 (=const wchar_t*) -> -> std::string -> std::u16string -> UTF16 ( = char16_t*)
std::string utf8str = convert_wstring.to_bytes(wbuf); // UTF16 ( = const wchar_t*) -> std::string
std::u16string u16str = convert.from_bytes(utf8str); // std::string -> std::u16string
u16ncpy(dst, u16str.c_str(), sz); // std::u16string.c_str() -> char16_t*
delete[] wbuf;
/** u16string <- wstring
* @brief Obtain a std::u16string from a std::wstring
* @param wstr the std::wstring to be converted
* @return a std::u16string
*/
std::u16string u16string_from_wstring(std::wstring const wstr) {
return convert<wchar_t, char16_t>((const std::wstring)wstr);
}
std::wstring convert_pchar16T_To_wstr(KMX_WCHAR *Name){
// convert char16_t* -> std::u16string -> std::string -> std::wstring
// char16_t* -> std::u16string
std::u16string u16str(Name);
// std::u16string -> std::string
std::string stri = string_from_u16string(u16str);
// std::string -> std::wstring
std::wstring wstr = wstring_from_string(stri);
return wstr;
}
/**
* @brief Convert pointer to wchar_t to pointer to char16_t and copy sz elements into dst
* @param dst destination
* @param sz nr of characters to be copied
* @param fmt source to convert and copy
*/
void u16sprintf(KMX_WCHAR* dst, const size_t sz, const wchar_t* fmt, ...) {
wchar_t* wbuf = new wchar_t[sz];
va_list args;
va_start(args, fmt);
vswprintf(wbuf, sz, fmt, args);
va_end(args);
long int u16tol(const KMX_WCHAR* str, KMX_WCHAR** endptr, int base)
{
std::u16string u16str = u16string_from_wstring(wbuf);
u16ncpy(dst, u16str.c_str(), sz);
delete[] wbuf;
}
/**
* @brief Convert u16string to long integer
* @param str u16string beginning with the representation of an integral number.
* @param endptr Reference to the next character in str
* @param base Numerical base (radix) that determines the valid characters and their interpretation
* @return a long
*/
long int u16tol(const KMX_WCHAR* str, KMX_WCHAR** endptr, int base) {
auto s = string_from_u16string(str);
char* t;
long int result = strtol(s.c_str(), &t, base);
if (endptr != nullptr) *endptr = (KMX_WCHAR*)str + (t - s.c_str());
if (endptr != nullptr)
*endptr = (KMX_WCHAR*)str + (t - s.c_str());
return result;
}
std::string toHex(int num1) {
if (num1 == 0)
return "0";
int num = num1;
std::string s = "";
while (num) {
int temp = num % 16;
if (temp <= 9)
s += (48 + temp);
else
s += (87 + temp);
num = num / 16;
}
std::reverse(s.begin(), s.end());
return s;
if (num1 == 0)
return "0";
int num = num1;
std::string s = "";
while (num) {
int temp = num % 16;
if (temp <= 9)
s += (48 + temp);
else
s += (87 + temp);
num = num / 16;
}
std::reverse(s.begin(), s.end());
return s;
}
const KMX_WCHAR * u16ncat(KMX_WCHAR *dst, const KMX_WCHAR *src, size_t max) {
/**
* @brief Append max characters from u16string
* @param dst Pointer to the destination array
* @param src u16string to be appended
* @param max Maximum number of characters to be appended.
* @return Pointer to dst
*/
const KMX_WCHAR* u16ncat(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max) {
KMX_WCHAR* o = dst;
dst = (KMX_WCHAR*) u16chr(dst, 0);
//max -= (dst-o);
dst = (KMX_WCHAR*)u16chr(dst, 0);
// max -= (dst-o);
while (*src && max > 0) {
*dst++ = *src++;
max--;
}
if(max > 0)
*dst = 0;
if (max > 0)
*dst = 0;
return o;
}
const KMX_WCHAR* u16rchr_slash(KMX_WCHAR const* Name)
{
/**
* @brief Find last '/' or '\\' in an array of char16_t
* @param name Pointer to the source
* @return Pointer to the last slash/backslash
*/
const KMX_WCHAR* u16rchr_slash(KMX_WCHAR const* name) {
const KMX_WCHAR* cp = NULL;
cp = u16rchr(Name, '\\');
cp = u16rchr(name, '\\');
if (cp == NULL)
cp = u16rchr(Name, '/');
cp = u16rchr(name, '/');
return cp;
}
KMX_CHAR* strrchr_slash(KMX_CHAR* Name)
{
/**
* @brief Find last '/' or '\\' in an array of char
* @param name Pointer to the source
* @return Pointer to the last slash/backslash
*/
KMX_CHAR* strrchr_slash(KMX_CHAR* name) {
KMX_CHAR* cp = NULL;
cp = strrchr(Name, '\\');
cp = strrchr(name, '\\');
if (cp == NULL)
cp = strrchr(Name, '/');
cp = strrchr(name, '/');
return cp;
}
// u16rchr returns last occurence of ch in p; It returns NULL if ch = '\0' and NULL if ch is not found
/**
* @brief Locate last occurrence of character in u16string
* @param p Pointer to the source
* @param ch The character to be found
* @return A pointer to the last occurrence of character in u16str
*/
const KMX_WCHAR* u16rchr(const KMX_WCHAR* p, KMX_WCHAR ch) {
const KMX_WCHAR* p_end = p + u16len(p) - 1;
if (ch == '\0') return p_end + 1;
while (p_end >= p) {
if (*p_end == ch) return p_end;
p_end--;
}
return NULL;
if (ch == '\0')
return p_end + 1;
while (p_end >= p) {
if (*p_end == ch)
return p_end;
p_end--;
}
return NULL;
}
const KMX_WCHAR * u16chr(const KMX_WCHAR *p, KMX_WCHAR ch) {
/**
* @brief Locate first occurrence of character in u16string
* @param p Pointer to the source
* @param ch The character to be found
* @return A pointer to the first occurrence of character in u16str
*/
const KMX_WCHAR* u16chr(const KMX_WCHAR* p, KMX_WCHAR ch) {
while (*p) {
if (*p == ch) return p;
if (*p == ch)
return p;
p++;
}
return ch == 0 ? p : NULL;
}
const KMX_WCHAR * u16cpy(KMX_WCHAR *dst, const KMX_WCHAR *src) {
KMX_WCHAR *o = dst;
/**
* @brief Copy the u16string pointed to by scr into the array pointed to by dst
* @param dst Pointer to the destination
* @param src Pointer to the source to be copied
* @return Pointer to dst
*/
const KMX_WCHAR* u16cpy(KMX_WCHAR* dst, const KMX_WCHAR* src) {
KMX_WCHAR* o = dst;
while (*src) {
*dst++ = *src++;
}
@ -161,19 +212,31 @@ const KMX_WCHAR * u16cpy(KMX_WCHAR *dst, const KMX_WCHAR *src) {
return o;
}
const KMX_WCHAR * u16ncpy(KMX_WCHAR *dst, const KMX_WCHAR *src, size_t max) {
KMX_WCHAR *o = dst;
/**
* @brief Copy max characters of the u16string pointed to by src into the array pointed by dst
* @param dst Pointer to the destination
* @param src Pointer to the source to be copied
* @param max Maximum number of characters to be copied
* @return Pointer to dst
*/
const KMX_WCHAR* u16ncpy(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max) {
KMX_WCHAR* o = dst;
while (*src && max > 0) {
*dst++ = *src++;
max--;
}
if(max > 0) {
if (max > 0) {
*dst = 0;
}
return o;
}
size_t u16len(const KMX_WCHAR *p) {
/**
* @brief Return the length of the u16string str
* @param p Pointer to the source
* @return The length of u16string
*/
size_t u16len(const KMX_WCHAR* p) {
int i = 0;
while (*p) {
p++;
@ -182,18 +245,35 @@ size_t u16len(const KMX_WCHAR *p) {
return i;
}
int u16cmp(const KMX_WCHAR *p, const KMX_WCHAR *q) {
/**
* @brief Compare two u16strings
* @param p Pointer one u16string
* @param q Pointer another u16string
* @return 0 if strings are equal
* ! = 0 if unequal
*/
int u16cmp(const KMX_WCHAR* p, const KMX_WCHAR* q) {
while (*p && *q) {
if (*p != *q) return *p - *q;
if (*p != *q)
return *p - *q;
p++;
q++;
}
return *p - *q;
}
int u16nicmp(const KMX_WCHAR *p, const KMX_WCHAR *q, size_t count) {
/**
* @brief Case insensitive comparison of up to count characters in two strings
* @param p Pointer one u16string
* @param q Pointer another u16string
* @param count Maximum number of characters to compare
* @return 0 if strings are equal
* ! = 0 if unequal
*/
int u16nicmp(const KMX_WCHAR* p, const KMX_WCHAR* q, size_t count) {
while (*p && *q && count) {
if (toupper(*p) != toupper(*q)) return *p - *q;
if (toupper(*p) != toupper(*q))
return *p - *q;
p++;
q++;
count--;
@ -203,18 +283,35 @@ int u16nicmp(const KMX_WCHAR *p, const KMX_WCHAR *q, size_t count) {
return 0;
}
int u16icmp(const KMX_WCHAR *p, const KMX_WCHAR *q) {
/**
* @brief Case insensitive comparison of two strings
* @param p Pointer one u16string
* @param q Pointer another u16string
* @return 0 if strings are equal
* ! = 0 if unequal
*/
int u16icmp(const KMX_WCHAR* p, const KMX_WCHAR* q) {
while (*p && *q) {
if (toupper(*p) != toupper(*q)) return *p - *q;
if (toupper(*p) != toupper(*q))
return *p - *q;
p++;
q++;
}
return *p - *q;
}
int u16ncmp(const KMX_WCHAR *p, const KMX_WCHAR *q, size_t count) {
/**
* @brief Comparison of up to count characters in two strings
* @param p Pointer one u16string
* @param q Pointer another u16string
* @param count Maximum number of characters to compare
* @return 0 if strings are equal
* ! = 0 if unequal
*/
int u16ncmp(const KMX_WCHAR* p, const KMX_WCHAR* q, size_t count) {
while (*p && *q && count) {
if (*p != *q) return *p - *q;
if (*p != *q)
return *p - *q;
p++;
q++;
count--;
@ -224,70 +321,73 @@ int u16ncmp(const KMX_WCHAR *p, const KMX_WCHAR *q, size_t count) {
return 0;
}
KMX_WCHAR * u16tok(KMX_WCHAR *p, const KMX_WCHAR ch, KMX_WCHAR **ctx) {
/**
* @brief Split u16string into tokens
* @param p Pointer to u16string to parse.
* @param ch the delimiter character
* @param ctx the remaining string after the first delimiter
* @return Pointer to the first token in p
*/
KMX_WCHAR* u16tok(KMX_WCHAR* p, const KMX_WCHAR ch, KMX_WCHAR** ctx) {
if (!p) {
p = *ctx;
if (!p) return NULL;
if (!p)
return NULL;
}
KMX_WCHAR *q = p;
KMX_WCHAR* q = p;
while (*q && *q != ch) {
q++;
}
if (*q) {
*q = 0;
q++;
while (*q == ch) q++;
while (*q == ch)
q++;
*ctx = q;
}
else {
} else {
*ctx = NULL;
}
return *p ? p : NULL;
}
KMX_WCHAR * u16tok(KMX_WCHAR* p, const KMX_WCHAR* delim, KMX_WCHAR** ctx) {
if (!p) {
p = *ctx;
if (!p) return NULL;
}
/**
* @brief Split u16string into tokens
* @param p Pointer to u16string to parse.
* @param delimiters an array of delimiter characters
* @param ctx the remaining string after the first delimiter
* @return Pointer to the first token in p
*/
KMX_WCHAR* u16tok(KMX_WCHAR* p, const KMX_WCHAR* delimiters, KMX_WCHAR** ctx) {
if (!p) {
p = *ctx;
if (!p)
return NULL;
}
KMX_WCHAR * q = p;
while (*q && !u16chr(delim, *q)) {
q++;
}
if (*q) {
*q = 0;
q++;
while (*q && u16chr(delim, *q)) q++;
*ctx = q;
}
else {
*ctx = NULL;
}
KMX_WCHAR* q = p;
while (*q && !u16chr(delimiters, *q)) {
q++;
}
if (*q) {
*q = 0;
q++;
while (*q && u16chr(delimiters, *q))
q++;
*ctx = q;
} else {
*ctx = NULL;
}
return *p ? p : NULL;
}
double u16tof( KMX_WCHAR* str)
{
double val = 0;
int offsetdot=0;
char digit;
PKMX_WCHAR q = (PKMX_WCHAR)u16chr(str, '.');
size_t pos_dot = (q-str < 0) ? u16len(str) : q-str;
for (size_t i = 0; i < u16len(str); i++)
{
digit = static_cast<char>(towupper(*str));
if (i > pos_dot - 1)
offsetdot = 1;
if (digit != '.')
val =val+ ((int(digit)) - 48) * pow(10, (pos_dot - 1- i + offsetdot));
str++;
}
return val;
/**
* @brief Convert a u16string to a double
* @param str Pointer to u16string
* @return double value equivalent to the string
*/
double u16tof(KMX_WCHAR* str16) {
char* pEnd;
std::string str = string_from_u16string(str16);
return strtof(str.c_str(), &pEnd);
}

View file

@ -7,32 +7,73 @@
#include <cstring>
#include "kmcompx.h"
std::string string_from_wstring(std::wstring const str);
/** @brief Obtain a std::string from a std::wstring */
std::string string_from_wstring(std::wstring const wstr);
/** @brief Obtain a std::wstring from a std::string */
std::wstring wstring_from_string(std::string const str);
/** @brief Obtain a std::u16string from a std::string */
std::u16string u16string_from_string(std::string const str);
std::string string_from_u16string(std::u16string const str);
std::wstring u16fmt(const KMX_WCHAR * str);
void u16sprintf(KMX_WCHAR * dst, const size_t sz, const wchar_t* fmt, ...) ;
/** @brief Obtain a std::string from a std::u16string */
std::string string_from_u16string(std::u16string const str16);
std::wstring convert_pchar16T_To_wstr(KMX_WCHAR *Name);
/** @brief Obtain a std::wstring from a std::u16string */
std::wstring wstring_from_u16string(std::u16string const str16);
size_t u16len(const KMX_WCHAR *p);
int u16cmp(const KMX_WCHAR *p, const KMX_WCHAR *q);
int u16icmp(const KMX_WCHAR *p, const KMX_WCHAR *q);
int u16ncmp(const KMX_WCHAR *p, const KMX_WCHAR *q, size_t count);
int u16nicmp(const KMX_WCHAR *p, const KMX_WCHAR *q, size_t count) ;
const KMX_WCHAR * u16ncpy(KMX_WCHAR *dst, const KMX_WCHAR *src, size_t max);
const KMX_WCHAR * u16cpy(KMX_WCHAR *dst, const KMX_WCHAR *src);
const KMX_WCHAR * u16rchr(const KMX_WCHAR *p, KMX_WCHAR ch) ;
const KMX_WCHAR * u16chr(const KMX_WCHAR *p, KMX_WCHAR ch) ;
const KMX_WCHAR * u16ncat(KMX_WCHAR *dst, const KMX_WCHAR *src, size_t max);
KMX_WCHAR * u16tok(KMX_WCHAR *p, const KMX_WCHAR ch, KMX_WCHAR **ctx) ;
KMX_WCHAR * u16tok(KMX_WCHAR* p, const KMX_WCHAR* ch, KMX_WCHAR** ctx) ;
long int u16tol(const KMX_WCHAR* str, KMX_WCHAR** endptr, int base) ;
double u16tof( KMX_WCHAR* str);
/** @brief Obtain a std::u16string from a std::wstring */
std::u16string u16string_from_wstring(std::wstring const wstr);
/** @brief Convert pointer to wchar_t to pointer to char16_t and copy sz elements into dst */
void u16sprintf(KMX_WCHAR* dst, const size_t sz, const wchar_t* fmt, ...);
/** @brief Return the length of the u16string str */
size_t u16len(const KMX_WCHAR* p);
/** @brief Compare two u16strings */
int u16cmp(const KMX_WCHAR* p, const KMX_WCHAR* q);
/** @brief Case insensitive comparison of two strings */
int u16icmp(const KMX_WCHAR* p, const KMX_WCHAR* q);
/** @brief Comparison of up to count characters in two strings */
int u16ncmp(const KMX_WCHAR* p, const KMX_WCHAR* q, size_t count);
/** @brief Case insensitive comparison of up to count characters in two strings */
int u16nicmp(const KMX_WCHAR* p, const KMX_WCHAR* q, size_t count);
/** @brief Copy max characters of the u16string pointed to by src into the array pointed to by dst */
const KMX_WCHAR* u16ncpy(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max);
/** @brief Copy the u16string pointed to by src into the array pointed to by dst */
const KMX_WCHAR* u16cpy(KMX_WCHAR* dst, const KMX_WCHAR* src);
/** @brief Locate last occurrence of character in u16string */
const KMX_WCHAR* u16rchr(const KMX_WCHAR* p, KMX_WCHAR ch);
/** @brief Locate first occurrence of character in u16string */
const KMX_WCHAR* u16chr(const KMX_WCHAR* p, KMX_WCHAR ch);
/** @brief Append max characters from u16string */
const KMX_WCHAR* u16ncat(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max);
/** @brief Split u16string into tokens */
KMX_WCHAR* u16tok(KMX_WCHAR* p, const KMX_WCHAR ch, KMX_WCHAR** ctx);
/** @brief Split u16string into tokens */
KMX_WCHAR* u16tok(KMX_WCHAR* p, const KMX_WCHAR* delimiters, KMX_WCHAR** ctx);
/** @brief Convert a u16string to a double */
long int u16tol(const KMX_WCHAR* str, KMX_WCHAR** endptr, int base);
/** @brief Convert a u16string to a double */
double u16tof(KMX_WCHAR* str);
/** @brief find last '/' or '\\' in an array of char */
KMX_CHAR* strrchr_slash(KMX_CHAR* Name);
/** @brief find last '/' or '\\' in an array of char16_t */
const KMX_WCHAR* u16rchr_slash(KMX_WCHAR const* Name);
std::string toHex(int num1);

View file

@ -85,6 +85,7 @@ lib = library('kmcmplib',
'versioning.cpp',
'virtualcharkeys.cpp',
'xstring.cpp',
'../../../../common/cpp/utfcodec.cpp',
'../../../../common/windows/cpp/src/ConvertUTF.c',
'../../../../common/windows/cpp/src/crc32.cpp',
'../../../../common/windows/cpp/src/vkeys.cpp',

View file

@ -132,8 +132,8 @@ FILE* Open_File(const KMX_WCHART* Filename, const KMX_WCHART* mode) {
FILE* Open_File(const KMX_WCHAR* Filename, const KMX_WCHAR* mode) {
#ifdef _MSC_VER
std::wstring cpath = convert_pchar16T_To_wstr((KMX_WCHAR*) Filename);
std::wstring cmode = convert_pchar16T_To_wstr((KMX_WCHAR*) mode);
std::wstring cpath = wstring_from_u16string(Filename);
std::wstring cmode = wstring_from_u16string(mode);
std::replace(cpath.begin(), cpath.end(), '/', '\\');
return _wfsopen(cpath.c_str(), cmode.c_str(), _SH_DENYWR);
#else