/* Parsing Funktionen um einen Header aus einem String zu erstellen
493311
protected function parseField($name, $value) {
    switch ($name) {
      case 'Content-Disposition':
        $this->assertNotEmpty($value, $name);
        
        // @TODO das ist ganz schön stümperhaft aber geht erstmal
        if (Preg::match($value, '/^(.*?);\s+filename="(.*)"$/', $match)) {
          $value = (object) array('type'=>$match[1],'filename'=>$match[2]);
        } else {
          throw new HeaderFieldParsingException('Content-Disposition: "'.$value.'" kann nicht geparsed werden');
        }
        break;
      
      case 'Cache-Control':
      case 'Pragma':
        $value = preg_split('/\s*,\s*/',$value);
        break;
    }
    return $value;
  }
271365
private static function parseRangeHeader($header)
    {
        if (preg_match('/bytes=(?P<first>\d+)-(?P<last>\d+)?/', $header, $matches)) {
            return [
                (int) $matches['first'],
                isset($matches['last']) ? (int) $matches['last'] : null,
            ];
        }

        return false;
    }
817853
function HeaderParser(cfg) {
  EventEmitter.call(this);

  var self = this;
  this.nread = 0;
  this.maxed = false;
  this.npairs = 0;
  this.maxHeaderPairs = (cfg && typeof cfg.maxHeaderPairs === 'number'
                         ? cfg.maxHeaderPairs
                         : MAX_HEADER_PAIRS);
  this.buffer = '';
  this.header = {};
  this.finished = false;
  this.ss = new StreamSearch(B_DCRLF);
  this.ss.on('info', function(isMatch, data, start, end) {
    if (data && !self.maxed) {
      if (self.nread + (end - start) > MAX_HEADER_SIZE) {
        end = (MAX_HEADER_SIZE - self.nread);
        self.nread = MAX_HEADER_SIZE;
      } else
        self.nread += (end - start);

      if (self.nread === MAX_HEADER_SIZE)
        self.maxed = true;

      self.buffer += data.toString('binary', start, end);
    }
    if (isMatch)
      self._finish();
  });
}
1052780
function parseTextBody(req, res, next){
    if (req.body === undefined) {
      req.body = '';
      req.on('data', function(chunk){ req.body += chunk });
      req.on('end', next);
    } else {
      next();
    }
  }
