Skip to content

Commit

Permalink
Merge pull request #237 from eexit/revert-single-quote-sprintf
Browse files Browse the repository at this point in the history
Stick to single quote convention + minor changes
  • Loading branch information
videlalvaro committed Jan 16, 2015
2 parents f11232f + 9061c8a commit 64daa14
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions PhpAmqpLib/Helper/MiscHelper.php
Expand Up @@ -67,23 +67,23 @@ public static function hexdump($data, $htmloutput = true, $uppercase = false, $r
// Init
$hexi = '';
$ascii = '';
$dump = ($htmloutput === true) ? '<pre>' : '';
$dump = $htmloutput ? '<pre>' : '';
$offset = 0;
$len = mb_strlen($data, 'ASCII');

// Upper or lower case hexidecimal
$x = ($uppercase === false) ? 'x' : 'X';
$hexFormat = $uppercase ? 'X' : 'x';

// Iterate string
for ($i = $j = 0; $i < $len; $i++) {
// Convert to hexidecimal
$hexi .= sprintf("%02$x ", ord($data[$i]));
// We must use concatenation here because the $hexFormat value
// is needed for sprintf() to parse the format
$hexi .= sprintf('%02' . $hexFormat . ' ', ord($data[$i]));

// Replace non-viewable bytes with '.'
if (ord($data[$i]) >= 32) {
$ascii .= ($htmloutput === true) ?
htmlentities($data[$i]) :
$data[$i];
$ascii .= $htmloutput ? htmlentities($data[$i]) : $data[$i];
} else {
$ascii .= '.';
}
Expand All @@ -97,7 +97,9 @@ public static function hexdump($data, $htmloutput = true, $uppercase = false, $r
// Add row
if (++$j === 16 || $i === $len - 1) {
// Join the hexi / ascii output
$dump .= sprintf("%04$x %-49s %s", $offset, $hexi, $ascii);
// We must use concatenation here because the $hexFormat value
// is needed for sprintf() to parse the format
$dump .= sprintf('%04' . $hexFormat . ' %-49s %s', $offset, $hexi, $ascii);

// Reset vars
$hexi = $ascii = '';
Expand All @@ -112,14 +114,13 @@ public static function hexdump($data, $htmloutput = true, $uppercase = false, $r
}

// Finish dump
$dump .= $htmloutput === true ? '</pre>' : '';
$dump .= $htmloutput ? '</pre>' : '';
$dump .= PHP_EOL;

// Output method
if ($return === false) {
echo $dump;
} else {
if ($return) {
return $dump;
}

echo $dump;
}
}

0 comments on commit 64daa14

Please sign in to comment.