Détecte si on est au début ou à la fin d'un bloc de code.
@param    string $string La chaîne à analyser.
@param    bool $inBlock (optional) True if the parser is already in the block.
@return    bool    True si le début ou la fin de bloc a été trouvée.
356097
public function detect($string, $inBlock = false)
    {
        $this->_detectMatch = false;
        if ($this->isOpen) {
            if (self::isMyLine($string)) {
                $this->needsClosing = true;
                return true;
            }

            if (!$this->needsClosing) {
                $this->_currentContent .= $string . "\n";
                return true;
            }

            return false;
        } else if (self::isMyLine($string)) {
            $this->needsClosing = false;
            $this->_programmingLanguage = trim(substr($string, 3));
            return true;
        }
        $this->isOpen = false;
        return false;
    }
719000
private static function debugHasKnownBlockType(array $block): bool
    {
        $result = false;

        if (array_key_exists(BlockSerializer::TYPE, $block) === true) {
            $type = $block[BlockSerializer::TYPE];

            $result =
                $type === BlockSerializer::TYPE__PROCEDURE ||
                $type === BlockSerializer::TYPE__AND_EXPRESSION ||
                $type === BlockSerializer::TYPE__OR_EXPRESSION ||
                $type === BlockSerializer::TYPE__IF_EXPRESSION;
        }

        return $result;
    }
642885
public function parse_docblock(string $block){
    $b = [
			'description' => '',
			'tags' => []
		];
    // Remove start pattern
    //$block = trim(substr($block, 3));
		// Remove end pattern
		$block = trim(substr($block, 0, strlen($block) - 2));
		// Tags
    $tags = $this->get_tags($block);
    foreach ( $tags as $i => $tag ){
			if (
				(
					isset($tags[$i+1]) &&
					($t = $this->parse_tag(substr($block, $tag[1], $tags[$i+1][1] - $tag[1])))
        ) ||
				($t = $this->parse_tag(substr($block, $tag[1])))
			){
				$b['tags'][] = $t;
			}
    }
    // Get Description
    $b['description'] = $this->clear_text(isset($tags[0]) ? substr($block, 3, $tags[0][1]-1) : substr($block, 3));
    return $b;
  }
82054
public function readString($string)
    {
        if (!is_string($string))
            throw new IniReadingException('The expected type is string');

        // PHP 5.3.3, an empty line return is needed at the end.
        $string .= "\n";

        $data = @parse_ini_string($string, true);
        if ($data === false) {
            $e = error_get_last();
            throw new IniReadingException('Syntax error in INI configuration: ' . $e['message']);
        }

        $rawValues = @parse_ini_string($string, true, INI_SCANNER_RAW);

        return $this->toCollection($this->decode($data, $rawValues));
    }
435583
public static function isPoint($string)
    {
        if (gettype($string) === 'string') {
            $parts = explode("\x20", $string);
            if (count($parts) == 2) {
                if (self::isInteger($parts[0]) && self::isInteger($parts[1])) {
                    return true;
                }
            }
        }

        return false;
    }
1327052
private function parseBlock($text, &$lines)
    {
        $lines = explode("\n", $text);
        $this->_blocks = array();
        $this->_current = 'normal';
        $this->_pos = -1;
        $state = array(
            'special'   =>  implode("|", array_keys($this->_specialWhiteList)),
            'empty'     =>  0,
            'html'      =>  false
        );
        // analyze by line
        foreach ($lines as $key => $line) {
            $block = $this->getBlock();
            $args = array($block, $key, $line, &$state, $lines);
            if ($this->_current != 'normal') {
                $pass = call_user_func_array($this->_parsers[$this->_current], $args);
                if (!$pass) {
                    continue;
                }
            }
            foreach ($this->_parsers as $name => $parser) {
                if ($name != $this->_current) {
                    $pass = call_user_func_array($parser, $args);
                    if (!$pass) {
                        break;
                    }
                }
            }
        }
        return $this->optimizeBlocks($this->_blocks, $lines);
    }
