• luabind 导出string问题


    luabind导出字符串 不能导出char* 会有问题 应该是字符串连接的时候出错了

    static _TCHAR* pRetChar = new _TCHAR[10];
    memcpy(pRetChar,szName,10);
    return NetE::wtoutf8(pRetChar);   //WCharToMultiByte 为什么就不可以那?

    std::string wtoutf8 ( const wchar_t *wstr )
    {
    std::string str = "";
    if ( NULL == wstr ) return str;

    size_t wlen = wcslen(wstr);
    if ( wlen >= 1020 ) wlen = 1020; // 防止溢出

    unsigned char obuff[1024] = "";

    unsigned char *t = obuff;
    wchar_t *us = const_cast<wchar_t*>(wstr);

    int UNICODE_CHARS = (sizeof(wchar_t) >= 4 ? 0x110000 : 0x10000);

    for (size_t i = 0; i < wlen; i++)
    {
    wchar_t mychar = us[i];
    if (mychar <= 0x7F)
    {
    *t++ = mychar; /* 7 sig bits */
    }
    else if (mychar <= 0x7FF)
    { /* 11 sig bits */
    *t++ = 0xC0 | (unsigned char) (mychar >> 6); /* upper 5 bits */
    *t++ = 0x80 | (unsigned char) (mychar & 0x3F); /* lower 6 bits */
    }
    else if (mychar <= 0xFFFF)
    { /* 16 sig bits */
    *t++ = 0xE0 | (unsigned char) (mychar >> 12); /* upper 4 bits */
    *t++ = 0x80 | (unsigned char) ((mychar >> 6) & 0x3F); /* next 6 bits */
    *t++ = 0x80 | (unsigned char) (mychar & 0x3F); /* lowest 6 bits */
    }
    else if (mychar < UNICODE_CHARS)
    { /* 21 sig bits */
    *t++ = 0xF0 | (unsigned char) ((mychar >> 18) & 0x07); /* upper 3 bits */
    *t++ = 0x80 | (unsigned char) ((mychar >> 12) & 0x3F); /* next 6 bits */
    *t++ = 0x80 | (unsigned char) ((mychar >> 6) & 0x3F); /* next 6 bits */
    *t++ = 0x80 | (unsigned char) (mychar & 0x3F); /* lowest 6 bits */
    }
    }
    str = (char*)obuff;
    return str;
    }

  • 相关阅读:
    Alpha 冲刺报告6
    课堂小测(同学录)
    Alpha 冲刺报告5
    alphe4
    Alpha 冲刺报告3
    软件工程实践2017第二次作业
    软件工程实践2017第一次作业
    面向对象程序设计 第六次作业
    1025 反转链表(待完善)
    面向对象程序设计 第五次作业
  • 原文地址:https://www.cnblogs.com/rexzhao/p/4598182.html
Copyright © 2020-2023  润新知