<commit_before><?php

namespace mdref;

/**
 * A ref entry file
 */
class File {
	/**
	 * @var resource
	 */
	private $fd;

	/**
	 * Open the file
	 * @param string $path
	 */
	public function __construct($path) {
		$this->fd = fopen($path, "rb");
	}

	/**
	 * Read the title of the refentry
	 * @return string
	 */
	public function readTitle() {
		if ($this->rewind(1)) {
			return fgets($this->fd);
		}
	}

	/**
	 * Read the description (first line) of the refentry
	 * @return string
	 */
	public function readDescription() {
		if ($this->rewind()
		&& (false !== fgets($this->fd))
		&& (false !== fgets($this->fd))) {
			return fgets($this->fd);
		}
	}

	/**
	 * Read the full description (first section) of the refentry
	 * @return string
	 */
	public function readFullDescription() {
		$desc = $this->readDescription();
		while (false !== ($line = fgets($this->fd))) {
			if ($line{0} === "#") {
				break;
			} else {
				$desc .= $line;
			}
		}
		return $desc;
	}

	/**
	 * Read the first subsection of a global refentry
	 * @return string
	 */
	public function readIntro() {
		$intro = "";
		if ($this->rewind()) {
			$header = false;

			while (!feof($this->fd)) {
				if (false === ($line = fgets($this->fd))) {
					break;
				}
				/* search first header and read until next header*/
				if ($this->isHeading($line)) {
					if ($header) {
						break;
					} else {
						$header = true;
						continue;
					}
				}
				if ($header) {
					$intro .= $line;
				}
			}
		}
		return $intro;
	}

	public function readSection($title) {
		$section = "";
		if ($this->rewind()) {
			while (!feof($this->fd)) {
				if (false === ($line = fgets($this->fd))) {
					break;
				}
				/* search for heading with $title and read until next heading */
				if ($this->isHeading($line, $title)) {
					do {
						if (false === $line = fgets($this->fd)) {
							break;
						}
						if ($this->isHeading($line)) {
							break;
						}
						$section .= $line;
					} while (true);
				}
			}
		}
		return $section;
	}

	private function rewind($offset = 0) {
		return 0 === fseek($this->fd, $offset, SEEK_SET);
	}

	private function isHeading(string $line, string $title = null) {
		if ("## " !== substr($line, 0, 3)) {
			return false;
		}
		if (isset($title)) {
			return !strncmp(substr($line, 3), $title, strlen($title));
		}
		return true;
	}
}<commit_msg>no type decls, yet<commit_after><?php

namespace mdref;

/**
 * A ref entry file
 */
class File {
	/**
	 * @var resource
	 */
	private $fd;

	/**
	 * Open the file
	 * @param string $path
	 */
	public function __construct($path) {
		$this->fd = fopen($path, "rb");
	}

	/**
	 * Read the title of the refentry
	 * @return string
	 */
	public function readTitle() {
		if ($this->rewind(1)) {
			return fgets($this->fd);
		}
	}

	/**
	 * Read the description (first line) of the refentry
	 * @return string
	 */
	public function readDescription() {
		if ($this->rewind()
		&& (false !== fgets($this->fd))
		&& (false !== fgets($this->fd))) {
			return fgets($this->fd);
		}
	}

	/**
	 * Read the full description (first section) of the refentry
	 * @return string
	 */
	public function readFullDescription() {
		$desc = $this->readDescription();
		while (false !== ($line = fgets($this->fd))) {
			if ($line{0} === "#") {
				break;
			} else {
				$desc .= $line;
			}
		}
		return $desc;
	}

	/**
	 * Read the first subsection of a global refentry
	 * @return string
	 */
	public function readIntro() {
		$intro = "";
		if ($this->rewind()) {
			$header = false;

			while (!feof($this->fd)) {
				if (false === ($line = fgets($this->fd))) {
					break;
				}
				/* search first header and read until next header*/
				if ($this->isHeading($line)) {
					if ($header) {
						break;
					} else {
						$header = true;
						continue;
					}
				}
				if ($header) {
					$intro .= $line;
				}
			}
		}
		return $intro;
	}

	public function readSection($title) {
		$section = "";
		if ($this->rewind()) {
			while (!feof($this->fd)) {
				if (false === ($line = fgets($this->fd))) {
					break;
				}
				/* search for heading with $title and read until next heading */
				if ($this->isHeading($line, $title)) {
					do {
						if (false === $line = fgets($this->fd)) {
							break;
						}
						if ($this->isHeading($line)) {
							break;
						}
						$section .= $line;
					} while (true);
				}
			}
		}
		return $section;
	}

	private function rewind($offset = 0) {
		return 0 === fseek($this->fd, $offset, SEEK_SET);
	}

	private function isHeading($line, $title = null) {
		if ("## " !== substr($line, 0, 3)) {
			return false;
		}
		if (isset($title)) {
			return !strncmp(substr($line, 3), $title, strlen($title));
		}
		return true;
	}
}
{'fraction_non_alphanumeric': 0.1906680805938494, 'fraction_numerical': 0.0029692470837751855, 'mean_word_length': 2.4473684210526314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1493514', 'n_tokens_mistral': 2043, 'n_tokens_neox': 1621, 'n_words': 419}