9 namespace Fossology\Lib\View;
13 const BYTES_PER_LINE = 16;
18 private $currentHexText;
42 private $highlightState;
50 parent::__construct($startOffset);
51 $this->highlightState = $highlightState;
53 $this->resetLineData();
59 $text = parent::getText();
61 if ($this->charCount > 0) {
69 if (strlen($text) > 0) {
70 $this->charText .= $text;
71 $this->currentHexText .= $text;
82 $usableCharacters =
min(self::BYTES_PER_LINE - $this->charCount, strlen($text));
83 $usedCharacters = substr($text, 0, $usableCharacters);
84 $text = substr($text, $usableCharacters);
86 $this->charText .= preg_replace(
"/\\s/",
" ", $escapedText);
88 if (strlen($this->currentHexText) > 0) {
91 $this->hexTexts = array_merge($this->hexTexts, $asHexStrings);
92 $this->charCount += strlen($usedCharacters);
94 if ($this->charCount == self::BYTES_PER_LINE) {
95 $this->highlightState->closeOpenElements($this);
96 if (strlen($this->currentHexText) > 0) {
97 $this->
mergeMetaText($this->hexTexts, count($this->hexTexts) - 1,
false);
101 parent::appendMetaText($result .
"<br/>\n");
102 $this->resetLineData();
103 $this->highlightState->openExistingElements($this);
117 $hexValues = array();
118 for ($i = 0; $i < strlen($text); $i ++) {
119 $hexValues[] = sprintf(
"%02x", ord($text[$i]));
129 $missingCharacters = self::BYTES_PER_LINE - $this->charCount;
130 $charTextFill = str_repeat(
" ", $missingCharacters);
131 $hexTextFill = str_repeat(
" __", $missingCharacters);
133 $hexText = implode(
" ", $this->hexTexts) . $hexTextFill;
134 $charText = $this->charText . $charTextFill;
135 $currentOffset = $this->
getStartOffset() + $this->lineCount * self::BYTES_PER_LINE;
136 return "0x" . sprintf(
"%08X", $currentOffset) .
" |" . $hexText .
"| |" . $charText .
"|";
139 protected function resetLineData()
141 $this->currentHexText =
"";
142 $this->hexTexts = array();
143 $this->charText =
"";
144 $this->charCount = 0;
153 protected function mergeMetaText(&$targetArray, $targetIndex, $prependMeta =
true)
155 $targetArray[$targetIndex] =
157 ? $this->currentHexText . $targetArray[$targetIndex]
158 : $targetArray[$targetIndex] . $this->currentHexText;
159 $this->currentHexText =
"";
169 for ($i = 0; $i < strlen($usedCharacters); $i ++) {
170 $character = $usedCharacters[$i];
171 $encodedText .= ctype_print($character) || ctype_space($character) ? htmlspecialchars($character) :
'?';
mergeMetaText(&$targetArray, $targetIndex, $prependMeta=true)
__construct($startOffset, HighlightState $highlightState)
encodeCharacters($usedCharacters)
FUNCTION int min(int user_perm, int permExternal)
Get the minimum permission level required.