亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? utf8.cpp

?? utf8編碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
#include "utf8.h"
#include "stdlib.h" 
#include <stdio.h>
#include <wchar.h>
#include <exception>
#include <assert.h>
#include <string.h>  
#if defined(WIN32)	 
#include <windows.h>
#pragma warning(disable : 4244)		
#endif


namespace dnc{
	class UTF8ConvertError : public std::exception{
	public:
		virtual castr what() const throw(){
			return "UTF8ConvertError";
		}
	};
	class XCharError : public std::exception{
	public:
		XCharError(xchar ch){
			m_ch = ch;
			::sprintf(m_msg,"XCharError:%i",ch);
		}
		virtual castr what() const throw(){
			return m_msg;
		}
	private:
		char m_msg[100];
		xchar m_ch;
	};
	class UTF8FormatError : public std::exception{
	public:
		UTF8FormatError(unsigned long pos,unsigned long  len,byte byte,unsigned long  index){
			m_len = len;
			m_pos = pos;
			m_byte= byte;
			m_index=index;
		}
		UTF8FormatError(unsigned long index){
			m_len = 0;
			m_pos = 0;
			m_byte= 0;
			m_index=index;
		}
	public:
		virtual const char* what() const throw(){
			return "UTF8FormatError";
		}
	private:
		unsigned long  m_len;
		unsigned long  m_pos;
		byte   m_byte;
		unsigned long  m_index;
	};
	
	DNC_DECLARE unsigned int XCharToUTF8(xchar ch,astr utf8){
		unsigned int encodedBytes;
		if(ch <= 127){
			*utf8 = (char)ch;
			encodedBytes = 1;
		}else{
			uchar *chars = (ustr)utf8;
			uchar *outPtr = chars;
			// Figure out how many bytes we need
			
			if (ch < 0x80)
				encodedBytes = 1;
			else if (ch < 0x800)
				encodedBytes = 2;
			else if (ch < 0x10000)
				encodedBytes = 3;
			else if (ch < 0x200000)
				encodedBytes = 4;
			else if (ch < 0x4000000)
				encodedBytes = 5;
			else if (ch <= 0x7FFFFFFF)
				encodedBytes = 6;
			else{
				
				throw XCharError(ch);
			}

			//
			//  And spit out the bytes. We spit them out in reverse order
			//  here, so bump up the output pointer and work down as we go.
			//
			outPtr += encodedBytes;
			switch(encodedBytes){
				case 6 : *--outPtr = byte((ch | 0x80UL) & 0xBFUL);
						ch >>= 6;
				case 5 : *--outPtr = byte((ch | 0x80UL) & 0xBFUL);
						ch >>= 6;
				case 4 : *--outPtr = byte((ch | 0x80UL) & 0xBFUL);
						ch >>= 6;
				case 3 : *--outPtr = byte((ch | 0x80UL) & 0xBFUL);
						ch >>= 6;
				case 2 : *--outPtr = byte((ch | 0x80UL) & 0xBFUL);
						ch >>= 6;
				case 1 : *--outPtr = byte(ch | gFirstByteMark[encodedBytes]);
			}
		}
		return encodedBytes;
	}
	DNC_DECLARE unsigned int UTF8ToXChar(custr utf8,xchar &ch){
		const unsigned char *srcPtr = (const unsigned char*)utf8;
		if (*srcPtr <= 127){
			return *srcPtr;
		}
		unsigned int trailingBytes = gUTFBytes[*srcPtr];

		xchar tmpVal = *srcPtr++;
		tmpVal <<= 6;
		for(unsigned int i=1; i<trailingBytes; i++){
			if((*srcPtr & 0xC0) == 0x80){
				tmpVal += *srcPtr++; 
				tmpVal <<= 6;
			}else throw UTF8FormatError(i,trailingBytes,*srcPtr,0xffffffff);
		}
		if((*srcPtr & 0xC0) == 0x80){
			tmpVal += *srcPtr++;
		}else throw UTF8FormatError(trailingBytes,trailingBytes,*srcPtr,0xffffffff);
		
		tmpVal -= gUTFOffsets[trailingBytes];

		//
		//  If it will fit into a single char, then put it in. Otherwise
		//  encode it as a surrogate pair. If its not valid, use the
		//  replacement char.
		//
		if (tmpVal & 0xFFFF0000){
			// Store the leading surrogate char
			tmpVal -= 0x10000;
		}
		ch = tmpVal;
		return trailingBytes+1;
	}
	DNC_DECLARE xchar utf8_value(custr str){
		unsigned char *srcPtr = (unsigned char*)str;
		if (*srcPtr <= 127){
			return *srcPtr;
		}
		unsigned int trailingBytes = gUTFBytes[*srcPtr];

		xchar tmpVal = *srcPtr++;
		tmpVal <<= 6;
		for(unsigned int i=1; i<trailingBytes; i++){
			if((*srcPtr & 0xC0) == 0x80){
				tmpVal += *srcPtr++; 
				tmpVal <<= 6;
			}else throw UTF8FormatError(i,trailingBytes,*srcPtr,0xffffffff);
		}
		if((*srcPtr & 0xC0) == 0x80){
			tmpVal += *srcPtr++;
		}else throw UTF8FormatError(trailingBytes,trailingBytes,*srcPtr,0xffffffff);
		
		tmpVal -= gUTFOffsets[trailingBytes];

		//
		//  If it will fit into a single char, then put it in. Otherwise
		//  encode it as a surrogate pair. If its not valid, use the
		//  replacement char.
		//
		if (tmpVal & 0xFFFF0000){
			// Store the leading surrogate char
			tmpVal -= 0x10000;
		}
		return tmpVal;
	}

	DNC_DECLARE int utf8_strcmp(castr str1,castr str2,size_t count){
		if(count == -1)
			return ::strcmp((char*)str1,(char*)str2);	
		else{
			unsigned int len1=(unsigned int)strlen((char*)str1);
			unsigned int len2=(unsigned int)strlen((char*)str2);
			unsigned int len = (len1<len2) ? len1 : len2;
			len = (len<count) ? len : count;

			int ret = memcmp(str1,str2,len);
			if(ret == 0){
				if(len1 > len2) ret = 1;
				else if(len1 < len2) ret = -1;
			}
			return ret;
		}
	}
	DNC_DECLARE void utf8_strlen(castr str,unsigned int &size,unsigned int &rawSize,unsigned int count){
		assert(str != NULL);
		rawSize = 0;
		size = 0;
		custr p=(custr)str;
		for(;*p!=0 && rawSize<count;p++){
			if(*p < 0x80 || *p >= 0xE0) size++;
			rawSize++;
		}
	}


	// ---------------------------------------------------------------------------
	//  Local static data
	//
	//  gUTFBytes
	//      A list of counts of trailing bytes for each initial byte in the input.
	//
	//  gUTFByteIndicator
	//      For a UTF8 sequence of n bytes, n>=2, the first byte of the
	//      sequence must contain n 1's followed by precisely 1 0 with the
	//      rest of the byte containing arbitrary bits.  This array stores
	//      the required bit pattern for validity checking.
	//  gUTFByteIndicatorTest
	//      When bitwise and'd with the observed value, if the observed
	//      value is correct then a result matching gUTFByteIndicator will
	//      be produced.
	//
	//  gUTFOffsets
	//      A list of values to offset each result char type, according to how
	//      many source bytes when into making it.
	//
	//  gFirstByteMark
	//      A list of values to mask onto the first byte of an encoded sequence,
	//      indexed by the number of bytes used to create the sequence.
	// ---------------------------------------------------------------------------
	cuchar gUTFBytes[256] =
	{
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		,   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
		,   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
		,   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
		,   3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
	};

	static cuchar gUTFByteIndicator[6] =
	{
		0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
	};
	static cuchar gUTFByteIndicatorTest[6] =
	{
		0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE
	};

	const unsigned long gUTFOffsets[6] =
	{
		0, 0x3080, 0xE2080, 0x3C82080, 0xFA082080, 0x82082080
	};

