/[cvs]/nfo/php/libs/org.netfrag.glib/Data/Encode.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.glib/Data/Encode.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Wed Jun 16 15:17:03 2004 UTC (20 years, 2 months ago) by joko
Branch: MAIN
Changes since 1.2: +41 -5 lines
now also en-/decodes hash-keys

1 <?
2 /**
3 * This file contains the Data::Encode class.
4 *
5 * @author Andreas Motl <andreas.motl@ilo.de>
6 * @package org.netfrag.glib
7 * @name Data::Encode
8 *
9 */
10
11 // -------------------------------------------------------------------------
12 // $Id: Encode.php,v 1.2 2003/03/10 23:25:02 joko Exp $
13 // -------------------------------------------------------------------------
14 // $Log: Encode.php,v $
15 // Revision 1.2 2003/03/10 23:25:02 joko
16 // + fixed metadata for phpDocumentor
17 //
18 // Revision 1.1 2003/02/03 14:49:37 joko
19 // + initial commit
20 // + refactored from flib/Application/i18n/TextEncode.php
21 //
22 // Revision 1.2 2003/02/03 03:40:02 jonen
23 // + added function 'toHTML()', for deep asci_2_html encoding (using htmlentities() )
24 //
25 // Revision 1.1 2002/11/12 05:42:30 joko
26 // + initial checkin
27 //
28 // -------------------------------------------------------------------------
29
30
31 /**
32 * --- Data::Encode
33 *
34 * @author Andreas Motl <andreas.motl@ilo.de>
35 * @package org.netfrag.glib
36 * @subpackage Data
37 * @name Data::Encode
38 *
39 */
40 class Data_Encode {
41
42 var $payload;
43 var $result;
44
45 function Data_Encode(&$payload, $args = array()) {
46 $this->payload = &$payload;
47 }
48
49 function &get() {
50 return $this->payload;
51 }
52
53 function get_result() {
54 return $this->result;
55 }
56
57 function toUTF8() {
58 $this->_iso_2_utf8($this->payload, $this->result);
59 }
60
61 function toISO() {
62 $this->_utf8_2_iso($this->payload, $this->result);
63 }
64
65 function toHTML() {
66 $this->_asci_2_html($this->payload);
67 }
68
69
70 function _utf8_2_iso_OLD(&$payload) {
71 if (is_array($payload)) {
72 foreach ($payload as $key => $val) {
73 if (is_array($payload[$key])) {
74 $this->_utf8_2_iso($payload[$key]);
75 } else {
76 $this->_utf8_2_iso_scalar($payload[$key]);
77 }
78 }
79 }
80 }
81
82 function _iso_2_utf8_OLD(&$payload) {
83 if (is_array($payload)) {
84 foreach ($payload as $key => $val) {
85 if (is_array($payload[$key])) {
86 $this->_iso_2_utf8($payload[$key]);
87 } else {
88 $this->_iso_2_utf8_scalar($payload[$key]);
89 }
90 }
91 }
92 }
93
94 function _utf8_2_iso(&$payload, &$result) {
95 if (is_array($payload)) {
96 foreach ($payload as $key => $val) {
97 if (is_array($val)) {
98 $this->_utf8_2_iso($val, $result[$key]);
99 } else {
100 $this->_utf8_2_iso_scalar($key);
101 $this->_utf8_2_iso_scalar($val);
102 $result[$key] = $val;
103 }
104 }
105 }
106 }
107
108 function _iso_2_utf8(&$payload, &$result) {
109 if (is_array($payload)) {
110 foreach ($payload as $key => $val) {
111 if (is_array($val)) {
112 $this->_iso_2_utf8($val, $result[$key]);
113 } else {
114 $this->_iso_2_utf8_scalar($key);
115 $this->_iso_2_utf8_scalar($val);
116 $result[$key] = $val;
117 }
118 }
119 }
120 }
121
122 function _utf8_2_iso_scalar(&$scalar) {
123 $scalar = utf8_decode($scalar);
124 }
125
126 function _iso_2_utf8_scalar(&$scalar) {
127 $scalar = utf8_encode($scalar);
128 }
129
130 function _asci_2_html_scalar(&$scalar) {
131 $scalar = htmlentities( trim($scalar) );
132 }
133
134 function _asci_2_html(&$payload) {
135 if (is_array($payload)) {
136 foreach ($payload as $key => $val) {
137 if (is_array($payload[$key])) {
138 $this->_asci_2_html($payload[$key]);
139 } else {
140 $this->_asci_2_html_scalar($payload[$key]);
141 }
142 }
143 }
144 }
145
146
147 }
148
149 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed