|
Boost Users : |
Subject: Re: [Boost-users] Using boost string algorithm with BOOST_NO_STD_LOCALE
From: Václav Zeman (vhaisman_at_[hidden])
Date: 2012-06-27 01:34:40
On 06/26/2012 08:50 PM, Allan Nielsen wrote:
> Hi,
>
> I'm developing for an embedded environment where we do not have a
> complete c++ standard library available, and one of the things missing
> is std::locale.
>
> But even without this feature, I would very much like to use the boost
> string algorithms ( split, tokenize, etc ). The only problem is that
> they depends on std::locale. I have been looking around in the source
> code, trying to see how easy it would be to add the needed ifdef's to
> make it work without std::locale. Most of the code looks straight
> forward to modify, but I'm stuck on this function:
>
> struct is_classifiedF :
> public predicate_facade<is_classifiedF>
> {
> // Boost.ResultOf support
> typedef bool result_type;
>
> // Constructor from a locale
> is_classifiedF(std::ctype_base::mask Type, std::locale
> const & Loc = std::locale()) :
> m_Type(Type), m_Locale(Loc) {}
> // Operation
> template<typename CharT>
> bool operator()( CharT Ch ) const
> {
> return std::use_facet< std::ctype<CharT>
>> (m_Locale).is( m_Type, Ch );
> }
>
> private:
> std::ctype_base::mask m_Type;
> std::locale m_Locale;
> };
>
> I know what the code does, I just do not know how it does it. This is
> without a doubt because I know nothing about locale, facet, etc.
>
> What I would like is another version of this struct which did not
> depend on std::locale, but simply assumed that the local used is "C".
> Something like this:
>
> struct is_classifiedF :
> public predicate_facade<is_classifiedF>
> {
> typedef bool result_type;
>
> is_classifiedF(std::ctype_base::mask Type) :
> m_Type(Type) {}
>
> template<typename CharT>
> bool operator()( CharT Ch ) const
> {
> // Write something here
> }
>
> private:
> std::ctype_base::mask m_Type;
> };
>
> But as I do not understand the meaning/encoding of
> std::ctype_base::mask m_Type I found it hard to write the missing
> function body.
>
> So I could use some pointers/hints on how to implement this.
>
See, e.g., the GNU libstdc++ docs: <
http://gcc.gnu.org/onlinedocs/gcc-4.7.1/libstdc++/api/a00617.html>. It
is a mask of given isfoo (e.g., isalnum(), etc.) character type query
function.
-- VZ
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net