Re: Escaping unicode

Tobias Nissen <[email protected]> Wed, 18 Nov 2009 08:27:03 +0100
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
--===============6648761036124446115==
Content-Type: multipart/signed; micalg=PGP-SHA1;
	boundary="Sig_/n53KkUXTn0MIkC7IqUAk/Qw";
	protocol="application/pgp-signature"

--Sig_/n53KkUXTn0MIkC7IqUAk/Qw
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

Thank you both for your answers!

Michael Peters wrote:
> On 11/13/2009 08:26 AM, Tobias Nissen wrote:
>> For the data to be escaped before feeding it to H::T, I'd have to
>> add a lot of code, therefore I'd like to avoid this approach. Is
>> there any way I can tell H::T to escape Unicode data I feed to it
>> with param()?
>=20
> You could create a function if you were using HTML::Template::Expr or=20
> you could subclass HTML::Template and change param to first filter
> the unicode chars for you. Then pass it off to the base class to do
> the rest. Would be an extremely simple subclass.

Indeed...

  package MyHT;
  use base 'HTML::Template';
  sub param { return SUPER::param(escape(@_)) }
  sub escape { ... escape magic ... }
  1;

Or something like that.

>> If not, then the next best thing would be to create a patched
>> version of H::T for my purposes with a method like param_escape()
>> or sth like that, right?
>=20
> No, please don't do that. Don't run with a patched version unless=20
> absolutely necessary. Instead go with a subclass.

You're right, that's the better approach. And at first it seemed like
the right approach for my problem, because I didn't want to walk
through complex data structures to escape characters. I thought it
would be enough to call a simple escaping function[0] for each value
(in (key, value)) param() gets passed. But it turned out to be
insufficient, since I was already passing data structures consisting of
arrays /and/ hashes. Hence I had to walk through the whole shebang...
At that moment a wrapper would just have meant more code, so now I'm
just calling

  $ht_params =3D escape_unicode_for_rtf($ht_params) if $format eq 'rtf';

before passing the parameters to param(). If there were other formats
(and not just RTF) where unicode sequences were to escape, then I'd use
a wrapper to enhance code readability, I think.

[0] i.e. one that takes every argument and escapes unicode sequences in
it. This would work for arrays, hashes and scalars. But that's it then.

--Sig_/n53KkUXTn0MIkC7IqUAk/Qw
Content-Type: application/pgp-signature; name=signature.asc
Content-Disposition: attachment; filename=signature.asc

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAksDoccACgkQ5jrP7hWxSO8UXACgxHK7hvhf7GNY5ge9WsQ5cvnv
ZyQAn0lhVKoHIbaUMcxRxTO8MYJ5JV4P
=5N/Z
-----END PGP SIGNATURE-----

--Sig_/n53KkUXTn0MIkC7IqUAk/Qw--


--===============6648761036124446115==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
--===============6648761036124446115==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Html-template-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/html-template-users

--===============6648761036124446115==--