从指定位置开始逐一扫描文本，如果扫描到敏感词，则返回敏感词长度。
如果扫描的第一个字符不是敏感词头，则直接返回0。

@param $text
@param $beginIndex
@param $length
@return int
15094
protected function _check($text, $beginIndex, $length)
    {
        $flag = false;
        $word_length = 0;
        if ($this->_matchCase) {
            $trie_tree = &$this->_wordsTrieTree;
        } else {
            $trie_tree = &$this->_wordsTrieTreeLowCase; // 引用第一层词源。
        }
        for ($i = $beginIndex; $i < $length; $i++) {
            $word = mb_substr($text, $i, 1);
            if (in_array($word, $this->_disturbList)) { // 检查是不是干扰字，是的话指针往前走一步。
                $word_length++;
                continue;
            }
            if (!isset($trie_tree[$word])) { // 一旦发现没有匹配敏感词，则直接跳出。
                break;
            }
            $word_length++;
            if ($trie_tree[$word] !== false) { // 看看是否到达词尾。
                $trie_tree = &$trie_tree[$word]; // 往深层引用，继续检索。
            } else {
                $flag = true;
            }
        }
        $flag || $word_length = 0; // 如果检查到最后一个字条还没有匹配到词尾，则当作没有匹配到。
        return $word_length;
    }
607996
private static boolean followingCharsAre(String str, int startIndex, String nextChars) {
        return (str.indexOf(nextChars, startIndex + 1) == (startIndex + 1));
    }
276909
@SuppressWarnings({ "rawtypes"})
	public int checkSensitiveWord(String txt,int beginIndex,MatchType matchType){
		boolean  flag = false;    //敏感词结束标识位：用于敏感词只有1位的情况
		int matchFlag = 0;     //匹配标识数默认为0
		char word = 0;
		Map nowMap = sensitiveWordMap;
		for(int i = beginIndex; i < txt.length() ; i++){
			word = txt.charAt(i);
			nowMap = (Map) nowMap.get(word);     //获取指定key
			if(nowMap != null){     //存在，则判断是否为最后一个
				matchFlag++;     //找到相应key，匹配标识+1 
				if("1".equals(nowMap.get("isEnd"))){       //如果为最后一个匹配规则,结束循环，返回匹配标识数
					flag = true;       //结束标志位为true   
					if(matchType==MatchType.minMatch){    //最小规则，直接返回,最大规则还需继续查找
						break;
					}
				}
			}
			else{     //不存在，直接返回
				break;
			}
		}
		if(matchFlag < 2 || !flag){        //长度必须大于等于1，为词 
			matchFlag = 0;
		}
		return matchFlag;
	}
1265377
private function changeDelimiters($text, $index)
    {
        $startIndex = strpos($text, '=', $index) + 1;
        $close      = '=' . $this->ctag;
        $closeIndex = strpos($text, $close, $index);

        $this->setDelimiters(trim(substr($text, $startIndex, $closeIndex - $startIndex)));

        $this->tokens[] = array(
            self::TYPE => self::T_DELIM_CHANGE,
            self::LINE => $this->line,
        );

        return $closeIndex + strlen($close) - 1;
    }
581990
public function prepare($text, $length = 100, $endString = '...')
    {
        $substring = strip_tags(preg_replace('/<br.?\/?>/', ' ',$text));
        $textLength = mb_strlen($substring);
        
        if($textLength > $length) {
            $lastWordPosition = mb_strpos($substring, ' ', $length);
            
            if($lastWordPosition) {
                $substring = mb_substr($substring, 0, $lastWordPosition);
            } else {
                $substring = mb_substr($substring, 0, $length);
            }
            
            $substring.= $endString;
        }
        
        return $substring;
    }
1032481
private static int compare(final char[] cer, final String text, final int start, final int end) {
        final int textLen = end - start;
        final int maxCommon = Math.min(cer.length, textLen);
        int i;
        // char 0 is discarded, will be & in both cases
        for (i = 1; i < maxCommon; i++) {
            final char tc = text.charAt(start + i);
            if (cer[i] < tc) {
                return -1;
            } else if (cer[i] > tc) {
                return 1;
            }
        }
        if (cer.length > i) {
            return 1;
        }
        if (textLen > i) {
            return -1;
        }
        return 0;
    }
1260603
public final T substr(int beginIndex) {
        if (beginIndex < 0) {
            throw new StringIndexOutOfBoundsException(beginIndex);
        }
        return (beginIndex == 0) ? me() : substr(beginIndex, size());
    }
309143
private static final String getString(CharacterIterator text, int start, int length) {
        StringBuilder result = new StringBuilder(length);
        int offset = text.getIndex();
        text.setIndex(start);
        for (int i = 0; i < length; i++) {
            result.append(text.current());
            text.next();
        }
        text.setIndex(offset);
        return result.toString();
    }
