/**
  * Returns backslash encoded numeric format. Does not use backslash
  * character escapes such as, \" or \' as these may cause parsing problems.
  * For example, if a javascript attribute, such as onmouseover, contains
  * a \" that will close the entire attribute and allow an attacker to inject
  * another script attribute.
  *
  * @param string $character utf-8 character that needs to be encoded
  * @return string encoded character
  */
 protected function encodeCharacter($character)
 {
     if ($this->isImmuneCharacter($character)) {
         return $character;
     }
     $ordinalValue = $this->charsetConversion->utf8CharToUnumber($character);
     // Check for alphanumeric characters
     $hex = $this->getHexForNonAlphanumeric($ordinalValue);
     if ($hex === NULL) {
         return $character;
     }
     // Encode up to 256 with \\xHH
     if ($ordinalValue < 256) {
         $pad = substr('00', strlen($hex));
         return '\\x' . $pad . strtoupper($hex);
     }
     // Otherwise encode with \\uHHHH
     $pad = substr('0000', strlen($hex));
     return '\\u' . $pad . strtoupper($hex);
 }
 /**
  * Splitting a string for ImageTTFBBox up into an array where each part has its own configuration options.
  *
  * @param string $string UTF-8 string
  * @param array $splitRendering Split-rendering configuration from GIFBUILDER TEXT object.
  * @param int $fontSize Current fontsize
  * @param string $fontFile Current font file
  * @return array Array with input string splitted according to configuration
  */
 public function splitString($string, $splitRendering, $fontSize, $fontFile)
 {
     // Initialize by setting the whole string and default configuration as the first entry.
     $result = array();
     $result[] = array('str' => $string, 'fontSize' => $fontSize, 'fontFile' => $fontFile);
     // Traverse the split-rendering configuration:
     // Splitting will create more entries in $result with individual configurations.
     if (is_array($splitRendering)) {
         $sKeyArray = TemplateService::sortedKeyList($splitRendering);
         // Traverse configured options:
         foreach ($sKeyArray as $key) {
             $cfg = $splitRendering[$key . '.'];
             // Process each type of split rendering keyword:
             switch ((string) $splitRendering[$key]) {
                 case 'highlightWord':
                     if ((string) $cfg['value'] !== '') {
                         $newResult = array();
                         // Traverse the current parts of the result array:
                         foreach ($result as $part) {
                             // Explode the string value by the word value to highlight:
                             $explodedParts = explode($cfg['value'], $part['str']);
                             foreach ($explodedParts as $c => $expValue) {
                                 if ((string) $expValue !== '') {
                                     $newResult[] = array_merge($part, array('str' => $expValue));
                                 }
                                 if ($c + 1 < count($explodedParts)) {
                                     $newResult[] = array('str' => $cfg['value'], 'fontSize' => $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], 'fontFile' => $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'], 'color' => $cfg['color'], 'xSpaceBefore' => $cfg['xSpaceBefore'], 'xSpaceAfter' => $cfg['xSpaceAfter'], 'ySpaceBefore' => $cfg['ySpaceBefore'], 'ySpaceAfter' => $cfg['ySpaceAfter']);
                                 }
                             }
                         }
                         // Set the new result as result array:
                         if (!empty($newResult)) {
                             $result = $newResult;
                         }
                     }
                     break;
                 case 'charRange':
                     if ((string) $cfg['value'] !== '') {
                         // Initialize range:
                         $ranges = GeneralUtility::trimExplode(',', $cfg['value'], true);
                         foreach ($ranges as $i => $rangeDef) {
                             $ranges[$i] = GeneralUtility::intExplode('-', $ranges[$i]);
                             if (!isset($ranges[$i][1])) {
                                 $ranges[$i][1] = $ranges[$i][0];
                             }
                         }
                         $newResult = array();
                         // Traverse the current parts of the result array:
                         foreach ($result as $part) {
                             // Initialize:
                             $currentState = -1;
                             $bankAccum = '';
                             // Explode the string value by the word value to highlight:
                             $utf8Chars = $this->csConvObj->utf8_to_numberarray($part['str'], true, true);
                             foreach ($utf8Chars as $utfChar) {
                                 // Find number and evaluate position:
                                 $uNumber = (int) $this->csConvObj->utf8CharToUnumber($utfChar);
                                 $inRange = 0;
                                 foreach ($ranges as $rangeDef) {
                                     if ($uNumber >= $rangeDef[0] && (!$rangeDef[1] || $uNumber <= $rangeDef[1])) {
                                         $inRange = 1;
                                         break;
                                     }
                                 }
                                 if ($currentState == -1) {
                                     $currentState = $inRange;
                                 }
                                 // Initialize first char
                                 // Switch bank:
                                 if ($inRange != $currentState && $uNumber !== 9 && $uNumber !== 10 && $uNumber !== 13 && $uNumber !== 32) {
                                     // Set result:
                                     if ($bankAccum !== '') {
                                         $newResult[] = array('str' => $bankAccum, 'fontSize' => $currentState && $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], 'fontFile' => $currentState && $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'], 'color' => $currentState ? $cfg['color'] : '', 'xSpaceBefore' => $currentState ? $cfg['xSpaceBefore'] : '', 'xSpaceAfter' => $currentState ? $cfg['xSpaceAfter'] : '', 'ySpaceBefore' => $currentState ? $cfg['ySpaceBefore'] : '', 'ySpaceAfter' => $currentState ? $cfg['ySpaceAfter'] : '');
                                     }
                                     // Initialize new settings:
                                     $currentState = $inRange;
                                     $bankAccum = '';
                                 }
                                 // Add char to bank:
                                 $bankAccum .= $utfChar;
                             }
                             // Set result for FINAL part:
                             if ($bankAccum !== '') {
                                 $newResult[] = array('str' => $bankAccum, 'fontSize' => $currentState && $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], 'fontFile' => $currentState && $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'], 'color' => $currentState ? $cfg['color'] : '', 'xSpaceBefore' => $currentState ? $cfg['xSpaceBefore'] : '', 'xSpaceAfter' => $currentState ? $cfg['xSpaceAfter'] : '', 'ySpaceBefore' => $currentState ? $cfg['ySpaceBefore'] : '', 'ySpaceAfter' => $currentState ? $cfg['ySpaceAfter'] : '');
                             }
                         }
                         // Set the new result as result array:
                         if (!empty($newResult)) {
                             $result = $newResult;
                         }
                     }
                     break;
             }
         }
     }
     return $result;
 }