# HG changeset patch # User Aziz K?ksal # Date 1190647379 -7200 # Node ID 3aa00474b381fb4c9f18a1f401bd8e403555779e # Parent 5431c0faf3b5e64421981255178222fb382e18c3 Fixed byte swap expressions in dil.File.utf32BEtoLE(). diff -r 5431c0faf3b5 -r 3aa00474b381 trunk/src/dil/File.d --- a/trunk/src/dil/File.d Sun Sep 23 21:50:27 2007 +0200 +++ b/trunk/src/dil/File.d Mon Sep 24 17:22:59 2007 +0200 @@ -125,14 +125,21 @@ dchar[] result = cast(dchar[]) new ubyte[data.length]; assert(result.length*4 == data.length); // BE to LE "1A 2B 3C 4D" -> "4D 3C 2B 1A" + // TODO: the 'bswap' asm instruction could be used instead of shifts and &-operations. foreach (i, c; cast(uint[]) data) - result[i] = ((c & 0xFF)) | - ((c >> 8) & 0xFF) | - ((c >> 16) & 0xFF) | - (c >> 24); + result[i] = (c << 24) | + ((c >> 8) & 0xFF00) | + ((c << 8) & 0xFF0000) | + (c >> 24); return cast(ubyte[]) result; } +unittest +{ + ubyte[] test = cast(ubyte[])x"1A 2B 3C 4D"; + assert(utf32BEtoLE(test) == cast(ubyte[])x"4D 3C 2B 1A"); +} + /// Byte Order Mark enum BOM {