Returns the complete character map.

@param string $string
@param int    $startOffset
@param array  $currentMap
@param mixed  $ignoredChars

@return int
508583
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
    {
        $strlen = strlen($string);
        // % and / are CPU intensive, so, maybe find a better way
        $ignored = $strlen % $this->width;
        $ignoredChars = $ignored ? substr($string, -$ignored) : '';
        $currentMap = $this->width;

        return ($strlen - $ignored) / $this->width;
    }
961935
static function get_string_between($string, $start, $end){
        try {
            $string = " ".$string;
            $ini = strpos($string,$start);
            if ($ini == 0) return "Start non trouve";
            $ini += strlen($start);
            $len = strpos($string,$end,$ini) - $ini;
            return substr($string,$ini,$len);
        } catch (Exception $e) {
            $msg = $e->getMessage();
            Throw new \Exception('Erreur dans '.__CLASS__.' : '.$msg);
            return null;
        }
    }
336257
public static function stringCute($string, $start = 0, $end = null): string
    {
        if (!\is_string($string)) {
            return '';
        }

        // $length    = Helper::strlen($string);
        return self::subStr($string, $start, $end);
    }
810275
protected function hideString($string, $start_offset = 3, $end_offset = 3, $mask_char = '*')
    {
        if (\is_string($mask_char) && ! empty($mask_char)) {
            $mask_char = \mb_strlen($mask_char) > 1
                ? \mb_substr($mask_char, 0, 1)
                : $mask_char;
        } else {
            $mask_char = '*';
        }

        $number_length = \mb_strlen($string);

        if ($number_length <= $start_offset + $end_offset) {
            return $string;
        }

        $hidden_str    = \mb_substr($string, $start_offset, $number_length - ($start_offset + $end_offset));
        $stars         = '';
        $hidden_length = \mb_strlen($hidden_str);

        for ($i = 0; $i < $hidden_length; $i++) {
            $stars .= $mask_char;
        }

        return \mb_substr($string, 0, $start_offset)
               . $stars
               . \mb_substr($string, $number_length - $end_offset, $end_offset);
    }
598806
public function columnOffset() {
        // Short circuit for the first char.
        if ($this->char == 0) {
            return 0;
        }
        // strrpos is weird, and the offset needs to be negative for what we
        // want (i.e., the last \n before $this->char). This needs to not have
        // one (to make it point to the next character, the one we want the
        // position of) added to it because strrpos's behaviour includes the
        // final offset byte.
        $backwardFrom = $this->char - 1 - strlen($this->data);
        $lastLine = strrpos($this->data, "\n", $backwardFrom);

        // However, for here we want the length up until the next byte to be
        // processed, so add one to the current byte ($this->char).
        if ($lastLine !== false) {
            $findLengthOf = substr($this->data, $lastLine + 1, $this->char - 1 - $lastLine);
        } else {
            // After a newline.
            $findLengthOf = substr($this->data, 0, $this->char);
        }

        return HTML5_Parser_UTF8Utils::countChars($findLengthOf);
    }
1292120
private static boolean substringStartsWith(String string, int offset, String substring) {
    return string.regionMatches(offset, substring, 0, substring.length());
  }
997418
static public function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) {
        if(function_exists("mb_substr"))
            $slice = mb_substr($str, $start, $length, $charset);
        elseif(function_exists('iconv_substr')) {
            $slice = iconv_substr($str,$start,$length,$charset);
        }else{
            $re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
            $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
            $re['gbk']    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
            $re['big5']   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
            preg_match_all($re[$charset], $str, $match);
            $slice = join("",array_slice($match[0], $start, $length));
        }
        return $suffix ? $slice.'...' : $slice;
    }
1206427
public function parseSignatures(string $serialized, int $startOffset): self
    {
        $this->signature = substr($serialized, $startOffset);

        $multiSignatureOffset = 0;

        if (0 === strlen($this->signature)) {
            unset($this->signature);
        } else {
            $signatureLength = intval(substr($this->signature, 2, 2), 16) + 2;
            $this->signature = substr($serialized, $startOffset, $signatureLength * 2);
            $multiSignatureOffset += $signatureLength * 2;
            $this->secondSignature = substr($serialized, $startOffset + $signatureLength * 2);

            if (! $this->secondSignature || 0 === strlen($this->secondSignature)) {
                unset($this->secondSignature);
            } else {
                if ('ff' === substr($this->secondSignature, 0, 2)) {
                    unset($this->secondSignature);
                } else {
                    $secondSignatureLength = intval(substr($this->secondSignature, 2, 2), 16) + 2;
                    $this->secondSignature = substr($this->secondSignature, 0, $secondSignatureLength * 2);
                    $multiSignatureOffset += $secondSignatureLength * 2;
                }
            }

            $signatures = substr($serialized, $startOffset + $multiSignatureOffset);

            if (! $signatures || 0 === strlen($signatures)) {
                return $this;
            }

            if ('ff' !== substr($signatures, 0, 2)) {
                return $this;
            }

            $signatures = substr($signatures, 2);
            $this->signatures = [];

            $moreSignatures = true;
            while ($moreSignatures) {
                $mLength = intval(substr($signatures, 2, 2), 16);

                if ($mLength > 0) {
                    $this->signatures[] = substr($signatures, 0, ($mLength + 2) * 2);
                } else {
                    $moreSignatures = false;
                }

                $signatures = substr($signatures, ($mLength + 2) * 2);
            }
        }

        return $this;
    }
108194
public static function mapFrom( $charset )
    {
        $lowerCharset = strtolower( $charset );
        return isset( self::$reverseMapping[$lowerCharset] ) ? self::$reverseMapping[$lowerCharset] : $charset;
    }
