Parse tables.

@param array $line
@param array $block
@return array
161412
protected function blockTable($line, array $block = null)
    {
        if (! isset($block) or isset($block[ 'type' ]) or isset($block[ 'interrupted' ])) {
            return;
        }

        if (strpos($block[ 'element' ][ 'text' ], '|') !== false and chop($line[ 'text' ], ' -:|') === '') {
            $alignments = array();

            $divider = $line[ 'text' ];
            $divider = trim($divider);
            $divider = trim($divider, '|');

            $dividerCells = explode('|', $divider);

            foreach ($dividerCells as $dividerCell) {
                $dividerCell = trim($dividerCell);

                if ($dividerCell === '') {
                    continue;
                }

                $alignment = null;

                if ($dividerCell[ 0 ] === ':') {
                    $alignment = 'left';
                }

                if (substr($dividerCell, -1) === ':') {
                    $alignment = $alignment === 'left' ? 'center' : 'right';
                }

                $alignments[] = $alignment;
            }

            $headerElements = array();

            $header = $block[ 'element' ][ 'text' ];

            $header = trim($header);
            $header = trim($header, '|');

            $headerCells = explode('|', $header);

            foreach ($headerCells as $index => $headerCell) {
                $headerCell = trim($headerCell);

                $headerElement = [
                    'name'    => 'th',
                    'text'    => $headerCell,
                    'handler' => 'line',
                ];

                if (isset($alignments[ $index ])) {
                    $alignment = $alignments[ $index ];

                    $headerElement[ 'attributes' ] = [
                        'style' => 'text-align: ' . $alignment . ';',
                    ];
                }

                $headerElements[] = $headerElement;
            }

            $block = [
                'alignments' => $alignments,
                'identified' => true,
                'element'    => [
                    'name'       => 'table',
                    'handler'    => 'elements',
                    'attributes' => [
                        'class' => 'table table-striped table-bordered'
                    ],
                ],
            ];

            $block[ 'element' ][ 'text' ][] = [
                'name'    => 'thead',
                'handler' => 'elements',
            ];

            $block[ 'element' ][ 'text' ][] = [
                'name'    => 'tbody',
                'handler' => 'elements',
                'text'    => array(),
            ];

            $block[ 'element' ][ 'text' ][ 0 ][ 'text' ][] = [
                'name'    => 'tr',
                'handler' => 'elements',
                'text'    => $headerElements,
            ];

            return $block;
        }
    }
288799
protected function parseHeader($block)
    {
        if (!$block || strlen($block) != 512) {
            throw new ArchiveCorruptedException('Unexpected length of header');
        }

        // null byte blocks are ignored
        if(trim($block) === '') return false;

        for ($i = 0, $chks = 0; $i < 148; $i++) {
            $chks += ord($block[$i]);
        }

        for ($i = 156, $chks += 256; $i < 512; $i++) {
            $chks += ord($block[$i]);
        }

        $header = @unpack(
            "a100filename/a8perm/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix",
            $block
        );
        if (!$header) {
            throw new ArchiveCorruptedException('Failed to parse header');
        }

        $return['checksum'] = OctDec(trim($header['checksum']));
        if ($return['checksum'] != $chks) {
            throw new ArchiveCorruptedException('Header does not match it\'s checksum');
        }

        $return['filename'] = trim($header['filename']);
        $return['perm']     = OctDec(trim($header['perm']));
        $return['uid']      = OctDec(trim($header['uid']));
        $return['gid']      = OctDec(trim($header['gid']));
        $return['size']     = OctDec(trim($header['size']));
        $return['mtime']    = OctDec(trim($header['mtime']));
        $return['typeflag'] = $header['typeflag'];
        $return['link']     = trim($header['link']);
        $return['uname']    = trim($header['uname']);
        $return['gname']    = trim($header['gname']);

        // Handle ustar Posix compliant path prefixes
        if (trim($header['prefix'])) {
            $return['filename'] = trim($header['prefix']).'/'.$return['filename'];
        }

        // Handle Long-Link entries from GNU Tar
        if ($return['typeflag'] == 'L') {
            // following data block(s) is the filename
            $filename = trim($this->readbytes(ceil($return['size'] / 512) * 512));
            // next block is the real header
            $block  = $this->readbytes(512);
            $return = $this->parseHeader($block);
            // overwrite the filename
            $return['filename'] = $filename;
        }

        return $return;
    }
