On Saturday 16 November 2002 03:52 am, Dmitry Timoshkov wrote:
"Greg Turner" gmturner007@ameritech.net wrote:
So, I think, I should #ifdef the byte-swapping based on the endianness of the target platform (little-endian hosts byte-swap, big-endian hosts don't).... does that sound right?
I think there is no need for #ifdef's. Something like this should work:
if (ch < 256) { mbch[0] = ch & 0xff; n_chars = 1; } else /* multibyte character */ { mbch[0] = (ch >> 8) & 0xff; mbch[1] = ch & 0xff; n_chars = 2; }
Of course, you are right -- that looks great. Now I just have to figure out that codepage thing, and I should be set.
An interesting side note: Microsoft claims that their implementations of these functions are blindingly fast (they said something along the lines that calling these is faster than "if (((0xXX <= ch) && (ch <= 0xYY)) || ((0xAA <= ch) && (ch <=0xBB)))"). I wonder if this means they are using a lookup table in their implementation? Not planning to implement any such thing myself, of course, but I did find it to be an intrigueing statement.