Hi,

On 30/04/2013 06:55, Johan Vromans wrote:
Mark Dootson <mark.doot...@znix.com> writes:

Hi,

On 29/04/2013 20:06, Johan Vromans wrote:

I'd say this is the wrong approach. The solution is to adjust the
WXSTRING_PUT macro to check for the utf8 flag and handle accordingly.

That's exactly what it does, unless I've misunderstood.

If it did, the explicit utf8::upgrade would not be necessary.

I'm not an XS expert, so I asked some of my friends who are. They
suggested to use SvPVutf8_force in WXSTRING_PUT.

Does that sound sensible?

-- Johan


Using SvPVutf8_force in WXSTRING_INPUT looks completely wrong to me. I think we must be talking at cross purposes.

Without introducing some extra parameters, when we pass a string to the wxWidgets library we can successfully do so as one of two formats.

Format 1 = UTF-8
Format 2 = whatever the wxWidgets library thinks the current default format is.

So, when we are passing the content of a Perl SV we can check the utf8 flag and depending on that we can tell the wxWidgets library either

1. This data is UTF-8
2. This data is the current default format fro wxWidgets.

I am of the opinion that this bit ( WXSTRING_INPUT ) already works as well as it can do if given an SV and no other params. I certainly would not want to change it to force all input to be valid UTF-8. There is absolutely no reason to do so.

On the decode / utf8::upgrade question:

It seems a simple thing to me that looking at the above, if you have a $string scalar that you know is valid UTF-8 then you may as well let the wxWidgets library convert it as UTF-8 rather than hoping that the other method will work.

Hence, utf8::upgrade($string);

All I am suggesting here is the functional equivalent of

my $string = decode('$externalencoding', $data);

.... do Perl stuff with $string.

$externallibrarycall( encode('$externalencoding', $string) );

I don't think there's a coding error just because I use utf8::upgrade($string). I don't need utf8::upgrade for my Perl code. I need it to allow me to tell wxWidgets what's in $string.

As noted in perldoc, utf8::upgrade can be used to ensure the utf8 flag is set on a scalar.

I appreciate your view may be different and you're entitled to think mine is wrong. I'm happy with the way WXSTRING_INPUT is and my advice to utf8::upgrade($string);


Cheers

Mark























Reply via email to