Parse the BBCode suffix starting at current position

Used to explicitly pair specific tags together, e.g.
[code:123][code]type your code here[/code][/code:123]

@return void
776324
protected function parseBBCodeSuffix()
	{
		$this->bbcodeSuffix = '';
		if ($this->text[$this->pos] === ':')
		{
			// Capture the colon and the (0 or more) digits following it
			$spn = 1 + strspn($this->text, '0123456789', 1 + $this->pos);
			$this->bbcodeSuffix = substr($this->text, $this->pos, $spn);

			// Move past the suffix
			$this->pos += $spn;
		}
	}
491109
protected function captureEndTag()
	{
		if (empty($this->uppercaseText))
		{
			$this->uppercaseText = strtoupper($this->text);
		}
		$match     = '[/' . $this->bbcodeName . $this->bbcodeSuffix . ']';
		$endTagPos = strpos($this->uppercaseText, $match, $this->pos);
		if ($endTagPos === false)
		{
			return;
		}

		return $this->parser->addEndTag($this->getTagName(), $endTagPos, strlen($match));
	}
779598
protected function endTag() {
        if ($this->scanner->current() != '/') {
            return false;
        }
        $tok = $this->scanner->next();

        // a-zA-Z -> tagname
        // > -> parse error
        // EOF -> parse error
        // -> parse error
        if (!ctype_alpha($tok)) {
            $this->parseError("Expected tag name, got '%s'", $tok);
            if ($tok == "\0" || $tok === false) {
                return false;
            }
            return $this->bogusComment('</');
        }

        $name = strtolower($this->scanner->charsUntil("\n\f \t>"));
        // Trash whitespace.
        $this->scanner->whitespace();

        if ($this->scanner->current() != '>') {
            $this->parseError("Expected >, got '%s'", $this->scanner->current());
            // We just trash stuff until we get to the next tag close.
            $this->scanner->charsUntil('>');
        }

        $this->events->endTag($name);
        $this->scanner->next();
        return true;
    }
1341593
protected function handleTag_ul()
    {
        if ($this->parser->isStartTag) {
            $this->stack();
            if (!$this->keepHTML && $this->lastClosedTag == $this->parser->tagName) {
                $this->out("\n" . $this->indent . '<!-- -->' . "\n" . $this->indent . "\n" . $this->indent);
            }
        } else {
            $this->unstack();
            if ($this->parent() != 'li' || preg_match('#^\s*(</li\s*>\s*<li\s*>\s*)?<(p|blockquote)\s*>#sU', $this->parser->html)) {
                // don't make Markdown add unneeded paragraphs
                $this->setLineBreaks(2);
            }
        }
    }
807691
protected void parseNames() {
        while (reader.hasNextCharacter()) {
            final char character = next();
            if (Strings.isWhitespace(character)) {
                addName();
                continue;
            } else if (character == blockOpening) {
                addName();
                break;
            } else {
                builder.append(character);
            }
        }
        if (GdxArrays.isEmpty(tags)) {
            throwException("No tag names chosen.");
        }
    }
1338571
function _tag_open( &$parser, $tag, $attributes ) {
		$this->currentElement = strtoupper( $tag );

		switch( $this->currentElement ) {
			case 'DROP':
				$this->drop();
				break;
			case 'CLUSTERED':
			case 'BITMAP':
			case 'UNIQUE':
			case 'FULLTEXT':
			case 'HASH':
				// Add index Option
				$this->addIndexOpt( $this->currentElement );
				break;
			default:
				// print_r( array( $tag, $attributes ) );
		}
	}
