2 |
## $Id$ |
## $Id$ |
3 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.24 2004/06/07 16:44:54 joko |
6 |
|
## sub expand: Now also converts hash-keys to/from utf-8 |
7 |
|
## |
8 |
|
## Revision 1.23 2003/05/13 07:39:22 joko |
9 |
|
## new option 'define' for "sub expand": set value to empty string if desired |
10 |
|
## |
11 |
## Revision 1.22 2003/05/10 17:09:18 jonen |
## Revision 1.22 2003/05/10 17:09:18 jonen |
12 |
## + added keep of empty arrays/hashes if 'expand' for php |
## + added keep of empty arrays/hashes if 'expand' for php |
13 |
## |
## |
175 |
|
|
176 |
# convert values in hash to utf8 (and back) to be ready for (e.g.) encapsulation in XML |
# convert values in hash to utf8 (and back) to be ready for (e.g.) encapsulation in XML |
177 |
# but still using the known latin locale stuff |
# but still using the known latin locale stuff |
178 |
|
# TODO: Review: Could this be revamped using Clone.pm? |
179 |
sub expand { |
sub expand { |
180 |
|
|
181 |
my $obj = shift; |
my $obj = shift; |
214 |
$item = latin_to_utf8_scalar($item) if ($item && $options->{utf8}); |
$item = latin_to_utf8_scalar($item) if ($item && $options->{utf8}); |
215 |
$item = utf8_to_latin_scalar($item) if ($item && $options->{to_latin}); |
$item = utf8_to_latin_scalar($item) if ($item && $options->{to_latin}); |
216 |
} |
} |
217 |
|
|
218 |
|
$item = '' if $options->{define} and not defined $item; |
219 |
#push(@{$result}, $item) if $item; # use item only if not undef (TODO: make configurable via $options) |
#push(@{$result}, $item) if $item; # use item only if not undef (TODO: make configurable via $options) |
220 |
push(@{$result}, $item); # use item in any case |
push(@{$result}, $item); # use item in any case |
221 |
|
|
235 |
$result = $obj; |
$result = $obj; |
236 |
} else { |
} else { |
237 |
IterHash %$obj, sub { |
IterHash %$obj, sub { |
238 |
|
my $key = $_[0]; |
239 |
my $item; |
my $item; |
240 |
|
|
241 |
|
# conversions/encodings |
242 |
|
$key = latin_to_utf8_scalar($key) if ($key && $options->{utf8}); |
243 |
|
$key = utf8_to_latin_scalar($key) if ($key && $options->{to_latin}); |
244 |
|
|
245 |
# if current item is a reference ... |
# if current item is a reference ... |
246 |
if (ref $_[1]) { |
if (ref $_[1]) { |
247 |
$item = $_[1]; |
$item = $_[1]; |
264 |
$item = latin_to_utf8_scalar($item) if ($item && $options->{utf8}); |
$item = latin_to_utf8_scalar($item) if ($item && $options->{utf8}); |
265 |
$item = utf8_to_latin_scalar($item) if ($item && $options->{to_latin}); |
$item = utf8_to_latin_scalar($item) if ($item && $options->{to_latin}); |
266 |
} |
} |
267 |
|
|
268 |
|
$item = '' if $options->{define} and not defined $item; |
269 |
#$result->{$_[0]} = $item if $item; # use item only if not undef (TODO: make configurable via $options) |
#$result->{$_[0]} = $item if $item; # use item only if not undef (TODO: make configurable via $options) |
270 |
$result->{$_[0]} = $item; # use item in any case |
$result->{$key} = $item; # use item in any case |
271 |
} |
} |
272 |
} |
} |
273 |
|
|