Boost logo

Boost :

Subject: Re: [boost] [spirit2] How to get encoding-specific parsers by character type
From: Joel de Guzman (joel_at_[hidden])
Date: 2010-06-11 20:09:23


On 6/12/10 5:13 AM, Andrey Semashev wrote:
> On 06/11/2010 12:35 PM, Hartmut Kaiser wrote:
>>> I was wondering if it was possible to get encoding-specific parsers by
>>> character type? Something like that:
>>>
>>> template< typename CharT>
>>> struct encoding_specific
>>> {
>>> ...
>>> };
>>>
>>> typedef encoding_specific< char> narrow;
>>> narrow::char_; // equivalent to spirit::standard::char_
>>>
>>> typedef encoding_specific< wchar_t> wide;
>>> wide::char_; // equivalent to spirit::standard_wide::char_
>>>
>>> This would help a lot in generic programming, when the character type is
>>> not known. Is there a tool like that already? If not, could it be added?
>>
>> There isn't anything like that. The reason is that usually you want to
>> specify a character set in addition to the character type to use. So the
>> solution above is nothing I would like to see in Spirit, even if it
>> might be
>> sufficient for your particular case. OTOH, if it is sufficient for you
>> why
>> don't you just add it inside your namespace and be done?
>
> Well, I did so. It just so happens that I find myself replicating that
> code in different places.
>
> I'm not very familiar with the standard specs on the new character types
> but isn't there a strong relationship between the character type and
> encoding? Can't we be sure that e.g. char16_t is UTF-16, char is the
> standard narrow and wchar_t is the standard wide encoding?

I don't think so. I use char/UTF-8 a lot now; I don't want char to be tied
to standard narrow.

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk