<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: decoder code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 11 Oct 2008 18:02:07 GMT</pubDate>
    <description>DZone Snippets: decoder code</description>
    <item>
      <title>UTF-8 Converter //JavaScript Object</title>
      <link>http://snippets.dzone.com/posts/show/5294</link>
      <description>&lt;br /&gt;&lt;br /&gt;&lt;a href="http://jsfromhell.com/geral/utf-8"&gt;&lt;br /&gt;Converts a sequence of ANSI characters to UTF-8 and vice-versa.&lt;br /&gt;&lt;br /&gt;[UPDATED CODE AND HELP CAN BE FOUND HERE]&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com/geral/utf-8 [v1.0]&lt;br /&gt;&lt;br /&gt;UTF8 = {&lt;br /&gt;	encode: function(s){&lt;br /&gt;		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i &lt; l;&lt;br /&gt;			s[i] = (c = s[i].charCodeAt(0)) &gt;= 127 ? o(0xc0 | (c &gt;&gt;&gt; 6)) + o(0x80 | (c &amp; 0x3f)) : s[i]&lt;br /&gt;		);&lt;br /&gt;		return s.join("");&lt;br /&gt;	},&lt;br /&gt;	decode: function(s){&lt;br /&gt;		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i &lt; l;&lt;br /&gt;			((a = s[i][c](0)) &amp; 0x80) &amp;&amp;&lt;br /&gt;			(s[i] = (a &amp; 0xfc) == 0xc0 &amp;&amp; ((b = s[i + 1][c](0)) &amp; 0xc0) == 0x80 ?&lt;br /&gt;			o(((a &amp; 0x03) &lt;&lt; 6) + (b &amp; 0x3f)) : o(128), s[++i] = "")&lt;br /&gt;		);&lt;br /&gt;		return s.join("");&lt;br /&gt;	}&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Example&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var s = "a&#225;&#233;&#237;&#243;&#250;e";&lt;br /&gt;document.write(&lt;br /&gt;	('UTF8.encode("' + s + '") = ').bold(), UTF8.encode(s), "&lt;br /&gt;",&lt;br /&gt;	('UTF8.decode(UTF8.encode("' + s + '"))) = ').bold(), UTF8.decode(UTF8.encode(s))&lt;br /&gt;);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 30 Mar 2008 16:52:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5294</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>Morse decode using sed</title>
      <link>http://snippets.dzone.com/posts/show/5144</link>
      <description>This is a short &lt;a href="http://en.wikipedia.org/wiki/Morse_code"&gt;Morse code&lt;/a&gt; decoder written as a shellscript using &lt;a href="http://en.wikipedia.org/wiki/Sed"&gt;sed&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The Morse coded text should be in $text, and should be written with spaces between the letters.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;echo $text\  | tr . 0 | sed -e {s/0----\ /1/g} -e {s/00---\ /2/g} -e {s/000--\ /3/g} -e {s/000-\ /4/g} -e {s/00000\ /5/g} -e {s/-0000\ /6/g} -e {s/--000\ /7/g} -e {s/---00\ /8/g} -e {s/----0\ /9/g} -e {s/-----\ /0/g} \&lt;br /&gt;	| sed -e {s/-0-0\ /c/g} -e {s/-000\ /b/g} -e {s/00-0\ /f/g} -e {s/0000\ /h/g} -e {s/0---\ /j/g} -e {s/0-00\ /l/g} -e {s/0--0\ /p/g} -e {s/--0-\ /q/g} -e {s/000-\ /v/g} -e {s/-00-\ /x/g} -e {s/-0--\ /y/g} -e {s/--00\ /z/g} \&lt;br /&gt;	| sed -e {s/0--\ /w/g} -e {s/-00\ /d/g} -e {s/--0\ /g/g} -e {s/-0-\ /k/g} -e {s/---\ /o/g} -e {s/0-0\ /r/g} -e {s/000\ /s/g} -e {s/00-\ /u/g} \&lt;br /&gt;	| sed -e {s/0-\ /a/g} -e {s/00\ /i/g} -e {s/--\ /m/g} -e {s/-0\ /n/g} \&lt;br /&gt;	| sed -e {s/0\ /e/g} -e {s/-\ /t/g}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 15 Feb 2008 13:54:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5144</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
  </channel>
</rss>