108669
private void processBeginBlockCmd(String parms, int cmdTPosBegin, int cmdTPosEnd)
            throws MiniTemplator.TemplateSyntaxException {
        if (conditionalExclude(cmdTPosBegin, cmdTPosEnd)) {
            return;
        }
        int p0 = skipBlanks(parms, 0);
        if (p0 >= parms.length()) {
            throw new MiniTemplator.TemplateSyntaxException(
                    "Missing block name in $BeginBlock command in template at offset " + cmdTPosBegin + ".");
        }
        int p = skipNonBlanks(parms, p0);
        String blockName = parms.substring(p0, p);
        if (!isRestOfStringBlank(parms, p)) {
            throw new MiniTemplator.TemplateSyntaxException(
                    "Extra parameter in $BeginBlock command in template at offset " + cmdTPosBegin + ".");
        }
        int blockNo = registerBlock(blockName);
        BlockTabRec btr = blockTab[blockNo];
        btr.tPosBegin = cmdTPosBegin;
        btr.tPosContentsBegin = cmdTPosEnd;
        openBlocksTab[currentNestingLevel] = blockNo;
        currentNestingLevel++;
        if (currentNestingLevel > maxNestingLevel) {
            throw new MiniTemplator.TemplateSyntaxException("Block nesting overflow for block \"" + blockName
                    + "\" in template at offset " + cmdTPosBegin + ".");
        }
    }
939866
public function writeBlockWithTags($string, array $tags = [])
    {
        if (!is_array($string)) {
            $string = explode(PHP_EOL, $string);
        }

        $strlen = 0;
        foreach ($string as $line) {
            $strlen = max($strlen, mb_strlen($line));
        }

        $tagsOpen  = '';
        $tagsClose = '';
        if (count($tags) > 0) {
            foreach ($tags as $tag) {
                $tagsOpen  .= "<{$tag}>";
                $tagsClose .= "</{$tag}>";
            }
        }

        $lines = [
            "",
            " {$tagsOpen}┌" . str_repeat("─", $strlen + 2) . "┐{$tagsClose}",
        ];

        foreach ($string as $line) {
            $padding = str_repeat(" ", $strlen - mb_strlen($line));
            $lines[] = " {$tagsOpen}│ {$line}{$padding} │{$tagsClose}";
        }

        $lines[] = " {$tagsOpen}└" . str_repeat("─", $strlen + 2) . "┘{$tagsClose}";
        $lines[] = "";

        $this->writeln($lines);
        return $this;
    }
1191966
public static function isPastOrNow( $string )
	{
		$date	= Alg_TimeConverter::complementMonthDate( $string );
		$time	= strtotime( $date );
		if( $time === FALSE )
			throw new InvalidArgumentException( 'Given Date "'.$string.'" could not been parsed.' );
		return $time < time();
	}
525507
public function startsWith($string, int $offset = 0): bool
    {
        try {
            Assert::typeOf(['string', __CLASS__], $string);
        } catch (InvalidArgumentException|TypeError $t) {
            return false;
        }

        return mb_strpos($this->data, (string) $string, $offset, $this->encoding) === 0;
    }
