--- nfo/php/libs/org.netfrag.glib/Data/Encode.php 2003/03/10 23:25:02 1.2 +++ nfo/php/libs/org.netfrag.glib/Data/Encode.php 2004/06/16 15:17:03 1.3 @@ -9,9 +9,12 @@ */ // ------------------------------------------------------------------------- -// $Id: Encode.php,v 1.2 2003/03/10 23:25:02 joko Exp $ +// $Id: Encode.php,v 1.3 2004/06/16 15:17:03 joko Exp $ // ------------------------------------------------------------------------- // $Log: Encode.php,v $ +// Revision 1.3 2004/06/16 15:17:03 joko +// now also en-/decodes hash-keys +// // Revision 1.2 2003/03/10 23:25:02 joko // + fixed metadata for phpDocumentor // @@ -40,6 +43,7 @@ class Data_Encode { var $payload; + var $result; function Data_Encode(&$payload, $args = array()) { $this->payload = &$payload; @@ -49,12 +53,16 @@ return $this->payload; } + function get_result() { + return $this->result; + } + function toUTF8() { - $this->_iso_2_utf8($this->payload); + $this->_iso_2_utf8($this->payload, $this->result); } function toISO() { - $this->_utf8_2_iso($this->payload); + $this->_utf8_2_iso($this->payload, $this->result); } function toHTML() { @@ -62,7 +70,7 @@ } - function _utf8_2_iso(&$payload) { + function _utf8_2_iso_OLD(&$payload) { if (is_array($payload)) { foreach ($payload as $key => $val) { if (is_array($payload[$key])) { @@ -74,7 +82,7 @@ } } - function _iso_2_utf8(&$payload) { + function _iso_2_utf8_OLD(&$payload) { if (is_array($payload)) { foreach ($payload as $key => $val) { if (is_array($payload[$key])) { @@ -84,6 +92,34 @@ } } } + } + + function _utf8_2_iso(&$payload, &$result) { + if (is_array($payload)) { + foreach ($payload as $key => $val) { + if (is_array($val)) { + $this->_utf8_2_iso($val, $result[$key]); + } else { + $this->_utf8_2_iso_scalar($key); + $this->_utf8_2_iso_scalar($val); + $result[$key] = $val; + } + } + } + } + + function _iso_2_utf8(&$payload, &$result) { + if (is_array($payload)) { + foreach ($payload as $key => $val) { + if (is_array($val)) { + $this->_iso_2_utf8($val, $result[$key]); + } else { + $this->_iso_2_utf8_scalar($key); + $this->_iso_2_utf8_scalar($val); + $result[$key] = $val; + } + } + } } function _utf8_2_iso_scalar(&$scalar) {