/*
Parsing HTML strings
551623
function canParseHTMLNatively () {
  var Parser = root.DOMParser
  var canParse = false

  // Adapted from https://gist.github.com/1129031
  // Firefox/Opera/IE throw errors on unsupported types
  try {
    // WebKit returns null on unsupported types
    if (new Parser().parseFromString('', 'text/html')) {
      canParse = true
    }
  } catch (e) {}

  return canParse
}
864744
function parseString(opts) {
    var obj = new Obj();

    opts.split(' ').forEach(function (item) {
        var data = splitByColon(item);
        obj[data.key] = data.val;
    });

    return obj;
}
427931
public function parseFromString($string){
		$dom = $this->html5->loadHTML($string);
		if( is_a($dom, 'DOMDocument') ){
			return $dom;
		}else{
			return false;
		}
	}
471359
function ReadMetaTags($html)
	{
		// changes anykey=anyvalue to anykey="anyvalue" (only do this when this happens inside tags)
		$regexp = '/ (\\w+?)=([^\\s>"]+)/si';
		$html = preg_replace($regexp, " \$1=\"\$2\"", $html);
		if (preg_match('/<title>(.*?)<\/title>/si', $html, $m)) {
			$this->SetTitle($m[1]);
		}
		preg_match_all('/<meta [^>]*?(name|content)="([^>]*?)" [^>]*?(name|content)="([^>]*?)".*?>/si', $html, $aux);
		$firstattr = $aux[1];
		$secondattr = $aux[3];
		for ($i = 0; $i < count($aux[0]); $i++) {
			$name = ( strtoupper($firstattr[$i]) == "NAME" ) ? strtoupper($aux[2][$i]) : strtoupper($aux[4][$i]);
			$content = ( strtoupper($firstattr[$i]) == "CONTENT" ) ? $aux[2][$i] : $aux[4][$i];
			switch ($name) {
				case "KEYWORDS":
					$this->SetKeywords($content);
					break;
				case "AUTHOR":
					$this->SetAuthor($content);
					break;
				case "DESCRIPTION":
					$this->SetSubject($content);
					break;
			}
		}
	}
323290
function parseSearchResults (html) {
  const $ = cheerio.load(html)
  return $('a')
    .filter(function (index, element) {
      const spans = $(element).find('span')
      return spans.length === 2 && spans.eq(0).text().trim() === 'English'
    })
    .map(function (index, element) {
      const title = $(element).find('span').eq(1).text().trim()
      const url = $(element).attr('href')
      return new SearchResult({
        title: title,
        url: url
      })
    })
    .get()
}
1212795
function parseQueryString(query) {
  const result = {};

  _.each(query.replace(/\+/g, ' ').split('&'), (key) => {
    const index = key.indexOf('=');
    let val = '';

    if (index >= 0) {
      val = decodeURIComponent(key.slice(index + 1));
      key = key.slice(0, index);
    }
    if (!key) return;

    key = decodeURIComponent(key);

    // brackets notation for array value
    if (key.slice(-2) === '[]') {
      key = key.slice(0, -2);
      val = [val];
    }

    // if there are multiple values per key, concatenate
    result[key] = _.has(result, key) ? [].concat(result[key], val) : val;
  });

  return result;
}
421609
function parseQueryString(string) {
    return _.transform(_.toString(string).split('&'), (result, segment) => {
        const split = segment.split('=');
        result[decodeURIComponent(split[0])] = decodeURIComponent(split[1]);
    }, {});
}
314154
function parseArray(tag, attrs, content, indentStr, indentLevel) {
    let html = '';
    for (let item of content) {
        if (getType(item)==='object') {
            let innerAttrs = getAttributes(item);
            let innerContent = TEXT in item ? item[TEXT] : '';
            html += renderElement(tag, innerAttrs, innerContent, indentStr, indentLevel);
        } else {
            html += renderElement(tag, attrs, item, indentStr, indentLevel);
        }
    }
    return html;
}
1340746
function parse($html)
		{
			$dom = new \DOMDocument();
			libxml_use_internal_errors(true);
			$dom->loadHTML($html);
			$xpath = new \DOMXPath($dom);
			
			// Load resources for tag actions
			$this->ignoreElements = new ResourceProvider("html_tag_actions/ignore.lst");
			$this->linkElements = new ResourceProvider("html_tag_actions/link.lst");
			$this->bodyElements = new ResourceProvider("html_tag_actions/body.lst");
			$this->inlineElements = new ResourceProvider("html_tag_actions/inline.lst");
			
			/*	
			 *  1st retrieve page title
			 *  With this technique: only process the entire document here 
			 *  as meta is excluded as 'content' and only required for initial title.
			 */

			// Extract title from DOM
			$body = $xpath->query('/')->item(0);
			$titleItem = $xpath->query('//title')->item(0);
			
			if(isset($titleItem))
			{
				$title = $titleItem->textContent;
			}
			$body = $xpath->query('//body')->item(0);
			
			// Try to extract title from OG meta
			foreach ($xpath->query("//meta[@property='og:title']") as $el) 
			{
				$title = $el->getAttribute("content");
			}
			
			$this->recurse($body);
			$Article = new Article();
			if(isset($title))
			{
				$Article->title = $title;
			}
			$Article->textBlocks = $this->textBlocks;
			return $Article;
		}
