<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>UTF-16 to UTF-8 without allocation</title>
		<link>http://www.allegro.cc/forums/view/613172</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 07 Sep 2013 16:05:15 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m looking into doing a Unicode build of Allegro 5.1 on Windows. To support both ANSI and UNICODE builds, I&#39;m thinking about adding this function:</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#ifdef UNICODE</span>
   <span class="k1">char</span> <span class="k3">*</span>_al_win_strconv<span class="k2">(</span><span class="k1">char</span> <span class="k3">*</span>dest, <span class="k1">const</span> TCHAR <span class="k3">*</span>src, <span class="k1">size_t</span> destsize<span class="k2">)</span><span class="k2">;</span>
<span class="p">#else</span>
   <span class="p">#define _al_win_strconv _al_sane_strncpy</span>
<span class="p">#endif</span>
</pre></div></div><p>

In unicode builds it would convert from utf-16 to utf-8. Does Allegro have internal functions that I can base it on? Or does anyone have this and would be willing to contribute it to Allegro? I&#39;m lazy today <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Fri, 23 Aug 2013 21:46:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You probably could use <span class="source-code"><a href="http://www.allegro.cc/manual/al_ustr_new_from_utf16"><span class="a">al_ustr_new_from_utf16</span></a></span> followed by <span class="source-code"><a href="http://www.allegro.cc/manual/al_ustr_to_buffer"><span class="a">al_ustr_to_buffer</span></a></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/al_ustr_free"><span class="a">al_ustr_free</span></a></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sat, 24 Aug 2013 07:04:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Allegro is UTF-8 internally, so it is probably best to keep all text as UTF-8, especially if you only want to display non-ASCII characters on the screen (i.e. you don&#39;t need to use any other Windows unicode functions). You don&#39;t need a Unicode build of your game to display non-ASCII.</p><p>The Windows &quot;Unicode&quot; compile mode is to change from narrow/multi-byte to wide (UTF-16) chars, and is there for historical reasons (UCS-2). It is a misleading name; both modes support Unicode. They should be called &quot;multi-byte&quot; and &quot;wide&quot;.</p><p>See: <a href="http://www.utf8everywhere.org">http://www.utf8everywhere.org</a></p><p>I changed (<a href="https://github.com/billyquith/GWEN">a fork of</a>) GWEN over to using UTF-8 everywhere, which simplifies using text, and makes Allegro 5 text rendering more efficient (i.e. nothing needs doing). It only needs to be converted to wide for Windows, on the fly, which has a very low overhead. Before it was doing it the other way round, everything was wide and converted to narrow on the fly, but UTF-8 everywhere is a better plan.</p><p>If you&#39;d like the code to &quot;widen&quot; and &quot;narrow&quot; the unicode strings, it is here: <a href="https://github.com/billyquith/GWEN/blob/gwork/gwen/src/Utility.cpp">https://github.com/billyquith/GWEN/blob/gwork/gwen/src/Utility.cpp</a></p><p>I&#39;m using the C++11 locale API. There are other alternatives.</p><p>My work is in the &quot;gwork&quot; branch. If you are using Allegro I&#39;d suggest using this branch/fork of GWEN as it has better Allegro support. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (billyquith)</author>
		<pubDate>Sat, 24 Aug 2013 14:20:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/613172/989138#target">Elias</a> said:</div><div class="quote"><p> You probably could use al_ustr_new_from_utf16 followed by al_ustr_to_buffer and al_ustr_free.</p></div></div><p>I basically made a version of al_ustr_new_from_utf16 that takes a buffer and writes the output into that.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/613172/989152#target">billyquith</a> said:</div><div class="quote"><p> Allegro is UTF-8 internally, so it is probably best to keep all text as UTF-8, especially if you only want to display non-ASCII characters on the screen (i.e. you don&#39;t need to use any other Windows unicode functions). You don&#39;t need a Unicode build of your game to display non-ASCII.</p></div></div><p>This is about the Windows-specific part of the library, not a game...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sat, 24 Aug 2013 18:01:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Bit late, but see also src/win/wunicode.c (though they allocate).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Mon, 26 Aug 2013 10:05:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, I put my new function into that file.</p><p>Seems like I will be too busy with my studies to get much done the next few months, though <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sat, 07 Sep 2013 16:05:15 +0000</pubDate>
	</item>
</rss>