631855
def tryStatement(self, block):
        
        currentBlock = self._prevNonEmptyBlock(block)

        if not currentBlock.isValid():
            return None

        indentation = None

        currentBlockText = currentBlock.text()
        if currentBlockText.endswith('('):
            # increase indent level
            dbg("tryStatement: success 1 in line %d" % block.blockNumber())
            return self._increaseIndent(self._lineIndent(currentBlockText))

        alignOnSingleQuote = self._qpart.language() in ('PHP/PHP', 'JavaScript')
        # align on strings "..."\n => below the opening quote
        # multi-language support: [\.+] for javascript or php
        pattern =  '^(.*)'                   # any                                                  group 1
        pattern += '([,"\'\\)])'             # one of [ , " ' )                                     group 2
        pattern += '(;?)'                    # optional ;                                           group 3
        pattern += '\s*[\.+]?\s*'            # optional spaces  optional . or +   optional spaces
        pattern += '(//.*|/\\*.*\\*/\s*)?$'  # optional(//any  or  /*any*/spaces)                   group 4
        match = re.match(pattern, currentBlockText)
        if match is not None:
            alignOnAnchor = len(match.group(3)) == 0 and match.group(2) != ')'
            # search for opening ", ' or (
            if match.group(2) == '"' or (alignOnSingleQuote and match.group(2) == "'"):
                startIndex = len(match.group(1))
                while True:
                    # start from matched closing ' or "
                    # find string opener
                    for i in range(startIndex - 1, 0, -1):
                        # make sure it's not commented out
                        if currentBlockText[i] == match.group(2) and (i == 0 or currentBlockText[i - 1] != '\\'):
                            # also make sure that this is not a line like '#include "..."' <-- we don't want to indent here
                            if re.match(r'^#include', currentBlockText):
                                dbg("tryStatement: success 2 in line %d" % block.blockNumber())
                                return indentation

                            break

                    if not alignOnAnchor and currentBlock.previous().isValid():
                        # when we finished the statement (;) we need to get the first line and use it's indentation
                        # i.e.: $foo = "asdf"; -> align on $
                        i -= 1 # skip " or '
                        # skip whitespaces and stuff like + or . (for PHP, JavaScript, ...)
                        for i in range(i, 0, -1):
                            if currentBlockText[i] in (' ', '\t', '.', '+'):
                                continue
                            else:
                                break

                        if i > 0:
                            # there's something in this line, use it's indentation
                            break
                        else:
                            # go to previous line
                            currentBlock = currentBlock.previous()
                            currentBlockText = currentBlock.text()
                            startIndex = len(currentBlockText)
                    else:
                        break

            elif match.group(2) == ',' and not '(' in currentBlockText:
                # assume a function call: check for '(' brace
                # - if not found, use previous indentation
                # - if found, compare the indentation depth of current line and open brace line
                #   - if current indentation depth is smaller, use that
                #   - otherwise, use the '(' indentation + following white spaces
                currentIndentation = self._blockIndent(currentBlock)
                try:
                    foundBlock, foundColumn = self.findBracketBackward(currentBlock, len(match.group(1)), '(')
                except ValueError:
                    indentation = currentIndentation
                else:
                    indentWidth = foundColumn + 1
                    text = foundBlock.text()
                    while indentWidth < len(text) and text[indentWidth].isspace():
                        indentWidth += 1
                    indentation = self._makeIndentAsColumn(foundBlock, indentWidth)

            else:
                try:
                    foundBlock, foundColumn = self.findBracketBackward(currentBlock, len(match.group(1)), '(')
                except ValueError:
                    pass
                else:
                    if alignOnAnchor:
                        if not match.group(2) in ('"', "'"):
                            foundColumn += 1
                        foundBlockText = foundBlock.text()
                        while foundColumn < len(foundBlockText) and \
                              foundBlockText[foundColumn].isspace():
                            foundColumn += 1
                        indentation = self._makeIndentAsColumn(foundBlock, foundColumn)
                    else:
                        currentBlock = foundBlock
                        indentation = self._blockIndent(currentBlock)
        elif currentBlockText.rstrip().endswith(';'):
            indentation = self._blockIndent(currentBlock)

        if indentation is not None:
            dbg("tryStatement: success in line %d" % currentBlock.blockNumber())
        return indentation
386486
public function compare($string)
    {
        foreach ($this->tokens as $token) {
            if (strcasecmp($token, $string) === 0) {
                $this->found = true;
            }
        }
    }
814956
protected function _setBlock($block)
    {
        if ($block !== null && !($block instanceof BlockInterface)) {
            throw $this->_createInvalidArgumentException(
                $this->__('Invalid block'),
                null,
                null,
                $block
            );
        }

        $this->block = $block;
    }
319974
public function detect($string, $inBlock = false)
    {
        if (!preg_match($this->regexp, $string, $this->_detectMatch)) {
            return (0);
        }

        return (1);
    }
71489
protected function isBlockEnd($line, $blockName = null)
    {
        $line = trim($line);
        $pattern = '/^\<\/';
        $pattern .= ($blockName) ? $blockName : '[^\s\>]+';
        $pattern .= '\>$/';
        return (preg_match($pattern, $line) > 0);
    }
1066265
private static function detectBank($string)
    {
        ksort(self::$registeredEngines, SORT_NUMERIC);

        foreach (self::$registeredEngines as $engineClass) {
            if ($engineClass::isApplicable($string)) {
                return new $engineClass();
            }
        }

        trigger_error('Unknown mt940 parser loaded, thus reverted to default');

        return new Engine\Unknown();
    }
905095
public static function isMessage(string $string): bool
    {
        return substr($string, 0, 2) == self::I18N_PREFIX
            && substr($string, -2) == self::I18N_POSTFIX;
    }