mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-06-24 13:01:22 +00:00
Added support for printing wide strings using "%ls" syntax
(cherry picked from commit 128ca7016018178c0c3231db7db2005dbf234068)
This commit is contained in:
parent
9dea06f5b5
commit
7308325559
|
@ -1514,6 +1514,19 @@ static size_t SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, c
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t SDL_PrintStringW(char *text, size_t maxlen, SDL_FormatInfo *info, const wchar_t *wide_string)
|
||||||
|
{
|
||||||
|
size_t length = 0;
|
||||||
|
if (wide_string) {
|
||||||
|
char *string = SDL_iconv_string("UTF-8", "WCHAR_T", (char *)(wide_string), (SDL_wcslen(wide_string) + 1) * sizeof(*wide_string));
|
||||||
|
length = SDL_PrintString(TEXT_AND_LEN_ARGS, info, string);
|
||||||
|
SDL_free(string);
|
||||||
|
} else {
|
||||||
|
length = SDL_PrintString(TEXT_AND_LEN_ARGS, info, NULL);
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
static void SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
|
static void SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
|
||||||
{ /* left-pad num with zeroes. */
|
{ /* left-pad num with zeroes. */
|
||||||
size_t sz, pad, have_sign;
|
size_t sz, pad, have_sign;
|
||||||
|
@ -1831,23 +1844,17 @@ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *f
|
||||||
done = SDL_TRUE;
|
done = SDL_TRUE;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
{
|
|
||||||
/* In practice this is used on Windows for WCHAR strings */
|
|
||||||
wchar_t *wide_arg = va_arg(ap, wchar_t *);
|
|
||||||
if (wide_arg) {
|
|
||||||
char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg) + 1) * sizeof(*wide_arg));
|
|
||||||
info.pad_zeroes = SDL_FALSE;
|
info.pad_zeroes = SDL_FALSE;
|
||||||
length += SDL_PrintString(TEXT_AND_LEN_ARGS, &info, arg);
|
length += SDL_PrintStringW(TEXT_AND_LEN_ARGS, &info, va_arg(ap, wchar_t *));
|
||||||
SDL_free(arg);
|
|
||||||
} else {
|
|
||||||
info.pad_zeroes = SDL_FALSE;
|
|
||||||
length += SDL_PrintString(TEXT_AND_LEN_ARGS, &info, NULL);
|
|
||||||
}
|
|
||||||
done = SDL_TRUE;
|
done = SDL_TRUE;
|
||||||
} break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
info.pad_zeroes = SDL_FALSE;
|
info.pad_zeroes = SDL_FALSE;
|
||||||
|
if (inttype > DO_INT) {
|
||||||
|
length += SDL_PrintStringW(TEXT_AND_LEN_ARGS, &info, va_arg(ap, wchar_t *));
|
||||||
|
} else {
|
||||||
length += SDL_PrintString(TEXT_AND_LEN_ARGS, &info, va_arg(ap, char *));
|
length += SDL_PrintString(TEXT_AND_LEN_ARGS, &info, va_arg(ap, char *));
|
||||||
|
}
|
||||||
done = SDL_TRUE;
|
done = SDL_TRUE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -62,6 +62,18 @@ int stdlib_snprintf(void *arg)
|
||||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%S", L"foo");
|
||||||
|
expected = "foo";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%S\", \"foo\")");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%ls", L"foo");
|
||||||
|
expected = "foo";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%ls\", \"foo\")");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||||
|
|
||||||
result = SDL_snprintf(text, 2, "%s", "foo");
|
result = SDL_snprintf(text, 2, "%s", "foo");
|
||||||
expected = "f";
|
expected = "f";
|
||||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
|
||||||
|
|
Loading…
Reference in a new issue