980089
function parseTag() {
    static $a_ord, $z_ord, $special_ords;
    if (!isset($a_ord)) {
      $a_ord = ord('a');
      $z_ord = ord('z');
      $special_ords = array(
        ord(':'), // for xml:lang
        ord('-'), // for http-equiv
      );
    }

    $tagName = '';

    $pos = 1;
    $isStartTag = $this->html[$pos] != '/';
    if (!$isStartTag) {
      $pos++;
    }
    # get tagName
    while (isset($this->html[$pos])) {
      $pos_ord = ord(strtolower($this->html[$pos]));
      if (($pos_ord >= $a_ord && $pos_ord <= $z_ord) || (!empty($tagName) && is_numeric($this->html[$pos]))) {
        $tagName .= $this->html[$pos];
        $pos++;
      } else {
        $pos--;
        break;
      }
    }

    $tagName = strtolower($tagName);
    if (empty($tagName) || !isset($this->blockElements[$tagName])) {
      # something went wrong => invalid tag
      $this->invalidTag();
      return false;
    }
    if ($this->noTagsInCode && end($this->openTags) == 'code' && !($tagName == 'code' && !$isStartTag)) {
      # we supress all HTML tags inside code tags
      $this->invalidTag();
      return false;
    }

    # get tag attributes
    /** TODO: in html 4 attributes do not need to be quoted **/
    $isEmptyTag = false;
    $attributes = array();
    $currAttrib = '';
    while (isset($this->html[$pos+1])) {
      $pos++;
      # close tag
      if ($this->html[$pos] == '>' || $this->html[$pos].$this->html[$pos+1] == '/>') {
        if ($this->html[$pos] == '/') {
          $isEmptyTag = true;
          $pos++;
        }
        break;
      }

      $pos_ord = ord(strtolower($this->html[$pos]));
      if ( ($pos_ord >= $a_ord && $pos_ord <= $z_ord) || in_array($pos_ord, $special_ords)) {
        # attribute name
        $currAttrib .= $this->html[$pos];
      } elseif (in_array($this->html[$pos], array(' ', "\t", "\n"))) {
        # drop whitespace
      } elseif (in_array($this->html[$pos].$this->html[$pos+1], array('="', "='"))) {
        # get attribute value
        $pos++;
        $await = $this->html[$pos]; # single or double quote
        $pos++;
        $value = '';
        while (isset($this->html[$pos]) && $this->html[$pos] != $await) {
          $value .= $this->html[$pos];
          $pos++;
        }
        $attributes[$currAttrib] = $value;
        $currAttrib = '';
      } else {
        $this->invalidTag();
        return false;
      }
    }
    if ($this->html[$pos] != '>') {
      $this->invalidTag();
      return false;
    }

    if (!empty($currAttrib)) {
      # html 4 allows something like <option selected> instead of <option selected="selected">
      $attributes[$currAttrib] = $currAttrib;
    }
    if (!$isStartTag) {
      if (!empty($attributes) || $tagName != end($this->openTags)) {
        # end tags must not contain any attributes
        # or maybe we did not expect a different tag to be closed
        $this->invalidTag();
        return false;
      }
      array_pop($this->openTags);
      if (in_array($tagName, $this->preformattedTags)) {
        $this->keepWhitespace--;
      }
    }
    $pos++;
    $this->node = substr($this->html, 0, $pos);
    $this->html = substr($this->html, $pos);
    $this->tagName = $tagName;
    $this->tagAttributes = $attributes;
    $this->isStartTag = $isStartTag;
    $this->isEmptyTag = $isEmptyTag || in_array($tagName, $this->emptyTags);
    if ($this->isEmptyTag) {
      # might be not well formed
      $this->node = preg_replace('# */? *>$#', ' />', $this->node);
    }
    $this->nodeType = 'tag';
    $this->isBlockElement = $this->blockElements[$tagName];
    return true;
  }
