On Tuesday 12 November 2002 10:42 pm, Dmitry Timoshkov wrote:
"Greg Turner" gmturner007@ameritech.net wrote:
So, on second thought, merged or no, I'll try to whip up a better version of _ismbc* and maybe, if I'm feeling especially cool, some others in the vicinity, using GetStringType as you reccomend.
try something like this (completely not tested):
int _ismbcalpha(unsigned int ch) { char mbch[2]; WCHAR chW; WORD ctype;
mbch[0] = ch & 0xff; mbch[1] = (ch >> 8) & 0xff; MultiByteToWideChar(CP_ACP, 0, mbch, 2, &chW, 1); GetStringTypeW(CT_CTYPE1, &chW, 1, &ctype); return (ctype & C1_ALPHA) != 0;
}
I'm not sure whether mbch[0] and mbch[1] should be actually swapped, in the case if multibyte character was passed in.
ok... after much pondering, I think I have this byte-ordering thing figured out. But, it's late, and I'm frazzled, so I'm hoping to get a santiy check on this before I go and implement the wrong thing.
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?
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.
/sheesh/ what a mess. so much for international standards making everything easy.... Advice, comments, tips, flames, mailbombs, reporting me to TIPS, etc. are appreciated...