From: Jim Weirich Date: 2006-06-29T05:25:55+09:00 Subject: Re: Unicode roadmap? Austin Ziegler wrote: > Again, you are wrong. Horribly so. I *can* guarantee that sizeof(char) > == sizeof(byte) if String#encoding is a single-byte encoding or is "raw" > (or "binary", whichever Matz uses). I think his point is that for any arbitrary string you cannot guarantee that it is a single byte encoding and that your code should be written: raise "Not PNG." unless (SINGLE_BYTE_ENCODINGS.include?(@top.encoding) && @top[0, 8] == "\x89PNG\x0d\x0a\x1a\x0a") Of course, if you can guarantee that @top is indeed a single byte encoded BEFORE hitting this line, then the encoding test is not needed (and I think you assume that). But in the general case, it just seems easier to write: raise "Not PNG." unless @top.byte(0, 8) == "\x89PNG\x0d\x0a\x1a\x0a" which will work in all cases, without any effort to ensure the precondition that the encoding is a single byte encoding. -- Jim Weirich -- Posted via http://www.ruby-forum.com/.