1056659
public function parseDefs()
    {
        if (! isset($this->defData)) {
            // allow wkt to define defData, and not be overwritten here.
            $this->defData = $this->proj4php->getDef($this->srsCode);
        }

        if (! $this->defData) {
            return;
        }

        $paramArray = explode('+', $this->defData);

        for ($prop = 0; $prop < sizeof($paramArray); $prop++) {
            if (strlen($paramArray[$prop]) == 0) {
                continue;
            }

            $property = explode("=", $paramArray[$prop]);
            $paramName = strtolower($property[0]);

            if (sizeof($property) >= 2) {
                $paramVal = $property[1];
            }

            switch (trim($paramName)) {
                // Throw away nameless parameter.
                // This will be from before the first "+" that explode() creates.
                case "":
                    break;
                case "title":
                    $this->title = $paramVal;
                    break;
                case "proj":
                    $this->projName = trim($paramVal);
                    break;
                case "units":
                    $this->units = trim($paramVal);
                    break;
                case "datum": $this->datumCode = trim($paramVal);
                    break;
                case "nadgrids": $this->nagrids = trim($paramVal);
                    break;
                case "ellps":
                    $this->ellps = trim($paramVal);
                    if ($this->ellps=='WGS84' && !isset($this->datumCode))
                       $this->datumCode = trim($paramVal);
                    break;
                case "a":
                    // semi-major radius
                    $this->a = floatval($paramVal);
                    break;
                case "b":
                    // semi-minor radius
                    $this->b = floatval($paramVal);
                    break;
                case "rf":
                    // DGR 2007-11-20
                    // inverse flattening rf= a/(a-b)
                    $this->rf = floatval($paramVal);
                    break;
                case "lat_0":
                    // phi0, central latitude
                    $this->lat0 = floatval($paramVal) * Common::D2R;
                    break;
                case "lat_1":
                    //standard parallel 1
                    $this->lat1 = floatval($paramVal) * Common::D2R;
                    break;
                case "lat_2":
                    //standard parallel 2
                    $this->lat2 = floatval($paramVal) * Common::D2R;
                    break;
                case "lat_ts":
                    // used in merc and eqc
                    $this->lat_ts = floatval($paramVal) * Common::D2R;
                    break;
                case "lon_0":
                    // lam0, central longitude
                    $this->long0 = floatval($paramVal) * Common::D2R;
                    break;
                case "alpha":
                    $this->alpha = floatval($paramVal) * Common::D2R;
                    //for somerc projection
                    break;
                case "lonc":
                    //for somerc projection
                    $this->longc = floatval($paramVal) * Common::D2R;
                    break;
                case "x_0":
                    // false easting
                    $this->x0 = floatval($paramVal);
                    break;
                case "y_0":
                    // false northing
                    $this->y0 = floatval($paramVal);
                    break;
                case "k_0":
                    // projection scale factor
                    $this->k0 = floatval($paramVal);
                    break;
                case "k":
                    // both forms returned
                    $this->k0 = floatval($paramVal);
                    break;
                case "r_a":
                    // sphere--area of ellipsoid
                    $this->R_A = true;
                    break;
                case "zone":
                    // UTM Zone
                    $this->zone = intval($paramVal, 10);
                    break;
                case "south":
                    // UTM north/south
                    $this->utmSouth = true;
                    break;
                case "towgs84":
                    $this->datum_params = explode( ",", $paramVal);
                    break;
                case "to_meter":
                    // cartesian scaling
                    $this->to_meter = floatval($paramVal);
                    break;
                case "from_greenwich":
                    $this->from_greenwich = floatval($paramVal) * Common::D2R;
                    break;
                case "pm":
                    // DGR 2008-07-09 : if pm is not a well-known prime meridian take
                    // the value instead of 0.0, then convert to radians
                    $paramVal = trim($paramVal);

                    $this->from_greenwich =
                        $this->proj4php->hasPrimeMeridian($paramVal)
                        ? $this->proj4php->getPrimeMeridian($paramVal)
                        : floatval($paramVal);

                    $this->from_greenwich *= Common::D2R;
                    break;
                case "axis":
                    // DGR 2010-11-12: axis
                    $paramVal = trim($paramVal);
                    $legalAxis = "ewnsud";
                    if (strlen($paramVal) == 3 &&
                        strpos($legalAxis, substr($paramVal, 0, 1)) !== false &&
                        strpos($legalAxis, substr($paramVal, 1, 1)) !== false &&
                        strpos($legalAxis, substr($paramVal, 2, 1)) !== false
                    ) {
                        $this->axis = $paramVal;
                    } //FIXME: be silent ?

                    break;
                case 'no_defs':
                    break;
                default:
                    //alert("Unrecognized parameter: " . paramName);
            } // switch()
        } // for paramArray

        $this->deriveConstants();
    }
8538
public function parseEncodedString()
    {
        $l = $this->parseEncodedBinary();
        if (($l === null) || ($l === false)) {
            return $l;
        }
        return $this->read($l);
    }
962509
public function getFullBbCode() : BbCode
    {
        $bbcode = new BbCode();

        $bold = new Bold();
        $bbcode->addTag($bold);

        $underline = new Underline();
        $bbcode->addTag($underline);

        $italic = new Italic();
        $bbcode->addTag($italic);

        $link = new Link;
        $bbcode->addTag($link);

        $img = new ImgTag();
        $bbcode->addTag($img);

        $unknownTag = new Tag\UnknownSimpleType();
        $bbcode->addTag($unknownTag);

        $youtubeTag = new YoutubeTag();
        $bbcode->addTag($youtubeTag);

        $tags = [
            $bold,
            $underline,
            $italic,
            $link,
            $unknownTag,
            $img,
            $youtubeTag,
        ];

        // link allowed
        $bbcode->addAllowedChildTag($link, $bold);
        $bbcode->addAllowedChildTag($link, $italic);
        $bbcode->addAllowedChildTag($link, $underline);
        $bbcode->addAllowedChildTag($link, $unknownTag);
        $bbcode->addAllowedChildTag($link, $img);

        $tagsAllowingAnyChild = [
            $bold,
            $italic,
            $underline,
            $unknownTag,
        ];

        foreach ($tagsAllowingAnyChild as $tagAllowingAnyTag) {
            foreach ($tags as $tag) {
                $bbcode->addAllowedChildTag($tagAllowingAnyTag, $tag);
            }
        }

        return $bbcode;
    }
