diff options
author | Chris Robinson <[email protected]> | 2018-01-13 02:03:13 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-01-13 02:03:13 -0800 |
commit | c9edf7cf7827dbbdbd2d76087a280f6d8aff4126 (patch) | |
tree | 0a2f97c657b6f9e3dda2df2f64ef529e733db3e0 | |
parent | 77910afe577458595a3fccd2487fcb567067be58 (diff) |
Add a string function to copy a wide-char range
-rw-r--r-- | Alc/alstring.h | 1 | ||||
-rw-r--r-- | Alc/helpers.c | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/Alc/alstring.h b/Alc/alstring.h index a7513516..e10811da 100644 --- a/Alc/alstring.h +++ b/Alc/alstring.h @@ -43,6 +43,7 @@ void alstr_append_range(al_string *str, const al_string_char_type *from, const a /* Windows-only methods to deal with WideChar strings. */ void alstr_copy_wcstr(al_string *str, const wchar_t *from); void alstr_append_wcstr(al_string *str, const wchar_t *from); +void alstr_copy_wrange(al_string *str, const wchar_t *from, const wchar_t *to); void alstr_append_wrange(al_string *str, const wchar_t *from, const wchar_t *to); #endif diff --git a/Alc/helpers.c b/Alc/helpers.c index 5d39f3d8..ac0826f2 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -1149,6 +1149,17 @@ void alstr_append_wcstr(al_string *str, const wchar_t *from) } } +void alstr_copy_wrange(al_string *str, const wchar_t *from, const wchar_t *to) +{ + int len; + if((len=WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), NULL, 0, NULL, NULL)) > 0) + { + VECTOR_RESIZE(*str, len, len+1); + WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), &VECTOR_FRONT(*str), len+1, NULL, NULL); + VECTOR_ELEM(*str, len) = 0; + } +} + void alstr_append_wrange(al_string *str, const wchar_t *from, const wchar_t *to) { int len; |