最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

為SQLite3提供一個ANSI到UTF8的互轉(zhuǎn)函數(shù)

 更新時間:2013年12月18日 00:16:13   作者:  
這篇文章主要為大家分享下ANSI與UTF8的互轉(zhuǎn)函數(shù),需要的朋友可以收藏下

在使用Sqlite3時必須要用到的

  使用方法:

  char* src = "...";//待轉(zhuǎn)換的ANSI或UTF8字符串
  char* dst = NULL;//保存由函數(shù)內(nèi)部分配的內(nèi)存指針, 不需要傳入內(nèi)存緩沖區(qū)的

  轉(zhuǎn)換為UTF-8:to_utf8(src, &dst);
  轉(zhuǎn)換為ANSI:to_gb(src, &dst);

  返回值:零 - 失敗, 非零 - 成功.
  注意:如果操作成功, 需要手動釋放函數(shù)內(nèi)部分配的空間:

復(fù)制代碼 代碼如下:

if(dst)
{
    free(dst);
    dst = NULL;
}

代碼:

復(fù)制代碼 代碼如下:

#include <windows.h>
#include <stdio.h>int to_utf8(char* psrc, char** ppdst)
{
    int ret,ret2;
    wchar_t* pws = NULL;
    char* putf = NULL;

    ret = MultiByteToWideChar(CP_ACP, 0, psrc, -1, NULL, 0);
    if(ret<=0){
        *ppdst = NULL;
        return 0;
    }
    pws = (wchar_t*)malloc(ret*2);
    if(!pws){
        *ppdst = NULL;
        return 0;
    }
    MultiByteToWideChar(CP_ACP, 0, psrc, -1, pws, ret);
    ret2 = WideCharToMultiByte(CP_UTF8, 0, pws, -1, NULL, 0, NULL, NULL);
    if(ret2<=0){
        free(pws);
        return 0;
    }
    putf = (char*)malloc(ret2);
    if(!putf){
        free(pws);
        return 0;
    }
    if(WideCharToMultiByte(CP_UTF8, 0, pws, ret, putf, ret2, NULL, NULL)){
        *ppdst = putf;
        free(pws);
        return 1;
    }else{
        free(pws);
        free(putf);
        *ppdst = NULL;
        return 0;
    }
}

int to_gb(char* psrc, char** ppdst)
{
    int ret, ret2;
    wchar_t* pws = NULL;
    char* pgb = NULL;
    ret = MultiByteToWideChar(CP_UTF8, 0, psrc, -1, NULL, 0);
    if(ret<=0){
        *ppdst = NULL;
        return 0;
    }
    pws = (wchar_t*)malloc(ret*2);
    if(!pws){
        *ppdst = NULL;
        return 0;
    }
    MultiByteToWideChar(CP_UTF8, 0, psrc, -1, pws, ret);
    ret2 = WideCharToMultiByte(CP_ACP, 0, pws, -1, NULL, 0, NULL, NULL);
    if(ret2<=0){
        free(pws);
        return 0;
    }
    pgb = (char*)malloc(ret2);
    if(!pgb){
        free(pws);
        *ppdst = NULL;
        return 0;
    }
    if(WideCharToMultiByte(CP_ACP, 0, pws, -1, pgb, ret2, NULL, NULL)){
        *ppdst = pgb;
        free(pws);
        return 1;
    }else{*ppdst = 0;
        free(pgb);
        free(pws);
        return 0;
    }
}

by: 女孩不哭

相關(guān)文章

最新評論

耿马| 元江| 赤城县| 嵩明县| 烟台市| 邵阳县| 郸城县| 沾化县| 梧州市| 东方市| 克拉玛依市| 宝坻区| 民县| 昌吉市| 浑源县| 盐源县| 四平市| 德令哈市| 正定县| 陆良县| 徐州市| 施秉县| 肃宁县| 高雄县| 怀集县| 临沭县| 临澧县| 芜湖县| 车险| 沙河市| 建湖县| 和田县| 蕲春县| 保德县| 木里| 瑞安市| 莎车县| 绥德县| 金沙县| 霍山县| 视频|