184336
function parse()
    {
        $criteria        = $this->criteria;
        $expectAsLiteral = $this->expectAsLiteral;


        $TOKENS  = preg_quote(static::TOKENS);

        $expectAsLiteral = (empty($expectAsLiteral)) ? '/@+-.' : $expectAsLiteral;
        $LITERAL = preg_quote($expectAsLiteral).'A-Za-z0-9_';


        $currentPos = 0;
        $length     = strlen($criteria);
        $parts      = [];
        $levelParts = [&$parts];
        $level      = 0;

        while ($currentPos < $length)
        {
            preg_match("(\G(?P<_literal_>[$LITERAL]*)(?P<_token_>[$TOKENS]|$))"
                , $criteria
                , $matches
                , 0
                , $currentPos
            );

            if ( empty($matches) )
                break;

            if (! empty($matches['_literal_']) ) {
                $levelParts[$level][] = ['_literal_' => $matches['_literal_']];
                $currentPos += strlen($matches['_literal_']);
            }

            # Deal With Token:
            if ( !isset($matches['_token_']) || $matches['_token_'] == '' )
                continue;

            $currentPos += strlen($matches['_token_']);
            $Token = $matches['_token_'];

            ## Regular Expression Token
            #
            #
            if ($Token === '~') {
                // ^ match any character that is not in list
                $pmatch = preg_match("/~(?P<_delimiter_>[^~]+)~/"
                    , $criteria
                    , $matches
                    , 0
                    , 0
                );
                if (! $pmatch )
                    throw new \RuntimeException('Miss usage of ~ ~ token.');

                $val['_regex_'] = $matches['_delimiter_'];
                $levelParts[$level][] = $val;

                $currentPos += strlen($matches[0])+2/*~x~*/;
            }
            ##
            # Variable
            # /:hash_id~\w{24}~
            #
            elseif ($Token === ':') {
                // ^$TOKENS  match any character that is not in list
                $pmatch = preg_match("(\G(?P<_name_>[^$TOKENS]+)(?:~(?P<_delimiter_>[^~]+)~)?:?)"
                    , $criteria
                    , $matches
                    , 0
                    , $currentPos
                );

                if (! $pmatch && !(isset($matches['_name_']) && isset($matches['_delimiter_'])) )
                    throw new \RuntimeException(
                        'Found empty parameter name or delimiter on (%s).'
                        , $criteria
                    );

                $parameter = $matches['_name_'];
                $val       = ['_parameter_' => $parameter];
                if (isset($matches['_delimiter_']))
                    $val[$parameter] = $matches['_delimiter_'];

                $levelParts[$level][] = $val;
                $currentPos += strlen($matches[0]);
            }

            ## Literal Token
            #  localhost\:port
            #
            elseif ($Token === '\\') {
                // Consider next character as Literal
                $nextChar = $currentPos += 1;
                $levelParts[$level][]   = ['_literal_' => $criteria[$nextChar]];
            }

            ## Optional Part
            #  /<u/:username~[a-zA-Z0-9._]+~><-:userid~\w{24}~>
            #
            elseif ($Token === '<') {
                if (! isset($va) ) {
                    $va = [];
                    $n = 0;
                }

                $n++;
                $va[$n] = [];
                $levelParts[$level][] = ['_optional_' => &$va[$n]];
                $level++;
                $levelParts[$level] = &$va[$n];
            }
            ## Close Optional ##
            elseif ($Token === '>') {
                unset($levelParts[$level]);
                $level--;

                if ($level < 0)
                    throw new \RuntimeException('Found closing bracket without matching opening bracket');
            }

            else
                // Recognized unused token return immanently
                $levelParts[$level][]   = ['_token_' => $Token];

        } // end while

        if ($level > 0)
            throw new \RuntimeException('Found unbalanced brackets');


        return ParsedCriteria::of($parts);
    }
1136907
public void parse() throws AuthHeaderParsingException {

		String[] parts = headerValue.trim().split("\\s+", 2);
		if (parts.length < 1) {
			throw new AuthHeaderParsingException("Unable to split scheme and other part in " + headerValue);
		}

		builder.scheme(parts[0]);
		
		if(parts.length == 1) {
			return;
		}
		
		// FIXME: handle optional, one-time token

		for (String kv : parts[1].split(",")) {
			String[] kva = kv.trim().split("=", 2);
			if (!(kva.length == 2)) {
				throw new AuthHeaderParsingException("Unable to split " + kv + " into parameter key and value in " + headerValue);
			}
			if (kva[1].startsWith("\"")) {
				kva[1] = kva[1].substring(1, kva[1].length() - 1);
			}
			builder.param(kva[0], kva[1]);
		}
	}
238958
protected function _parseFunction() {
        $this->_content = preg_replace('`' . $this->_openTag . $this->_name . preg_quote($this->markup['function'][0]) . $this->_spaceR . preg_quote($this->markup['function'][1]) . $this->_space . '=' . $this->_space . '"' . $this->_space . '(.+)' . $this->_space . '"' . $this->_space . '/' . $this->_closeTag . '`isU', '<?php $1 ?>', $this->_content);
    }
425539
function (header) {
    this.httpHeader = parseHTTPHeader(header);

    if (this.httpHeader[ 'content-length' ]) this.size = this.httpHeader[ 'content-length' ];

    if (this.httpHeader[ 'content-type' ]) this.mime = this.httpHeader[ 'content-type' ];

    if (this.httpHeader[ 'last-modified' ]) this.lastModified = new Date(this.httpHeader[ 'last-modified' ]);
  }
