Discussion:
convert string, wstring to lowercase
(too old to reply)
Jeremy Pullicino
2004-01-15 13:24:50 UTC
Permalink
I have once seen a solution to convert a string or wstring to lowercase.

Does anyone have it handy?

Thanks,
Jeremy Pullicino
Vincent Finn
2004-01-15 14:56:25 UTC
Permalink
On Thu, 15 Jan 2004 14:24:50 +0100, "Jeremy Pullicino"
Post by Jeremy Pullicino
I have once seen a solution to convert a string or wstring to lowercase.
std::transform(myString.begin(), myString.end(), mtString.begin(),
tolower);
Ken Alverson
2004-01-15 15:48:04 UTC
Permalink
Post by Vincent Finn
On Thu, 15 Jan 2004 14:24:50 +0100, "Jeremy Pullicino"
Post by Jeremy Pullicino
I have once seen a solution to convert a string or wstring to lowercase.
std::transform(myString.begin(), myString.end(), mtString.begin(),
tolower);
Careful, I believe this will compile for wstrings (because tolower takes
ints), but it won't do what you want it to (it'll treat your unicode as
ascii). I don't think there is a C++ standard way to lowercase wchars...on
win32, you can do it with the function CharLower[W], but you'll need to wrap
it to use it in a std::transform, because it represents the epitome of how not
to create an API.

Ken
Igor Tandetnik
2004-01-15 16:01:09 UTC
Permalink
Post by Ken Alverson
I don't think there is a C++ standard way to lowercase wchars...
ctype<wchar_t>::tolower, std::tolower<wchar_t>(wchar_t, locale)
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Ken Alverson
2004-01-15 19:15:18 UTC
Permalink
Post by Igor Tandetnik
Post by Ken Alverson
I don't think there is a C++ standard way to lowercase wchars...
ctype<wchar_t>::tolower, std::tolower<wchar_t>(wchar_t, locale)
Whoops. Good catch!

Ken
Sean Kelly
2004-01-23 01:07:25 UTC
Permalink
Post by Igor Tandetnik
ctype<wchar_t>::tolower, std::tolower<wchar_t>(wchar_t, locale)
Here's a reasonable implementation of a conversion object, benefit being
the ctype info is only retrieved once:


template<typename Ty>
struct to_lower :
public std::unary_function<Ty,Ty>
{
public:
to_lower() :
m_ct( std::use_facet<std::ctype<Ty> >( std::locale::classic() ) ) {}
Ty operator()( Ty in ) const { return m_ct.tolower( in ); }
private:
std::ctype<Ty> const& m_ct;
};


Sean

Loading...