summaryrefslogtreecommitdiff
path: root/include/al
diff options
context:
space:
mode:
Diffstat (limited to 'include/al')
-rw-r--r--include/al/wstr.h30
1 files changed, 14 insertions, 16 deletions
diff --git a/include/al/wstr.h b/include/al/wstr.h
index 70dccff..4c37453 100644
--- a/include/al/wstr.h
+++ b/include/al/wstr.h
@@ -81,14 +81,14 @@ static inline bool al_wstr_from_cstr(wstr *w, char *c)
#ifdef AL_HAVE_WIDE_STRING
mbstate_t mbstate = { 0 };
size_t length = mbsrtowcs(NULL, (const char **)&c, 0, &mbstate);
- if (length == (size_t)-1) {
- return false;
+ bool success = length != (size_t)-1;
+ if (success) {
+ al_wstr_sized(w, (u32)(length + 1));
+ w->length = (u32)mbsrtowcs(w->data, (const char **)&c, length, &mbstate);
+ al_assert(w->length == (u32)length);
+ w->data[w->length] = L'\0';
}
- al_wstr_sized(w, (u32)(length + 1));
- w->length = (u32)mbsrtowcs(w->data, (const char **)&c, length, &mbstate);
- al_assert(w->length == (u32)length);
- w->data[w->length] = L'\0';
- return true;
+ return success;
#else
(void)c;
(void)w;
@@ -103,10 +103,8 @@ static inline void al_wstr_from_str(wstr *w, str *s)
al_free(c_str);
}
-// This is horrible.
static inline bool al_str_from_wstr(str *s, wstr *w)
{
- // This is broken on Windows. Locale issue?
#ifdef AL_HAVE_WIDE_STRING
wstr copy;
// We have to make a copy in case w->length is less than the
@@ -115,15 +113,15 @@ static inline bool al_str_from_wstr(str *s, wstr *w)
wchar_t *copy_data = copy.data;
mbstate_t mbstate = { 0 };
size_t length = wcsrtombs(NULL, (const wchar_t **)&copy_data, 0, &mbstate);
- if (length == (size_t)-1) {
- return false;
+ bool success = length != (size_t)-1;
+ if (success) {
+ al_str_sized(s, (u32)length);
+ // Excludes the null terminator.
+ s->length = (u32)wcsrtombs(s->data, (const wchar_t **)&copy_data, length, &mbstate);
+ al_assert(s->length == (u32)length);
}
- al_str_sized(s, (u32)length);
- // Excludes the null terminator.
- s->length = (u32)wcsrtombs(s->data, (const wchar_t **)&copy_data, length, &mbstate);
- al_assert(s->length == (u32)length);
al_wstr_free(&copy);
- return true;
+ return success;
#else
(void)s;
(void)w;