1004369
function parse(c) {

  let ret = [];

  // replace windows line breaks with linux line breaks
  let c1 = c.replace(new RegExp('[\r][\n]', 'g'), '\n');

  // split string to line array
  let c2 = c1.split('\n');

  for (let i = 0; i < c2.length; i++) {

    //line object
    let lo = {};

    // line
    let l = c2[i];

    // trim line
    let l1 = l.trim();

    // set line number
    lo.num = i + 1;

    // set original line
    lo.content = l1;

    // check empty line
    if (l1 === '') {
      lo.isEmpty = true;
    } else {
      lo.isEmpty = false;

      // check line comment
      if (l1.startsWith('#')) {
        lo.isComment = true;
        lo.comment = lo.content.substring(1,lo.content.length).trim();
      } else {
        lo.isComment = false;

        // Check included comments
        lo = Object.assign(lo, checkComment(l1));

        // check key value
        lo = Object.assign(lo, checkKeyValue(lo.contentWithoutComment));

        // check block key
        lo = Object.assign(lo, checkBlockKey(lo));
        
    
      }
    }

    //console.log(lo);

    ret.push(lo);
  }

  checkBlockEndSum(ret);
  determineDepth(ret);

  return ret;
}
1198947
function parse($data)
    {
        $_header = strstr($data, self::HTTP_EOF, true);
        if ($_header === false)
        {
            $this->buffer = $data;
        }
        $header = self::parseHeader($_header);
        if ($header === false)
        {
            $this->isError = true;
        }
        $this->header = $header;
        return $header;
    }
979683
function parseString($html) {
    $this->parser->html = $html;
    $this->parse();
    return $this->output;
  }
41665
function parse() {
    $this->output = '';
    # drop tags
    $this->parser->html = preg_replace('#<('.implode('|', $this->drop).')[^>]*>.*</\\1>#sU', '', $this->parser->html);
    while ($this->parser->nextNode()) {
      switch ($this->parser->nodeType) {
        case 'doctype':
          break;
        case 'pi':
        case 'comment':
          if ($this->keepHTML) {
            $this->flushLinebreaks();
            $this->out($this->parser->node);
            $this->setLineBreaks(2);
          }
          # else drop
          break;
        case 'text':
          $this->handleText();
          break;
        case 'tag':
          if (in_array($this->parser->tagName, $this->ignore)) {
            break;
          }
          if ($this->parser->isStartTag) {
            $this->flushLinebreaks();
          }
          if ($this->skipConversion) {
            $this->isMarkdownable(); # update notConverted
            $this->handleTagToText();
            continue;
          }
          if (!$this->parser->keepWhitespace && $this->parser->isBlockElement && $this->parser->isStartTag) {
            $this->parser->html = ltrim($this->parser->html);
          }
          if ($this->isMarkdownable()) {
            if ($this->parser->isBlockElement && $this->parser->isStartTag && !$this->lastWasBlockTag && !empty($this->output)) {
              if (!empty($this->buffer)) {
                $str =& $this->buffer[count($this->buffer) -1];
              } else {
                $str =& $this->output;
              }
              if (substr($str, -strlen($this->indent)-1) != "\n".$this->indent) {
                $str .= "\n".$this->indent;
              }
            }
            $func = 'handleTag_'.$this->parser->tagName;
            $this->$func();
            if ($this->linksAfterEachParagraph && $this->parser->isBlockElement && !$this->parser->isStartTag && empty($this->parser->openTags)) {
              $this->flushStacked();
            }
            if (!$this->parser->isStartTag) {
              $this->lastClosedTag = $this->parser->tagName;
            }
          } else {
            $this->handleTagToText();
            $this->lastClosedTag = '';
          }
          break;
        default:
          trigger_error('invalid node type', E_USER_ERROR);
          break;
      }
      $this->lastWasBlockTag = $this->parser->nodeType == 'tag' && $this->parser->isStartTag && $this->parser->isBlockElement;
    }
    if (!empty($this->buffer)) {
      trigger_error('buffer was not flushed, this is a bug. please report!', E_USER_WARNING);
      while (!empty($this->buffer)) {
        $this->out($this->unbuffer());
      }
    }
    ### cleanup
    $this->output = rtrim(str_replace('&amp;', '&', str_replace('&lt;', '<', str_replace('&gt;', '>', $this->output))));
    # end parsing, flush stacked tags
    $this->flushStacked();
    $this->stack = array();
  }
