Re: [pcre-dev] implementing support for std::wstring in pcre…

Startseite
Nachricht löschen
Autor: Craig Silverstein
Datum:  
To: Thorsten Schöning
CC: pcre-dev
Betreff: Re: [pcre-dev] implementing support for std::wstring in pcrecpp
} Because we only use pcrecpp and it abstracts the use of strings in
} it's own StringPiece class, I thought of extending it to support
} std::wstring by reencoding it itself into proper UTF-8. It seems
} that I just has to write a new constructor which does the encoding
} work, maintain a flag that UTF-8 is present and adjust the args
} given to PCRE to use UTF-8-matching and maybe add/change
} Arg::parse_* methods which handle strings.

This is a reasonable approach. But I'm guessing we probably won't
want to add an encoding-conversion library into pcre, either as a
dependency or hard-coded in.

There's another way to do it, which is uglier but doesn't require
modifying pcre: use a conversion operator.

For this to work, you'll need to subclass std::wstring. The subclass
will define the constructors you need, and also an 'operator
StringPiece() const'. It's this method that will convert the wstring
into a utf-8 string, wrap that in a stringpiece, and return it.

Then you should be able to pass in your wstring-subclass whenever
pcrecpp expects a StringPiece. Would this work for your needs?

craig