	cuchar gFirstByteMark[7] =
	{
		0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
	};

	DNC_DECLARE size_t ANSIToUNICODE(castr srcData,size_t srcCount, wstr destData,size_t destCount){
		int ret;
#if defined(_MSC_VER)
		ret = ::MultiByteToWideChar(CP_ACP,0,srcData,(int)srcCount,destData,(int)destCount);
		if(ret == 0) ret = -1;
		return ret;
#else
		ret = ::mbstowcs(destData, srcData,destCount);
#endif
		return (unsigned int)ret;
	}
	DNC_DECLARE size_t UNICODEToANSI(cwstr srcData,size_t srcCount,astr destData,size_t destCount){
		int ret;
#if defined(_MSC_VER)
		ret = ::WideCharToMultiByte(CP_ACP,0,srcData,(int)srcCount,destData,(int)destCount, NULL, NULL );
#else
		ret = ::wcstombs(destData,srcData,destCount);
#endif
		return (unsigned int)ret;
	}

	// ---------------------------------------------------------------------------
	//  XMLUTF8Transcoder: Implementation of the transcoder API
	// ---------------------------------------------------------------------------
	DNC_DECLARE size_t ANSIToUTF8(castr srcData,size_t srcCount,ustr destData,size_t destCount){
		wchar_t *wstr = (wchar_t*)malloc(srcCount*2);
		size_t len = 0;
		int ret = 0;
		try{
#if defined(WIN32)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色综合天天综合网天天狠天天 | 日本一区中文字幕| 亚洲视频精选在线| 国产精品污www在线观看| 久久久久成人黄色影片| 久久综合九色综合欧美就去吻| 亚洲国产高清不卡| 中文天堂在线一区| 中文字幕第一区| 亚洲三级电影网站| 亚洲成人资源网| 蜜臀av性久久久久蜜臀aⅴ四虎| 老司机免费视频一区二区| 久久精品999| 成人午夜大片免费观看| 成人avav在线| 欧美在线免费观看视频| 欧美精品在线观看一区二区| 亚洲国产精品高清| 国产精品传媒在线| 亚洲综合免费观看高清完整版在线 | 午夜精品国产更新| 日本91福利区| 粉嫩欧美一区二区三区高清影视| 成人app网站| 欧美特级限制片免费在线观看| 6080日韩午夜伦伦午夜伦| 久久伊99综合婷婷久久伊| 国产精品国产自产拍高清av王其| 亚洲美女视频在线观看| 偷拍亚洲欧洲综合| 国产大陆精品国产| 91国偷自产一区二区三区观看| 5566中文字幕一区二区电影| 国产欧美日韩亚州综合| 最新日韩在线视频| 九九在线精品视频| 色综合久久久网| 久久一区二区三区四区| 亚洲最大色网站| 国产高清无密码一区二区三区| 99久久精品免费看国产| 91精品国产综合久久精品图片| 久久久精品国产免费观看同学| 亚洲蜜臀av乱码久久精品| 日本三级韩国三级欧美三级| 成人高清av在线| 久久一留热品黄| 三级欧美韩日大片在线看| www.爱久久.com| 欧美成人精品福利| 亚洲国产一二三| 不卡的电影网站| 久久久久久久网| 美国毛片一区二区| 欧美日韩黄色影视| 亚洲精品中文在线影院| 粗大黑人巨茎大战欧美成人| 日韩视频在线永久播放| 日韩精品高清不卡| 欧美久久一区二区| 亚洲综合免费观看高清在线观看| aa级大片欧美| 中文字幕第一区综合| 国内成人自拍视频| 精品国产露脸精彩对白| 日本亚洲欧美天堂免费| 在线播放视频一区| 调教+趴+乳夹+国产+精品| 日本电影欧美片| 亚洲一区二区影院| 欧美视频一区二区| 亚洲一级片在线观看| 色婷婷亚洲婷婷| 亚洲免费色视频| 欧美专区日韩专区| 一区二区三区四区高清精品免费观看| 国产91丝袜在线观看| 久久噜噜亚洲综合| 国产成人在线视频播放| 国产精品美女久久久久久久| 成人精品电影在线观看| 亚洲另类春色校园小说| 欧美日韩国产大片| 轻轻草成人在线| 久久亚洲私人国产精品va媚药| 久久精品久久综合| 中文文精品字幕一区二区| 国产成人精品免费视频网站| 国产精品视频麻豆| 色综合中文字幕| 亚洲国产一区二区三区| 欧美一级二级三级乱码| 国产乱码精品一区二区三区av| 国产精品午夜春色av| 欧美性xxxxxxxx| 精品一区二区三区不卡| 中文字幕av不卡| 欧美丝袜丝交足nylons| 精品一区二区三区蜜桃| 国产精品欧美一区喷水| 色噜噜狠狠成人网p站| 午夜影视日本亚洲欧洲精品| 久久综合久久综合亚洲| 97se狠狠狠综合亚洲狠狠| 日韩成人av影视| 久久精品视频免费| 色乱码一区二区三区88| 麻豆专区一区二区三区四区五区| 国产欧美精品区一区二区三区| 在线区一区二视频| 国内精品伊人久久久久av影院| 中文在线资源观看网站视频免费不卡| 欧美日韩一区 二区 三区 久久精品| 日韩精品一区第一页| 中文字幕一区二区三区在线观看| 欧美日韩国产中文| 成人国产精品免费观看视频| 日韩av一区二区三区| 亚洲欧洲日韩在线| 精品sm在线观看| 精品视频一区三区九区| 成人免费毛片片v| 蜜臀91精品一区二区三区| 亚洲精品久久嫩草网站秘色| 91精品国产综合久久精品性色| 成人免费黄色在线| 激情六月婷婷综合| 天天综合天天做天天综合| 亚洲色图一区二区| 国产亚洲精品bt天堂精选| 欧美乱妇20p| 色噜噜狠狠色综合中国| 成人av网站在线观看| 蜜桃久久久久久| 婷婷综合在线观看| 亚洲高清中文字幕| 一区二区三区欧美久久| 亚洲天堂中文字幕| 国产精品毛片a∨一区二区三区| 精品免费视频.| 日韩亚洲欧美在线| 欧美精品99久久久**| 在线观看成人小视频| 91在线一区二区三区| 成人午夜av影视| av中文字幕亚洲| www.久久久久久久久| jlzzjlzz亚洲女人18| 99精品国产视频| 成人av在线影院| 粉嫩av一区二区三区| 不卡的av在线| 91网站在线播放| 色婷婷av一区二区三区软件 | 久久精品一级爱片| 久久天堂av综合合色蜜桃网| 久久久蜜臀国产一区二区| 精品国精品国产尤物美女| www一区二区| 国产情人综合久久777777| 国产精品视频九色porn| 亚洲视频在线一区二区| 一区二区欧美国产| 午夜精品久久久久影视| 图片区小说区国产精品视频| 丝袜美腿亚洲色图| 久久99久久久欧美国产| 国产一区二区三区电影在线观看| 国产999精品久久久久久绿帽| 成人av资源网站| 欧美日韩国产精品成人| 欧美精品一区二区蜜臀亚洲| 中文字幕精品一区| 亚洲一区二区av在线| 久久成人18免费观看| 成人午夜电影久久影院| 欧美亚洲丝袜传媒另类| 在线综合亚洲欧美在线视频| 欧美精品一区二区三区高清aⅴ | 欧美三级资源在线| 日韩视频在线你懂得| 亚洲国产成人在线| 亚洲高清在线精品| 国产一区二区不卡在线| 99久久99久久精品免费看蜜桃| 欧美日韩一区三区四区| 久久久综合视频| 一区二区久久久| 国产精品99久久久久| 欧美性色欧美a在线播放| 日韩午夜在线观看视频| 国产精品理论在线观看| 天堂在线一区二区| 成人做爰69片免费看网站| 欧美一区二区女人| 亚洲欧美一区二区在线观看| 久久精品国产色蜜蜜麻豆| 91精品福利视频| 精品999在线播放|