458881
function parse (string) {
  var result = jsonmatter.parse(string, {
    regex: /^[\s\t\n\r]*---{1}[\s\t\n\r]*(\{[\s\S]*\}[\s\t\n\r]*)(---{1})/
  })
  var markdown        = result.__content__
  var html            = marked(markdown).replace(/\r?\n|\r/g, "")
  result.__content__  = patch(html, result.custom)
  return result
}
653356
function htmlDecode(input) {
  if (input === " ") return input;
  const doc = new DOMParser().parseFromString(input.replace(/<[^>]+>/g, ""), "text/html");
  return doc.documentElement.textContent;
}
979683
function parseString($html) {
    $this->parser->html = $html;
    $this->parse();
    return $this->output;
  }
672294
function processHTML(cssSelectors = [], htmlDataIn = null, htmlOptionsIn = null) {

		//read html files
		if (OPTIONS.html !== '' && OPTIONS.html !== undefined && OPTIONS.special_reduce_with_html) {

			var htmlFiles = OPTIONS.html;
			tmpHTMLPaths = [];

			//check for file or files
			switch (typeof htmlFiles) {
				case 'object':
				case 'array':
						
					for (i = 0; i < htmlFiles.length; ++i) {

						getFilePaths(htmlFiles[i], ['.html','.htm']);
					}

					if (tmpHTMLPaths.length) {
						htmlFiles = tmpHTMLPaths;
					}
					break;
				case 'string':
					//formats
					htmlFiles = htmlFiles.replace(/ /g, '');

					// comma delimited list - filename1.html, filename2.html
					if (htmlFiles.indexOf(',') > -1) { 
			
						htmlFiles = htmlFiles.replace(/^\s+|\s+$/g,'').split(',');
						tmpStr = '';
						for (i = 0; i < htmlFiles.length; ++i) {

							getFilePaths(htmlFiles[i], ['.html','.htm']);

						} //end of for

						if (tmpHTMLPaths.length) {
							htmlFiles = tmpHTMLPaths;
						}

					} else {

						//string path
						getFilePaths(htmlFiles, ['.html','.htm']);

						if (tmpHTMLPaths.length) {
							htmlFiles = tmpHTMLPaths;
						}

					}

					break;
			} //end of switch

			htmlFileLocation = (htmlFiles)?htmlFiles.toString():htmlFiles;

			readHTMLFile(htmlFiles);
			CPEVENTS.on('HTML_READ_AGAIN', function(){
				//process selectors
				processHTMLSelectors(cssSelectors, htmlDataIn, htmlOptionsIn);

				//read next file
				dataHTMLIn = [];
				readHTMLFile(htmlFiles);
			});
			CPEVENTS.on('HTML_READ_END', function(){
				//process selectors
				processHTMLSelectors(cssSelectors, htmlDataIn, htmlOptionsIn);

				dataHTMLIn = [];
				CPEVENTS.emit('HTML_RESULTS_END', cssSelectors);

			});


		} //end of html files check








	}
298669
function parse (headers) {
  if (headers.slice(0,4).toLowerCase() == 'http') {
    var newlineIndex = headers.indexOf('\r\n');
    headers = headers.slice(newlineIndex + 2);
  }
  return parseHeaders(headers);
}
488910
function parseVariableDeclarations(string) {
  // Do not parse empty files. Otherwise gonzales.parse will fail
  if (!string) {
    return [];
  }

  var out = [],
      ast = gonzales.parse(string, {
        syntax: syntax
      }),
      visitor = {
        // Visitor for SASS, SCSS and plain CSS syntaxes
        test: function(name, nodes) {
          if (name !== 'declaration') {
            return false;
          }

          if (
              nodes.content[0] &&
              nodes.content[0].content &&
              nodes.content[0].content[0] &&
              nodes.content[0].content[0].type &&
              nodes.content[0].content[0].type === 'variable'
            ) {
            return true;
          }

        },
        process: function(nodes) {
          var varName = nodes.content[0].content[0].content[0].content;

          // trim the spaces
          var content = nodes.content.filter(function(item) {
            return (item.type !== 'space');
          });

          if (content[2] && content[2].type && content[2].type === 'value') {
            out.push({
              name: varName,
              value: content[2].toString(syntax),
              line: content[2].start.line
            });
          }
        }
      };

  traverser.traverse(ast, visitor);
  return out;
}
264573
function parse($str) {
		preg_match_all('/(\w+|\*)\h*=\h*(?:\[(.+?)\]|(.+?))(?=,|$)/',
			$str,$pairs,PREG_SET_ORDER);
		$out=[];
		foreach ($pairs as $pair)
			if ($pair[2]) {
				$out[$pair[1]]=[];
				foreach (explode(',',$pair[2]) as $val)
					array_push($out[$pair[1]],$val);
			}
			else
				$out[$pair[1]]=trim($pair[3]);
		return $out;
	}
913203
function parse(html) {
  // compatibility with the old signature
  html = arguments[arguments.length - 1];

  var items      = [];
  var parsedHTML = $.load(html);

  parsedHTML('[itemtype]').map(function (i, item) {
    processItemtype(item, items);
  });

  parsedHTML('[itemprop]').map(function (i, item) {
    processItemprop(item, items);
  });

  return exports.returnJson ? JSON.stringify(items) : items;
}