1189243
protected function __parseRanges()
    {
        if (isset($this->__meta["labelRange"]) && is_array($this->__meta["labelRange"])) {
            if (isset($this->__meta["valueRange"]) && is_array($this->__meta["valueRange"]) && count($this->__meta["labelRange"]) == count($this->__meta["valueRange"])) {
                $intIndex = 0;
                foreach ($this->__meta["labelRange"] as $strLabel) {
                    $this->addField($strLabel, $this->__meta["valueRange"][$intIndex]);
                    $intIndex ++;
                }
            } else {
                foreach ($this->__meta["labelRange"] as $strLabel) {
                    $this->addField($strLabel, $strLabel);
                }
            }
        } elseif (isset($this->__meta["start"]) && is_numeric($this->__meta["start"]) && isset($this->__meta["end"]) && is_numeric($this->__meta["end"])) {
            if ($this->__meta["start"] < $this->__meta["end"]) {
                for ($intIndex = $this->__meta["start"]; $intIndex <= $this->__meta["end"]; $intIndex ++) {
                    $this->addField($intIndex, $intIndex);
                }
            } else {
                for ($intIndex = $this->__meta["start"]; $intIndex >= $this->__meta["end"]; $intIndex --) {
                    $this->addField($intIndex, $intIndex);
                }
            }
        }
    }
127544
protected static function _doShortcode($m)
    {
        // allow {{foo}} syntax for escaping a tag
        if ($m[1] == '{' && $m[6] == '}') {
            return substr($m[0], 1, -1);
        }

        $tag = $m[2];
        $atts = static::_parseAttributes($m[3]);
        $listeners = EventDispatcher::instance('Shortcode')
            ->eventManager()
            ->listeners($tag);

        if (!empty($listeners)) {
            $options = [
                'atts' => (array)$atts,
                'content' => null,
                'tag' => $tag
            ];

            if (isset($m[5])) {
                $options['content'] = $m[5];
            }

            $result = EventDispatcher::instance('Shortcode')
                ->triggerArray([$tag, static::cache('context')], $options)
                ->result;

            return $m[1] . $result . $m[6];
        }

        return '';
    }
102794
function handleTag_pre() {
    if ($this->keepHTML && $this->parser->isStartTag) {
      # check if a simple <code> follows
      if (!preg_match('#^\s*<code\s*>#Us', $this->parser->html)) {
        # this is no standard markdown code block
        $this->handleTagToText();
        return;
      }
    }
    $this->indent('    ');
    if (!$this->parser->isStartTag) {
      $this->setLineBreaks(2);
    } else {
      $this->parser->html = ltrim($this->parser->html);
    }
  }