85451
public function parseMany($line)
    {
        $results = [];
        $buffer  = '';

        foreach (\str_split($line) as $character)
        {
            if ('{' == $character)
            {
                $buffer = $character;
            }
            elseif ('}' == $character)
            {
                $results[] = $this->parse($buffer.$character);
            }
            else
            {
                $buffer .= $character;
            }
        }

        return $results;
    }
1103560
protected function consumeParagraph($lines, $current)
	{
		// consume until newline
		$content = [];
		for ($i = $current, $count = count($lines); $i < $count; $i++) {
			$line = $lines[$i];
			if ($this->isParagraphEnd($line)) {
				break;
			}
			$content[] = $line;
		}
		$block = [
			'paragraph',
			'content' => $this->parseInline(implode("\n", $content)),
		];
		return [$block, --$i];
	}
773100
def _parse_block(self):
        """"""
        if self._iter_rows is not None:
            return

        rows = _avro_rows(self._block, self._avro_schema)
        self._num_items = self._block.avro_rows.row_count
        self._remaining = self._block.avro_rows.row_count
        self._iter_rows = iter(rows)
85875
public function meta(array $rows, $block = null)
    {
        $output = [];
        foreach ($rows as $row) {
            $output[] = trim($row);
        }

        $output = implode($this->eol, $output) . $this->eol;

        if ($block !== null) {
            $this->_View->append($block, $output);
            return null;
        }

        return $output;
    }
1009849
protected function block(OutputBlock $block)
    {
        if (empty($block->lines) && empty($block->children)) {
            return;
        }

        $this->currentBlock = $block;

        $pre = $this->indentStr();

        if (! empty($block->selectors)) {
            $this->blockSelectors($block);

            $this->indentLevel++;
        }

        if (! empty($block->lines)) {
            $this->blockLines($block);
        }

        if (! empty($block->children)) {
            $this->blockChildren($block);
        }

        if (! empty($block->selectors)) {
            $this->indentLevel--;

            if (empty($block->children)) {
                $this->write($this->break);
            }

            $this->write($pre . $this->close . $this->break);
        }
    }
1090705
protected function parseBlockLine($line, \SplFileObject $file, $lineBreaks)
    {
        $block = new Block();

        $args = $this->blockRegex($line);
        $name = array_shift($args);

        if ($name === null) {
            $lineNum = $file->key();
            throw new SyntaxException($lineNum, $line, "Could not parse the name of the block");
        }

        $block->setName($name)
              ->setArguments($args)
              ->setLineBreaks($lineBreaks);

        // Now we parse the children
        $newLine = $file->getCurrentLine();

        while (!$this->isBlockEnd($newLine, $name)) {
            $parsedLine = $this->parseLine($newLine, $file);
            if (!is_null($parsedLine)) {
                $block->addChild($parsedLine);
            }
            $newLine = $file->getCurrentLine();
        }

        return $block;
    }