465902
public static function SubstringWithLength( $item, $startingLoc, $length )
	{
		if ( $item instanceof Undefined )
		{
			return "";
		}

		$value = (string)$item; // . "";

		if ( $startingLoc instanceof XPath2Item )
		{
			$startingLoc = $startingLoc->getTypedValue();
		}

		if ( $length instanceof XPath2Item )
		{
			$length = $length->getTypedValue();
		}

		if ( $startingLoc == INF ||  $startingLoc == -INF || is_nan( $startingLoc ) || $length == -INF || is_nan( $length ) )
		{
			return "";
		}

		$pos = intval( Round( $startingLoc ) ) - 1;
		$len;
		if ( $length == INF )
		    $len = PHP_INT_MAX;
		else
		    $len = intval( Round( $length ) );

		if ( $pos < 0 )
		{
		    $len = $len + $pos;
		    $pos = 0;
		}

		if ( $pos < strlen( $value ) )
		{
		    if ( $pos + $len > strlen( $value ) )
			   $len = strlen( $value ) - $pos;

		    if ( $len > 0 )
			   return substr( $value, $pos, $len );
		}
		return "";
	}
708123
public StringExpression substring(Expression<Integer> beginIndex, Expression<Integer> endIndex) {
        return Expressions.stringOperation(Ops.SUBSTR_2ARGS, mixin, beginIndex, endIndex);
    }
1115730
public function subString($startPosition, $length)
    {
        if (!$this->isNumber($startPosition)) {
            throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [
                '$startPosition',
                'integer'
            ]);
        }

        if (!$this->isNumber($length)) {
            throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [
                '$length',
                'integer'
            ]);
        }

        if ($length == 0) {
            $length = null;
        }
        $value = mb_substr($this->val(), $startPosition, $length, self::DEF_ENCODING);
        $this->val($value);

        return $this;
    }
413751
public static function sub($string, $start, $length = 0)
    {
        if (self::isMBString()) {
            if (0 === $length) {
                $length = self::len($string);
            }

            return mb_substr($string, $start, $length, self::$encoding);
        }

        return substr($string, $start, $length); // @codeCoverageIgnore
    }
1316185
public static function truncateText($text, $length = 30, $truncate_string = '...', $truncate_lastspace = false)
    {
        if ($text == '') {
            return '';
        }

        $mbstring = extension_loaded('mbstring');
        if ($mbstring) {
            $old_encoding = mb_internal_encoding();
            mb_internal_encoding(mb_detect_encoding($text));
        }
        $strlen = ($mbstring) ? 'mb_strlen' : 'strlen';
        $substr = ($mbstring) ? 'mb_substr' : 'substr';
        if ($strlen($text) > $length) {
            $truncate_text = $substr($text, 0, $length - $strlen($truncate_string));
            if ($truncate_lastspace) {
                $truncate_text = preg_replace('/\s+?(\S+)?$/', '', $truncate_text);
            }
            $text = $truncate_text.$truncate_string;
        }
        if ($mbstring) {
            mb_internal_encoding($old_encoding);
        }

        return $text;
    }
616167
private function longestCommonPrefixLength($string1, $string2)
    {
        $length = min(strlen($string1), strlen($string2));
        $index  = 0;

        while ($index < $length) {
            if ($string1[$index] !== $string2[$index]) {
                break;
            }

            ++$index;
        }

        return $index;
    }
1278149
private function walkEdge(string $s, int $i, int $start, int $end): int
    {
        $text = $this->getS();
        for ($k = $start; $k <= $end && $i < strlen($s); $k++, $i++) {
            if ($text{$k} !== $s{$i}) {
                return -1;
            }
        }
        if (strlen($s) === $i) {
            return $k > $end ? 2 : 1;
        }
        return 0;
    }
32633
public static function substrForGbk($string, $start, $length = null, $dot = false)
	{
		$l = strlen($string);
		$p = $s = 0;
		if (0 !== $start)
		{
			while ($start-- && $p < $l)
			{
				if ($string[$p] > "\x80")
					$p += 2;
				else
					$p++;
			}
			$s = $p;
		}
		
		if (empty($length))
		{
			$t = substr($string, $s);
		}
		else
		{
			$i = $length;
			while ($i-- && $p < $l)
			{
				if ($string[$p] > "\x80")
					$p += 2;
				else
					$p++;
			}
			$t = substr($string, $s, $p - $s);
		}
		
		$dot && ($p < $l) && $t .= "...";
		return $t;
	}
1054896
public static function substring($string, $start = 0, $length = null)
    {
        if (!self::isValid($string)) {
            return false;
        }

        return mb_substr($string, $start, $length);
    }