ui/winui/util.cpp

Fri, 06 Oct 2023 19:38:10 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 06 Oct 2023 19:38:10 +0200
branch
newapi
changeset 204
4a258d47f964
parent 192
bcacd00ea955
child 205
b1ac0dd1d38b
permissions
-rw-r--r--

add breadcrumb bar



#include "util.h"

#include <stdlib.h>

#include <Windows.h>


wchar_t* str2wstr(const char* str, int* newlen) {
    size_t len = strlen(str);


    wchar_t* wstr = (wchar_t*)calloc(len + 1, sizeof(wchar_t));
    int wlen = MultiByteToWideChar(
        CP_UTF8,
        0,
        str,
        len,
        wstr,
        len + 1
    );
    if (newlen) {
        *newlen = wlen;
    }
    wstr[wlen] = 0;

    return wstr;
}

char* wchar2utf8(const wchar_t* wstr, size_t wlen) {
    size_t maxlen = wlen * 4;
    char* ret = (char*)malloc(maxlen + 1);
    int ret_len = WideCharToMultiByte(
        CP_UTF8,
        0,
        wstr,
        wlen,
        ret,
        maxlen,
        NULL,
        NULL);
    ret[ret_len] = 0;
    return ret;
}

mercurial