389253
public function getValidBlockItems(Block $block)
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->select(
                $this->connection->quoteIdentifier('p.object_id'),
                $this->connection->quoteIdentifier('p.node_id'),
                $this->connection->quoteIdentifier('p.priority'),
                $this->connection->quoteIdentifier('p.ts_publication'),
                $this->connection->quoteIdentifier('p.ts_visible'),
                $this->connection->quoteIdentifier('p.ts_hidden'),
                $this->connection->quoteIdentifier('p.rotation_until'),
                $this->connection->quoteIdentifier('p.moved_to')
            )
            ->from($this->connection->quoteIdentifier(self::EZM_POOL_TABLE), 'p')
            ->innerJoin(
                'p',
                $this->connection->quoteIdentifier('ezcontentobject_tree'),
                't',
                $query->expr()->eq(
                    $this->connection->quoteIdentifier('t.node_id'),
                    $this->connection->quoteIdentifier('p.node_id')
                )
            )
            ->where(
                $query->expr()->eq('p.block_id', ':blockId'),
                $query->expr()->gt('p.ts_visible', ':tsVisible'),
                $query->expr()->eq('p.ts_hidden', ':tsHidden')
            )
            ->setParameter(':blockId', $block->id)
            ->setParameter(':tsVisible', 0, PDO::PARAM_INT)
            ->setParameter(':tsHidden', 0, PDO::PARAM_INT)
            ->orderBy('p.priority', 'DESC')
        ;

        $statement = $query->execute();

        $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
        $items = [];
        foreach ($rows as $row) {
            $items[] = $this->buildBlockItem(
                $row + [
                    'block_id' => $block->id,
                    'ts_hidden' => 0,
                ]
            );
        }

        return $items;
    }
114753
def getblock(lines):
    """"""
    try:
        tokenize.tokenize(ListReader(lines).readline, BlockFinder().tokeneater)
    except EndOfBlock, eob:
        return lines[:eob.args[0]]
    # Fooling the indent/dedent logic implies a one-line definition
    return lines[:1]
477594
public Block split(final Line line)
    {
        final Block block = new Block();

        block.lines = this.lines;
        block.lineTail = line;
        this.lines = line.next;
        line.next = null;
        if (this.lines == null)
        {
            this.lineTail = null;
        }
        else
        {
            this.lines.previous = null;
        }

        if (this.blocks == null)
        {
            this.blocks = this.blockTail = block;
        }
        else
        {
            this.blockTail.next = block;
            this.blockTail = block;
        }

        return block;
    }
1346974
public function loadCollectionReferencesData(Block $block, ?string $identifier = null): array
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('block_id', 'block_status', 'collection_id', 'collection_status', 'identifier')
            ->from('ngbm_block_collection')
            ->where(
                $query->expr()->eq('block_id', ':block_id')
            )
            ->setParameter('block_id', $block->id, Type::INTEGER)
            ->orderBy('identifier', 'ASC');

        $this->applyStatusCondition($query, $block->status, 'block_status');

        if ($identifier !== null) {
            $query->andWhere($query->expr()->eq('identifier', ':identifier'))
                ->setParameter('identifier', $identifier, Type::STRING);
        }

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
151688
protected function loadCollection(BlockInterface $block)
    {
        $properties = $block->getProperties();

        $conditions = (isset($properties['conditions'])) ? $properties['conditions'] : '[]';
        $conditions = $this->expressionEngine->deserialize($conditions);

        if (empty($conditions)) {
            return;
        }

        $site = $this->siteManager->getSite();

        $qb = $this->expressionEngine->toQueryBuilder($conditions, $this->contentManager->getClass());
        $qb->andWhere('a.publishAt < :now OR a.publishAt IS NULL')
            ->andWhere('a.active = :active')
            ->andWhere('a.layout = :layout');

        if ($site == null) {
            $qb->andWhere('a.site IS NULL');
        } else {
            $qb->andWhere('a.site = :site')
               ->setParameter('site', $site);
        }

        $qb->setParameter('active', true)
            ->setParameter('layout', false)
            ->setParameter('now', new \DateTime());

        if (isset($properties['order_by'])) {
            $direction = (isset($properties['order_direction'])) ? $properties['order_direction'] : 'ASC';

            $qb->orderBy('a.'.$properties['order_by'], $direction);
        }

        $limit = (isset($properties['limit'])) ? $properties['limit'] : 10;
        $qb->setMaxResults($limit);

        $collection = $qb->getQuery()->getResult();

        if ($collection) {
            $block->setCollection($collection);
        }
    }
954594
protected function blockQuote($Line)
    {
        if (!$this->config('markup.quote.keepSigns'))
        {
            return parent::blockQuote($Line);
        }

        if (mb_ereg('^>([ ]?.*)', $Line['text'], $matches))
        {
            $matches = str_replace(">", "&gt;", $matches[1]);
            $Block = array(
                'element' => array(
                    'name' => 'blockquote',
                    'handler' => 'lines',
                    'text' => [ "&gt;{$matches}" ],
                ),
            );

            return $Block;
        }
    }