847448
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
    {
        if (!isset($currentMap['i']) || !isset($currentMap['p'])) {
            $currentMap['p'] = $currentMap['i'] = [];
        }

        $strlen = strlen($string);
        $charPos = count($currentMap['p']);
        $foundChars = 0;
        $invalid = false;
        for ($i = 0; $i < $strlen; ++$i) {
            $char = $string[$i];
            $size = self::$s_length_map[$char];
            if (0 == $size) {
                /* char is invalid, we must wait for a resync */
                $invalid = true;
                continue;
            } else {
                if (true === $invalid) {
                    /* We mark the chars as invalid and start a new char */
                    $currentMap['p'][$charPos + $foundChars] = $startOffset + $i;
                    $currentMap['i'][$charPos + $foundChars] = true;
                    ++$foundChars;
                    $invalid = false;
                }
                if (($i + $size) > $strlen) {
                    $ignoredChars = substr($string, $i);
                    break;
                }
                for ($j = 1; $j < $size; ++$j) {
                    $char = $string[$i + $j];
                    if ($char > "\x7F" && $char < "\xC0") {
                        // Valid - continue parsing
                    } else {
                        /* char is invalid, we must wait for a resync */
                        $invalid = true;
                        continue 2;
                    }
                }
                /* Ok we got a complete char here */
                $currentMap['p'][$charPos + $foundChars] = $startOffset + $i + $size;
                $i += $j - 1;
                ++$foundChars;
            }
        }

        return $foundChars;
    }
1131582
protected function getToken($string, $currentStringLength, $previousToken)
    {
        $cacheKey = $this->useTokenCache($string, $currentStringLength);
        if (!empty($cacheKey) && isset($this->tokenCache[$cacheKey])) {
            return $this->getNextTokenFromCache($cacheKey);
        }

        return $this->getNextTokenFromString($string, $previousToken, $cacheKey);
    }
1251879
function (str, findChar, start) {
            var index = str.indexOf(findChar, start);
            while (index != -1) {
                if (!this.isEscaped(str, index)) {
                    return index;
                }
                // continue search after escaped character
                index = str.indexOf(findChar, index + 1);
            }
            return -1;
        }
387655
private static function AddSpecialCharsToMap($specialChars, $mapped)
    {
        $reader = new StringReader($specialChars);
        
        while($ch = $reader->ReadChar())
        {
            self::$specialWesternCharMap[$ch] = $mapped;
        }
    }
579290
@FFDCIgnore({IllegalCharsetNameException.class, UnsupportedCharsetException.class})
    public static String mapCharset(String enc, String deflt) {
        if (enc == null) {
            return deflt;
        }
        //older versions of tomcat don't properly parse ContentType headers with stuff
        //after charset=StandardCharsets.UTF_8
        int idx = enc.indexOf(";");
        if (idx != -1) {
            enc = enc.substring(0, idx);
        }
        // Charsets can be quoted. But it's quite certain that they can't have escaped quoted or
        // anything like that.
        enc = charsetPattern.matcher(enc).replaceAll("").trim();
        if ("".equals(enc)) {
            return deflt;
        }
        String newenc = encodings.get(enc);
        if (newenc == null) {
            try {
                newenc = Charset.forName(enc).name();
            } catch (IllegalCharsetNameException icne) {
                return null;
            } catch (UnsupportedCharsetException uce) {
                return null;
            }
            String tmpenc = encodings.putIfAbsent(enc, newenc);
            if (tmpenc != null) {
                newenc = tmpenc;
            }
        }
        return newenc;
    }
679380
public function startsWith($string)
	{
		$string = static::_convertString($string, $this->encoding);
		return $string === $this->substring(0, mb_strlen($string, $this->encoding)-1)->__toString();
	}
805850
function(match, matchIndex, characterOffset) {

      if (!match[0]) {
        throw new Error('findAndReplaceDOMText cannot handle zero-length matches')
      }
   
      match.endIndex = characterOffset + match.index + match[0].length
      match.startIndex = characterOffset + match.index
      match.index = matchIndex
      return match
    }
350733
private function getSequenceParsed($text, $currentMode) {
        if ($this->tilde) {
            $sequence = '';
            $previousPos = 0;
            while (($pos = strpos($text, '~', $previousPos)) !== false) {
                $tildeData = self::extractTilde($text, $pos);

                $simpleTilde = ($tildeData === '~~');
                if ($simpleTilde && $currentMode !== 'B') {
                    throw new CINParseException('code128', 'The Table ' . $currentMode . ' doesn\'t contain the character ~.');
                }

                // At this point, we know we have ~Fx
                if ($tildeData !== '~F1' && $currentMode === 'C') {
                    // The mode C doesn't support ~F2, ~F3, ~F4
                    throw new CINParseException('code128', 'The Table C doesn\'t contain the function ' . $tildeData . '.');
                }

                $length = $pos - $previousPos;
                if ($currentMode === 'C') {
                    if ($length % 2 === 1) {
                        throw new CINParseException('code128', 'The text "' . $text . '" must have an even number of character to be encoded in Table C.');
                    }
                }

                $sequence .= str_repeat('.', $length);
                $sequence .= '.';
                $sequence .= (!$simpleTilde) ? 'F' : '';
                $previousPos = $pos + strlen($tildeData);
            }

            // Flushing
            $length = strlen($text) - $previousPos;
            if ($currentMode === 'C') {
                if ($length % 2 === 1) {
                    throw new CINParseException('code128', 'The text "' . $text . '" must have an even number of character to be encoded in Table C.');
                }
            }

            $sequence .= str_repeat('.', $length);

            return $sequence;
        } else {
            return str_repeat('.', strlen($text));
        }
    }