<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DEAN LEE:/DEV/BLOG &#187; code_snippet</title>
	<atom:link href="http://www.deanlee.cn/tag/code_snippet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.deanlee.cn</link>
	<description>mount /dev/brain &#124;&#124; tail -f /var/log/thoughts &#62;&#62; /pub/www</description>
	<lastBuildDate>Fri, 03 Sep 2010 04:03:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Convert Unicode To UTF8</title>
		<link>http://www.deanlee.cn/programming/convert-unicode-to-utf8/</link>
		<comments>http://www.deanlee.cn/programming/convert-unicode-to-utf8/#comments</comments>
		<pubDate>Sun, 24 Sep 2006 06:00:15 +0000</pubDate>
		<dc:creator>Dean Lee</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[code_snippet]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[unicode]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://www.deanlee.cn/2006/09/24/convert-unicode-to-utf8/</guid>
		<description><![CDATA[char* __stdcall UnicodeToUtf8&#40; const WCHAR* wstr &#41; &#123; &#160; &#160; const WCHAR* w; &#160; &#160; // Convert unicode to utf8 &#160; &#160; int len = 0; &#160; &#160; for &#40; w = wstr; *w; w++ &#41; &#123; &#160; &#160; &#160; &#160; if &#40; *w &#60; 0&#215;0080 &#41; len++; &#160; &#160; &#160; &#160; else if &#40; [...]


Related posts:<ol><li><a href='http://www.deanlee.cn/programming/jenkins_hash/' rel='bookmark' title='Permanent Link: Jenkins hash算法。'>Jenkins hash算法。</a></li><li><a href='http://www.deanlee.cn/programming/convert-ip-address-to-geographic-location/' rel='bookmark' title='Permanent Link: Convert Ip Address To Geographic Location'>Convert Ip Address To Geographic Location</a></li><li><a href='http://www.deanlee.cn/windows/how-to-detect-whether-or-not-user-is-running-a-full-screen-program/' rel='bookmark' title='Permanent Link: How to detect whether or not user is running a full-screen program'>How to detect whether or not user is running a full-screen program</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div class="dean_ch" style="white-space: wrap;"><span class="kw4">char</span>* __stdcall UnicodeToUtf8<span class="br0">&#40;</span> <span class="kw4">const</span> WCHAR* wstr <span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">const</span> WCHAR* w;<br />
&nbsp; &nbsp; <span class="co1">// Convert unicode to utf8</span><br />
&nbsp; &nbsp; <span class="kw4">int</span> len = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span> w = wstr; *w; w++ <span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> *w &lt; 0&#215;0080 <span class="br0">&#41;</span> len++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span> *w &lt; 0&#215;0800 <span class="br0">&#41;</span> len += <span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> len += <span class="nu0">3</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw4">unsigned</span> <span class="kw4">char</span>* szOut = <span class="br0">&#40;</span> <span class="kw4">unsigned</span> <span class="kw4">char</span>* <span class="br0">&#41;</span>malloc<span class="br0">&#40;</span> len<span class="nu0">+1</span> <span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> szOut == <span class="kw2">NULL</span> <span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">NULL</span>;</p>
<p>&nbsp; &nbsp; <span class="kw4">int</span> i = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span> w = wstr; *w; w++ <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> *w &lt; 0&#215;0080 <span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; szOut<span class="br0">&#91;</span>i++<span class="br0">&#93;</span> = <span class="br0">&#40;</span> <span class="kw4">unsigned</span> <span class="kw4">char</span> <span class="br0">&#41;</span> *w;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span> *w &lt; 0&#215;0800 <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; szOut<span class="br0">&#91;</span>i++<span class="br0">&#93;</span> = 0xc0 | <span class="br0">&#40;</span><span class="br0">&#40;</span> *w <span class="br0">&#41;</span> &gt;&gt; <span class="nu0">6</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; szOut<span class="br0">&#91;</span>i++<span class="br0">&#93;</span> = 0&#215;80 | <span class="br0">&#40;</span><span class="br0">&#40;</span> *w <span class="br0">&#41;</span> &amp;amp; 0x3f <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; szOut<span class="br0">&#91;</span>i++<span class="br0">&#93;</span> = 0xe0 | <span class="br0">&#40;</span><span class="br0">&#40;</span> *w <span class="br0">&#41;</span> &gt;&gt; <span class="nu0">12</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; szOut<span class="br0">&#91;</span>i++<span class="br0">&#93;</span> = 0&#215;80 | <span class="br0">&#40;</span><span class="br0">&#40;</span> <span class="br0">&#40;</span> *w <span class="br0">&#41;</span> &gt;&gt; <span class="nu0">6</span> <span class="br0">&#41;</span> &amp;amp; 0x3f <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; szOut<span class="br0">&#91;</span>i++<span class="br0">&#93;</span> = 0&#215;80 | <span class="br0">&#40;</span><span class="br0">&#40;</span> *w <span class="br0">&#41;</span> &amp;amp; 0x3f <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> &nbsp; &nbsp;<span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; szOut<span class="br0">&#91;</span> i <span class="br0">&#93;</span> = <span class="st0">&#8216;<span class="es0">\0</span>&#8216;</span>;<br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span> <span class="kw4">char</span>* <span class="br0">&#41;</span>szOut;<br />
<span class="br0">&#125;</span></div>
<img src="http://www.deanlee.cn/?ak_action=api_record_view&id=47&type=feed" alt="" />

<p>Related posts:<ol><li><a href='http://www.deanlee.cn/programming/jenkins_hash/' rel='bookmark' title='Permanent Link: Jenkins hash算法。'>Jenkins hash算法。</a></li><li><a href='http://www.deanlee.cn/programming/convert-ip-address-to-geographic-location/' rel='bookmark' title='Permanent Link: Convert Ip Address To Geographic Location'>Convert Ip Address To Geographic Location</a></li><li><a href='http://www.deanlee.cn/windows/how-to-detect-whether-or-not-user-is-running-a-full-screen-program/' rel='bookmark' title='Permanent Link: How to detect whether or not user is running a full-screen program'>How to detect whether or not user is running a full-screen program</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.deanlee.cn/programming/convert-unicode-to-utf8/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
