<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On 03 Jan 2015, at 19:12, James Mills <<a href="mailto:prologic@shortcircuit.net.au" class="">prologic@shortcircuit.net.au</a>> wrote:</div><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":1gt" class="a3s" style="overflow:hidden">Look at the function strniconv() on string.c line 144. Not the easiest to understand because it has lots of bit handling - you should probably read & fully understand some UTF-8 docs before trying to figure out what my code does and why it works the way it does.<div class="yj6qo ajU"><div id=":1kd" class="ajR" tabindex="0"></div></div></div></blockquote></div><br class="">Interesting :) Got a lnk to some docs/refs that explain how this works? (I assume you followed some well understood algo)</div></div></div></blockquote><br class=""></div><div>Nope, there is no algo here, just my own code based on my reading of the offical docs.</div><div><br class=""></div><div>Basic idea:</div><div><br class=""></div><div>- first 128 bytes of US-ASCII & Latin-1 & UTF-8 are the same</div><div>- first 256 bytes of Latin-1 & UTF-8 are the same</div><div>- the way UTF-8 encodes >0x80 values is easy to detect from byte stream</div><div><br class=""></div><div>Based on that I made a function which:</div><div><br class=""></div><div>- first upconverts all three to 32-bit UTF</div><div>- if output = US-ASCII use the translation table defined in gophernicus.h to downconvert 0x80 - 0xff to 7-bit</div><div>- if output = Latin-1 let 0x00-0xff pass through and discard anything > 0xff</div><div>- if output = UTF-8 just encode anything over 0x80 using the UTF-8 encoding</div><div><br class=""></div><div><br class=""></div><div><br class=""></div><div>- Kim</div><div><br class=""></div><div><br class=""></div><div><br class=""></div><div><br class=""></div><div><br class=""></div><div><br class=""></div><br class=""></body></html>