1008827
public function parse()
    {
        $parents = array();

        // flag : are we in a <pre> Tag ?
        $tagPreIn = false;

        // action to use for each line of the content of a <pre> Tag
        $tagPreBr = array(
                    'name' => 'br',
                    'close' => false,
                    'param' => array(
                        'style' => array(),
                        'num'    => 0
                    )
                );

        // tag that can be not closed
        $tagsNotClosed = array(
            'br', 'hr', 'img', 'col',
            'input', 'link', 'option',
            'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline'
        );

        // search the HTML tags
        $tmp = array();
        $this->_searchCode($tmp);

        // all the actions to do
        $actions = array();

        // foreach part of the HTML code
        foreach ($tmp as $part) {
            // if it is a tag code
            if ($part[0]=='code') {
                // analise the HTML code
                $res = $this->_analiseCode($part[1]);

                // if it is a real HTML tag
                if ($res) {
                    // save the current posistion in the HTML code
                    $res['html_pos'] = $part[2];

                    // if the tag must be closed
                    if (!in_array($res['name'], $tagsNotClosed)) {
                        // if it is a closure tag
                        if ($res['close']) {
                            // HTML validation
                            if (count($parents)<1)
                                throw new HTML2PDF_exception(3, $res['name'], $this->getHtmlErrorCode($res['html_pos']));
                            else if ($parents[count($parents)-1]!=$res['name'])
                                throw new HTML2PDF_exception(4, $parents, $this->getHtmlErrorCode($res['html_pos']));
                            else
                                unset($parents[count($parents)-1]);
                        } else {
                            // if it is a autoclosed tag
                            if ($res['autoclose']) {
                                // save the opened tag
                                $actions[] = $res;

                                // prepare the closed tag
                                $res['params'] = array();
                                $res['close'] = true;
                            }
                            // else :add a child for validation
                            else
                                $parents[count($parents)] = $res['name'];
                        }

                        // if it is a <pre> tag (or <code> tag) not auclosed => update the flag
                        if (($res['name']=='pre' || $res['name']=='code') && !$res['autoclose']) {
                            $tagPreIn = !$res['close'];
                        }
                    }

                    // save the actions to convert
                    $actions[] = $res;
                } else { // else (it is not a real HTML tag => we transform it in Texte
                    $part[0]='txt';
                }
            }
            // if it is text
            if ($part[0]=='txt') {
                // if we are not in a <pre> tag
                if (!$tagPreIn) {
                    // save the action
                    $actions[] = array(
                        'name'    => 'write',
                        'close'    => false,
                        'param' => array('txt' => $this->_prepareTxt($part[1])),
                    );
                } else { // else (if we are in a <pre> tag)
                    // prepare the text
                    $part[1] = str_replace("\r", '', $part[1]);
                    $part[1] = explode("\n", $part[1]);

                    // foreach line of the text
                    foreach ($part[1] as $k => $txt) {
                        // transform the line
                        $txt = str_replace("\t", self::HTML_TAB, $txt);
                        $txt = str_replace(' ', '&nbsp;', $txt);

                        // add a break line
                        if ($k>0) $actions[] = $tagPreBr;

                        // save the action
                        $actions[] = array(
                            'name'    => 'write',
                            'close'    => false,
                            'param' => array('txt' => $this->_prepareTxt($txt, false)),
                        );
                    }
                }
            }
        }

        // for each indentified action, we have to clean up the begin and the end of the texte
        // based on tags that surround it

        // list of the tags to clean
        $tagsToClean = array(
            'page', 'page_header', 'page_footer', 'form',
            'table', 'thead', 'tfoot', 'tr', 'td', 'th', 'br',
            'div', 'hr', 'p', 'ul', 'ol', 'li',
            'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
            'bookmark', 'fieldset', 'legend',
            'draw', 'circle', 'ellipse', 'path', 'rect', 'line', 'g', 'polygon', 'polyline',
            'option'
        );

        // foreach action
        $nb = count($actions);
        for ($k=0; $k<$nb; $k++) {
            // if it is a Text
            if ($actions[$k]['name']=='write') {
                // if the tag before the text is a tag to clean => ltrim on the text
                if ($k>0 && in_array($actions[$k-1]['name'], $tagsToClean))
                    $actions[$k]['param']['txt'] = ltrim($actions[$k]['param']['txt']);

                // if the tag after the text is a tag to clean => rtrim on the text
                if ($k<$nb-1 && in_array($actions[$k+1]['name'], $tagsToClean))
                    $actions[$k]['param']['txt'] = rtrim($actions[$k]['param']['txt']);

                // if the text is empty => remove the action
                if (!strlen($actions[$k]['param']['txt']))
                    unset($actions[$k]);
            }
        }

        // if we are not on the level 0 => HTML validator ERROR
        if (count($parents)) throw new HTML2PDF_exception(5, $parents);

        // save the actions to do
        $this->code = array_values($actions);
    }
115525
private function parsing() : void
    {
        $lines = explode("\n", $this->raw);

        foreach ($lines as $line) {
            // check "at" mark
            if (false === strpos($line, '@')) {
                continue;
            }

            // check inline annotation
            if ($anp = strpos($line, '//')) {
                $line = substr($line, 0, $anp);
            }

            // trim blanks
            $line = trim(ltrim($line, ' *'));

            // analyze expr
            if (false === $fws = strpos($line, ' ')) {
                // @some-key
                $key = substr($line, 1);
                $val = true;
            } else {
                // @some-key some-val
                $key = substr($line, 1, $fws - 1);
                $val = trim(substr($line, $fws));
            }

            $this->lines[] = [$key, $val];

            $this->declares[$key][] = $val;
        }
    }
835099
private function parseShortString()
    {
        $length = \ord($this->buffer);

        try {
            return mb_orig_substr($this->buffer, 1, $length);
        } finally {
            $this->buffer = mb_orig_substr($this->buffer, $length + 1);
        }
    }
861601
def p_suffix(self, length=None, elipsis=False):
        ""
        if length is not None:
            result = self.input[self.pos:self.pos + length]
            if elipsis and len(result) == length:
                result += "..."
            return result
        return self.input[self.pos:]
26564
protected function handleTag_a()
    {
        if ($this->parser->isStartTag) {
            $this->buffer();
            $this->handleTag_a_parser();
            $this->stack();
        } else {
            $tag = $this->unstack();
            $buffer = $this->unbuffer();
            $this->handleTag_a_converter($tag, $buffer);
            $this->out($this->handleTag_a_converter($tag, $buffer), true);
        }
    }