[v2 PATCH 1/4] shcore: Implement a bunch of string conversion functions.

Dmitry Timoshkov dmitry at baikal.ru
Thu Nov 29 00:10:30 CST 2018


Nikolay Sivov <nsivov at codeweavers.com> wrote:

> +DWORD WINAPI SHAnsiToAnsi(const char *src, char *dest, int dest_len)
> +{
> +    DWORD ret = 0;
> +
> +    TRACE("(%s, %p, %d)\n", debugstr_a(src), dest, dest_len);
> +
> +    if (!src || !dest || dest_len <= 0)
> +        return 0;
> +
> +    while (dest_len > 1 && *src)
> +    {
> +        dest_len--;
> +        *dest++ = *src++;
> +        ret++;
> +    }
> +
> +    if (dest_len)
> +    {
> +        *dest = 0;
> +        ret++;
> +    }
> +
> +    return ret;
> +}

Still the same duplication without a reasonable explanation.

> +DWORD WINAPI SHUnicodeToAnsi(const WCHAR *src, char *dest, int dest_len)
> +{
> +    int required = 1;
> +
> +    TRACE("(%s, %p, %d)\n", debugstr_w(src), dest, dest_len);
> +
> +    if (!dest || !dest_len)
> +        return 0;
> +
> +    if (src)
> +    {
> +        required = WideCharToMultiByte(CP_ACP, 0, src, -1, NULL, 0, NULL, NULL);
> +        WideCharToMultiByte(CP_ACP, 0, src, -1, dest, dest_len, NULL, NULL);

It should be possible to avoid doing the conversion twice.

Same comments apply for remaining implementations.

-- 
Dmitry.



More information about the wine-devel mailing list