1080622
public function loadChildBlocksData(Block $block, ?string $placeholder = null): array
    {
        $query = $this->getBlockSelectQuery();
        $query->where(
            $query->expr()->eq('b.parent_id', ':parent_id')
        )
        ->setParameter('parent_id', $block->id, Type::INTEGER)
        ->addOrderBy('b.placeholder', 'ASC')
        ->addOrderBy('b.position', 'ASC');

        if ($placeholder !== null) {
            $query->andWhere(
                $query->expr()->eq('b.placeholder', ':placeholder')
            )
            ->setParameter('placeholder', $placeholder, Type::STRING);
        }

        $this->applyStatusCondition($query, $block->status, 'b.status');

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
599450
private function parseRow($line, $type): ?TableRow
    {
        if (strpos($line, '|') === false) {
            return null;
        }

        $row = new TableRow();
        foreach (explode('|', $line) as $cell) {
            // Strip leading ".b." from <th> cells
            if ($type === TableCell::TYPE_HEAD && substr_compare($cell, '.b.', 0)) {
                $cell = substr($cell, 3);
            }
            $row->appendChild(new TableCell($cell, $type, null));
        }

        return $row;
    }
324162
protected function getDefinedPredicatesInSpecBlock(array $block)
    {
        $predicates = [];
        // If the spec has a "type" property, include rdf:type
        if(isset($block['type']))
        {
            $predicates[] = $this->getLabeller()->uri_to_alias(RDF_TYPE);
        }
        if(isset($block['filter']))
        {
            foreach($block['filter'] as $filter)
            {
                if(isset($filter['condition']))
                {
                    $predicates = array_merge($predicates, $this->getPredicatesFromFilterCondition($filter['condition']));
                }
            }
        }
        // Get the predicates out of the defined fields
        if(isset($block['fields']))
        {
            foreach($block['fields'] as $field)
            {
                if(isset($field['predicates']))
                {
                    foreach($field['predicates'] as $p)
                    {
                        if(!empty($p))
                        {
                            // The actual predicate strings may be buried in predicate function blocks
                            $predicates = array_merge($predicates, $this->getPredicateAliasesFromPredicateProperty($p));
                        }
                    }
                }
            }
        }

        // Loop through the joins and pass the objects back to this method
        if(isset($block['joins']))
        {
            foreach($block['joins'] as $predicate=>$join)
            {
                // Joins are keyed on the predicate, so save that
                $predicates[] = $this->getLabeller()->uri_to_alias($predicate);
                $predicates = array_merge($predicates, $this->getDefinedPredicatesInSpecBlock($join));
            }
        }

        // Loop through the counts blocks
        if(isset($block['counts']))
        {
            foreach($block['counts'] as $property)
            {
                // counts use the redundant property 'property', which behaves exactly like a predicate and needs to be deprecated
                if(isset($property['property']))
                {
                    $predicates[] = $this->getLabeller()->uri_to_alias($property['property']);
                }

                // This is here so we can easily deprecate 'property' in favor of 'predicates'
                if(isset($property['predicates']))
                {
                    foreach($property['predicates'] as $p)
                    {
                        if(!empty($p))
                        {
                            // The actual predicate strings may be buried in predicate function blocks
                            $predicates = array_merge($predicates, $this->getPredicateAliasesFromPredicateProperty($p));
                        }
                    }
                }
            }
        }

        // Loop through the indices: these should be more or less identical to 'fields'
        if(isset($block['indices']))
        {
            foreach($block['indices'] as $index)
            {
                if(isset($index['predicates']))
                {
                    foreach($index['predicates'] as $p)
                    {
                        if(!empty($p))
                        {
                            $predicates = array_merge($predicates, $this->getPredicateAliasesFromPredicateProperty($p));
                        }
                    }
                }
            }
        }
        return $predicates;
    }