Mercurial > projects > dil
changeset 408:3aa00474b381
Fixed byte swap expressions in dil.File.utf32BEtoLE().
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 24 Sep 2007 17:22:59 +0200 |
parents | 5431c0faf3b5 |
children | 38fccd2640eb |
files | trunk/src/dil/File.d |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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 {