"Greg Turner" gmturner007@ameritech.net wrote:
It seems pretty clear from the examples already implemented in this unit that, regardless of the platform endianness, the low order byte will be the trailing byte, and the high-order byte will be the leading byte. MultiByteToWideChar (and _mbtowc, which might be more appropriate here? More on this below...) would seem to expect the bytes in the following order: [leading byte, trailing byte], regardless of the endianness of the platform. 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:
int _ismbcalpha(unsigned int ch) { char mbch[2]; WCHAR chW; WORD ctype; int n_chars;
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; } MultiByteToWideChar(CP_ACP, 0, mbch, n_chars, &chW, 1); GetStringTypeW(CT_CTYPE1, &chW, 1, &ctype); return (ctype & C1_ALPHA) != 0; }
Another issue that I haven't quite figured out: In this function, I'm supposed to respect the current multibyte code page, as can be get/set by the _{get,set}mbcp functions. The proposed implementation above uses the ANSI codepage, but are those the same thing? To me, it seems like they aren't but I haven't really looked into it, because I've been focusing on the byte ordering issue so far.
Frankly speaking, I don't know.