93737
public function parseHeader()
    {
        //$header = explode("\r\n", rtrim($this->response['headerRaw'], "\r\n"));
        
        $rawHeaders = rtrim($this->response['headerRaw'], "\r\n");
        # Handle multiple responses e.g. with redirections (proxies too)
        $headerGroups = explode("\r\n\r\n", $rawHeaders);
        # We're only interested in the last one
        $header = explode("\r\n", end($headerGroups));

        $output = array();

        if ('HTTP' === substr($header[0], 0, 4)) {
            list($output['version'], $output['status']) = explode(' ', $header[0]);
            unset($header[0]);
        }

        foreach ($header as $entry) {
            $pos = strpos($entry, ':');
            $output[trim(substr($entry, 0, $pos))] = trim(substr($entry, $pos + 1));
        }

        $this->response['header'] = $output;
        return $this;
    }
1131523
function parse (string) {
  if (!string) {
    throw new TypeError('argument string is required')
  }

  // support req/res-like objects as argument
  var header = typeof string === 'object'
    ? getcontenttype(string)
    : string

  if (typeof header !== 'string') {
    throw new TypeError('argument string is required to be a string')
  }

  var index = header.indexOf(';')
  var type = index !== -1
    ? header.substr(0, index).trim()
    : header.trim()

  if (!TYPE_REGEXP.test(type)) {
    throw new TypeError('invalid media type')
  }

  var obj = new ContentType(type.toLowerCase())

  // parse parameters
  if (index !== -1) {
    var key
    var match
    var value

    PARAM_REGEXP.lastIndex = index

    while ((match = PARAM_REGEXP.exec(header))) {
      if (match.index !== index) {
        throw new TypeError('invalid parameter format')
      }

      index += match[0].length
      key = match[1].toLowerCase()
      value = match[2]

      if (value[0] === '"') {
        // remove quotes and escapes
        value = value
          .substr(1, value.length - 2)
          .replace(QESC_REGEXP, '$1')
      }

      obj.parameters[key] = value
    }

    if (index !== header.length) {
      throw new TypeError('invalid parameter format')
    }
  }

  return obj
}
818563
public function parseHeader($header)
    {
        $parsed_header = array();

        $header_lines = explode("\r\n", $header);
        if (count($header_lines) > 0) {
            foreach ($header_lines as $line) {
                $header = explode(':', $line);
                if (count($header) > 1) {
                    $label = array_shift($header);

                    $value = $header;
                    $value = implode(':', $header);
                    $value = trim($value);

                    $parsed_header[$label] = $value;
                }
            }
        }

        return $parsed_header;
    }
1326951
function parse(headers) {
    var output = {}, i, p, k, v;
    headers = headers || '';
    headers = headers.replace('\r', '');
    headers = headers.split('\n');
    for(i = 0;i < headers.length;i++) {
      p = headers[i].indexOf(':');
      k = headers[i].substr(0, p);
      v = headers[i].substr(p + 1);
      if(k && v) {
        k = k.replace(/^\s+/, '').replace(/\s+$/, '');
        v = v.replace(/^\s+/, '').replace(/\s+$/, '');
        output[k.toLowerCase()] = v;
      }
    }
    return output;
  }