decodeunicode函式
string decodeunicode
(string thestring)
} % 256));
string value2 =
codepointtoutf8
(value)
; outbuffer.
insert
(outbuffer.
end(
), value2.
begin()
, value2.
end())
;}else
}else
outbuffer.
push_back((
char
)achar);}
//return outbuffer.tostring();
string result
(outbuffer.
begin()
, outbuffer.
end())
;return result;
}
codepointtoutf8()
/// converts a unicode code-point to utf-8.
static
inline jsoncpp_string codepointtoutf8
(unsigned
int cp)
else
if(cp <=
0x7ff
)else
if(cp <=
0xffff);
char dest[5]
=;src[0]
= static_cast
(cp)
; std:
:string curlocale =
setlocale
(lc_all,
null);
setlocale
(lc_all,
"chs");
wcstombs_s
(null
, dest,
5, src,2)
; result = dest;
setlocale
(lc_all, curlocale.
c_str()
);}else
}else
if(cp <=
0x10ffff
)return result;
}
decodeunicode()函式將\u5e73的後四位數字由十六進製制轉為十進位制存放在value(unsigned int型別)後呼叫codepointtoutf8(),codepointtoutf8()函式將value解析為string型別返回
另外,若呼叫result[「result」][1][「root」].asstring()會出現中文繁體亂碼,這是因為jsoncpp會自動用utf-8的方式對中文編碼,需要用utf8togb()函式轉為gbk的形式再列印。
參考部落格
//unicodetochinese
//codepointtoutf8()
// utf8togb()
//unicodetochinese()忘記出處在哪兒了,找到了補上 -_-ll
小白的第一篇部落格,如有不足望指正^_^
完整**如下:
#include
#include
#include
#include
#include
"image_classify.h"
#include
using namespace std;
/// converts a unicode code-point to utf-8.
static
inline jsoncpp_string codepointtoutf8
(unsigned
int cp)
else
if(cp <=
0x7ff
)else
if(cp <=
0xffff);
char dest[5]
=;src[0]
= static_cast
(cp)
; std:
:string curlocale =
setlocale
(lc_all,
null);
setlocale
(lc_all,
"chs");
wcstombs_s
(null
, dest,
5, src,2)
; result = dest;
setlocale
(lc_all, curlocale.
c_str()
);}else
}else
if(cp <=
0x10ffff
)return result;
}string decodeunicode
(string thestring)
} % 256));
string value2 =
codepointtoutf8
(value)
; outbuffer.
insert
(outbuffer.
end(
), value2.
begin()
, value2.
end())
;}else
}else
outbuffer.
push_back((
char
)achar);}
//return outbuffer.tostring();
string result
(outbuffer.
begin()
, outbuffer.
end())
;return result;
}//unicodetochinese()這個函式**裡沒有用到,可將'\u2132'轉為對於的cstring中文
bool unicodetochinese
(string str, cstring& cstr)
int nvalue =0;
wchar* pwchar;
wchar_t* szhex;
char strchar[6]
=;for(i =
0; i < len; i++
) uses_conversion;
szhex =
a2w(strchar)
;strtointexw
(szhex, stif_support_hex,
&nvalue)
; pwchar =
(wchar*
)&nvalue;
cstr = cstr + pwchar;}}
return true;
}string utf8togb
(const
char
* str)
intmain()
GPT轉MBR怎麼轉?
如果本身電腦有兩個硬碟,可以直接在win7 win8系統下進行gpt轉mbr 如果只有乙個硬碟,那可以進入winpe裡面進行gpt磁碟轉mbr磁碟。注 gpt轉mbr必須得清空硬碟上的所有資料!請注意儲存資料!1 在win7 win8系統下,按快捷鍵 win r 彈出執行視窗,然後輸入 cmd wi...
GPT轉MBR怎麼轉?
如果本身電腦有兩個硬碟,可以直接在win7 win8系統下進行gpt轉mbr 如果只有乙個硬碟,那可以進入winpe裡面進行gpt磁碟轉mbr磁碟。注 gpt轉mbr必須得清空硬碟上的所有資料!請注意儲存資料!1 在win7 win8系統下,按快捷鍵 win r 彈出執行視窗,然後輸入 cmd wi...
java後台轉json 轉物件 轉list集合
前台資料傳遞到後台轉json 1 普通格式轉換成物件 string data request.getparameter data 單資料的時候轉換方式 jsonobject json jsonobject.fromobject data tree tree tree jsonobject.tobea...