MCPcopy Create free account
hub / github.com/apache/avro / asciiArray

Method asciiArray

lang/php/lib/AvroDebug.php:148–230  ·  view source on GitHub ↗

* @param string $str * @param string $format one of 'ctrl', 'hex', or 'dec' for control, * hexadecimal, or decimal format for bytes. * - ctrl: ASCII control characters represented as text. * For example, the null byte is represented as 'NUL'. * Visible ASCII characters represent themselves, and * others are represented as a decimal ('%03d') * - hex: bytes represe

($str, $format = 'ctrl')

Source from the content-addressed store, hash-verified

146 * @throws AvroException
147 */
148 public static function asciiArray($str, $format = 'ctrl')
149 {
150 if (!in_array($format, ['ctrl', 'hex', 'dec'])) {
151 throw new AvroException('Unrecognized format specifier');
152 }
153
154 $ctrl_chars = array(
155 'NUL',
156 'SOH',
157 'STX',
158 'ETX',
159 'EOT',
160 'ENQ',
161 'ACK',
162 'BEL',
163 'BS',
164 'HT',
165 'LF',
166 'VT',
167 'FF',
168 'CR',
169 'SO',
170 'SI',
171 'DLE',
172 'DC1',
173 'DC2',
174 'DC3',
175 'DC4',
176 'NAK',
177 'SYN',
178 'ETB',
179 'CAN',
180 'EM',
181 'SUB',
182 'ESC',
183 'FS',
184 'GS',
185 'RS',
186 'US'
187 );
188 $x = array();
189 foreach (str_split($str) as $b) {
190 $db = ord($b);
191 if ($db < 32) {
192 switch ($format) {
193 case 'ctrl':
194 $x[] = str_pad($ctrl_chars[$db], 3, ' ', STR_PAD_LEFT);
195 break;
196 case 'hex':
197 $x[] = sprintf("x%02X", $db);
198 break;
199 case 'dec':
200 $x[] = str_pad($db, 3, '0', STR_PAD_LEFT);
201 break;
202 }
203 } else {
204 if ($db < 127) {
205 $x[] = " $b";

Callers 1

asciiStringMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected