From: Austin Ziegler Date: 2006-06-29T03:36:51+09:00 Subject: Re: Unicode roadmap? On 6/28/06, Julian 'Julik' Tarkhanov wrote: > On 28-jun-2006, at 19:33, Austin Ziegler wrote: > > Better, from my perspective: > > raise u"Not PNG." unless @top[0, 8] == "\x89PNG\x0d\x0a\x1a\x0a" > > > > That way, I *mark* the strings for which I want Unicode format. The > > encoding pragma makes it hard to do mixed content files. > > > > (This example, by the way, is *specifically* artificial, but the code > > involved is real. It's image matching code with error messages if > > there's a mismatch.) > > Please no. Please please no. > > What about: > > raise "Not PNG." unless @top.bytes[0, 8] == "\x89PNG\x0d\x0a\x1a\x0a" Except that @top is guaranteed to not have an encoding -- at least it damned well better not -- and @top.bytes is redundant in this case. I see no reason to access #bytes unless I know I'm dealing with a multibyte String. Worse, why would "Not PNG." be treated as Unicode under your scheme but "\x89PNG\x0d\x0a\x1a\x0a" not be? I don't think you're thinking this through. @top[0, 8] is sufficient when you can guarantee that sizeof(char) == sizeof(byte). On "raw" strings, this is always the case. On all strings, @top[0, 8] would return the appropriate number of characters -- not the number of bytes. It just so happens on binary strings that the number of characters and bytes is exactly the same. What I'm arguing is that while the pragma may work for the less-common encodings, both binary (non-)encoding and Unicode (probably UTF-8) are going to be common enough that specific literal constructors are probably a very good idea. -austin -- Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca