<?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>Erxin, Shang(Edwin, 尚尔鑫)&#039;s Home Page &#187; javascript</title>
	<atom:link href="http://www.shangerxin.com/?feed=rss2&#038;tag=javascript" rel="self" type="application/rss+xml" />
	<link>http://www.shangerxin.com</link>
	<description>Knowledge should be free.</description>
	<lastBuildDate>Tue, 24 Aug 2021 02:27:23 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.8.13</generator>
	<item>
		<title>Polyfill for Utf8toUtf16 for JavaScript</title>
		<link>http://www.shangerxin.com/?p=295</link>
		<comments>http://www.shangerxin.com/?p=295#comments</comments>
		<pubDate>Tue, 20 Sep 2016 09:30:50 +0000</pubDate>
		<dc:creator><![CDATA[Shang Erxin]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.shangerxin.com/?p=295</guid>
		<description><![CDATA[As we know the TextEncoder will drop support utf-16 and other legacy encoding types from Mozilla. Google also confirmed it and Chrome will only remain support utf-16 encoding. Here is a polyfill implementation for convert utf-8 string to utf-16le &#160; Reference: https://bugzilla.mozilla.org/show_bug.cgi?id=1257877 https://www.chromestatus.com/feature/5630760492990464]]></description>
				<content:encoded><![CDATA[<p>As we know the <a title="TextEncoder" href="https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder">TextEncoder </a>will drop support utf-16 and other legacy encoding types from Mozilla. Google also confirmed it and Chrome will only remain support utf-16 encoding.</p>
<p>Here is a polyfill implementation for convert utf-8 string to utf-16le</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Utf8toUtf16 Polyfill</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="javascript" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">function utf8ToUtf16(s) {</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	var a = new Uint8Array(s.length * 2),</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	view = new DataView(a.buffer);</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	s.split('').forEach(function (c, i) {</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">		//the third parameter equal to true indicate little ending</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">		view.setUint16(i * 2, c.charCodeAt(0), true);</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	});</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	return a;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">}</div></li></ol></pre></div></div>
<p>&nbsp;</p>
<p>Reference:<br />
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1257877">https://bugzilla.mozilla.org/show_bug.cgi?id=1257877</a><br />
<a href="https://www.chromestatus.com/feature/5630760492990464">https://www.chromestatus.com/feature/5630760492990464</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shangerxin.com/?feed=rss2&#038;p=295</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
