Georg Baum wrote:
Am Sonntag, 3. September 2006 15:30 schrieb Abdelrazak Younes:
Question first: std::tolower() is a template and compiles fine with
char_type.
??? std::tolower comes from the C library (ctype.h) and is defined like
this:
int tolower(int);
MSVC doc says:
Converts a character to upper case.
template<Class CharType>
CharType toupper(
CharType _Ch,
const locale& _Loc
)
Parameters
_Ch
The character to be converted to upper case.
_Loc
The locale containing the character to be converted.
Return Value
The character converted to upper case.
Remarks
The template function returns use_facet<ctype<CharType>
>(_Loc).toupper(_Ch).
Example
The cast is not useful here as the test above ensure that the
argument is 8-bit ascii. Question is: is the test really necessary?
The function is not correct with or without the test.
Should we trust std::lower() to do the right thing with unicode char?
No, since the result of std::tolower depends on the current locale. I guess
you know by now that I prefer to not touch these functions and let the
compiler gerenate warnings for wrong argument types unless the function is
implemented correctly for unicode.
I prefer to fix the warning a put a FIXME to document our current
understanding:
// FIXME for lowercase() and uppercase() function below:
// 1) std::tolower() and std::toupper() are templates that
// compile fine with char_type. With the test (c >= 256) we
// do not trust these function to do the right thing with
// unicode char.
// 2) these functions use the current locale, which is wrong
// if it is not latin1 based (latin1 is a subset of UCS4).
That's a matter of taste I guess ;-)
Abdel.