From: Mike Taylor Date: Tue, 5 Dec 2006 17:19:35 +0000 (+0000) Subject: xml_encode() now takes an optional hash of options. X-Git-Tag: CPAN-v1.02~714 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=337cd65767c5ae6e7b2f11651da22391fc677b73;p=irspy-moved-to-github.git xml_encode() now takes an optional hash of options. Only option currently used is "nbsp" to make spaces unbreakable. --- diff --git a/lib/ZOOM/IRSpy/Utils.pm b/lib/ZOOM/IRSpy/Utils.pm index 071e226..6367761 100644 --- a/lib/ZOOM/IRSpy/Utils.pm +++ b/lib/ZOOM/IRSpy/Utils.pm @@ -1,4 +1,4 @@ -# $Id: Utils.pm,v 1.18 2006-11-30 12:02:26 mike Exp $ +# $Id: Utils.pm,v 1.19 2006-12-05 17:19:35 mike Exp $ package ZOOM::IRSpy::Utils; @@ -36,7 +36,13 @@ sub isodate { # Template::Plugin both roll their own. So I will do likewise. D'oh! # sub xml_encode { - my($text, $fallback) = @_; + my($text, $fallback, $opts) = @_; + if (!defined $opts && ref $fallback) { + # The second and third arguments are both optional + $opts = $fallback; + $fallback = undef; + } + $opts = {} if !defined $opts; $text = $fallback if !defined $text; use Carp; @@ -49,6 +55,8 @@ sub xml_encode { # Internet Explorer can't display ' (!) so don't create it #$text =~ s/['']/'/g; $text =~ s/[""]/"/g; + $text =~ s/ / /g if $opts->{nbsp}; + return $text; }