24 const BYTES_PER_LINE = 16;
29 private $currentHexText;
53 private $highlightState;
61 parent::__construct($startOffset);
62 $this->highlightState = $highlightState;
64 $this->resetLineData();
68 public function getText()
70 $text = parent::getText();
72 if ($this->charCount > 0) {
78 public function appendMetaText($text)
80 if (strlen($text) > 0) {
81 $this->charText .= $text;
82 $this->currentHexText .= $text;
93 $usableCharacters =
min(self::BYTES_PER_LINE - $this->charCount, strlen($text));
94 $usedCharacters = substr($text, 0, $usableCharacters);
95 $text = substr($text, $usableCharacters);
97 $this->charText .= preg_replace(
"/\\s/",
" ", $escapedText);
99 if (strlen($this->currentHexText) > 0) {
102 $this->hexTexts = array_merge($this->hexTexts, $asHexStrings);
103 $this->charCount += strlen($usedCharacters);
105 if ($this->charCount == self::BYTES_PER_LINE) {
106 $this->highlightState->closeOpenElements($this);
107 if (strlen($this->currentHexText) > 0) {
108 $this->
mergeMetaText($this->hexTexts, count($this->hexTexts) - 1,
false);
112 parent::appendMetaText($result .
"<br/>\n");
113 $this->resetLineData();
114 $this->highlightState->openExistingElements($this);
128 $hexValues = array();
129 for ($i = 0; $i < strlen($text); $i ++) {
130 $hexValues[] = sprintf(
"%02x", ord($text[$i]));
140 $missingCharacters = self::BYTES_PER_LINE - $this->charCount;
141 $charTextFill = str_repeat(
" ", $missingCharacters);
142 $hexTextFill = str_repeat(
" __", $missingCharacters);
144 $hexText = implode(
" ", $this->hexTexts) . $hexTextFill;
145 $charText = $this->charText . $charTextFill;
146 $currentOffset = $this->
getStartOffset() + $this->lineCount * self::BYTES_PER_LINE;
147 return "0x" . sprintf(
"%08X", $currentOffset) .
" |" . $hexText .
"| |" . $charText .
"|";
150 protected function resetLineData()
152 $this->currentHexText =
"";
153 $this->hexTexts = array();
154 $this->charText =
"";
155 $this->charCount = 0;
164 protected function mergeMetaText(&$targetArray, $targetIndex, $prependMeta =
true)
166 $targetArray[$targetIndex] =
168 ? $this->currentHexText . $targetArray[$targetIndex]
169 : $targetArray[$targetIndex] . $this->currentHexText;
170 $this->currentHexText =
"";
180 for ($i = 0; $i < strlen($usedCharacters); $i ++) {
181 $character = $usedCharacters[$i];
182 $encodedText .= ctype_print($character) || ctype_space($character) ? htmlspecialchars($character) :
'?';
FUNCTION int min(int user_perm, int permExternal)
Get the minimum permission level required.
mergeMetaText(&$targetArray, $targetIndex, $prependMeta=true)
encodeCharacters($usedCharacters)
__construct($startOffset, HighlightState $highlightState)