<commit_before><?php

class Page {
  function __construct($name = '') {
    $this->name = $name ? $name : 'index';
    $this->text = '';
  }

  function filepath() {
    return dirname(__FILE__) . '/../' . EDITH_DATA_PATH . '/' . str_replace('.', '_', $this->name) . '.txt';
  }

  function name() {
    $name = str_replace('_', ' ', $this->name);
    $name = str_replace('-', ' ', $name);
    $name = ucwords($name);
    return $name;
  }

  function has_safe_name() {
    return preg_match("/^[a-z0-9-._ ]+$/i", $this->name);
  }

  function exists() {
    return is_file($this->filepath());
  }

  function load() {	
    $this->text = 'Edit me!';
    if ($this->exists())
      $this->text = file_get_contents($this->filepath());
  }

  function save() {
    if ($this->text == '') {
      if ($this->exists())
        $this->delete(); // delete empty files
      return;
    }

    $handle = @fopen($this->filepath(), 'w');
    if (!$handle)
      throw new Exception('Error opening the file in write mode');

    $ok = @fwrite($handle, $this->text);
    if (!$ok) return false;
    fclose($handle);
    return true;
  }

  function delete() {
    return unlink($this->filepath());
  }

  function is_writeable() {
    return is_writeable($this->filepath());
  }
}

<commit_msg>Force \n in text files<commit_after><?php

class Page {
  function __construct($name = '') {
    $this->name = $name ? $name : 'index';
    $this->text = '';
  }

  function filepath() {
    return dirname(__FILE__) . '/../' . EDITH_DATA_PATH . '/' . str_replace('.', '_', $this->name) . '.txt';
  }

  function name() {
    $name = str_replace('_', ' ', $this->name);
    $name = str_replace('-', ' ', $name);
    $name = ucwords($name);
    return $name;
  }

  function has_safe_name() {
    return preg_match("/^[a-z0-9-._ ]+$/i", $this->name);
  }

  function exists() {
    return is_file($this->filepath());
  }

  function load() {	
    $this->text = 'Edit me!';
    if ($this->exists())
      $this->text = file_get_contents($this->filepath());
  }

  function save() {
    if ($this->text == '') {
      if ($this->exists())
        $this->delete(); // delete empty files
      return;
    }

    $handle = @fopen($this->filepath(), 'w');
    if (!$handle)
      throw new Exception('Error opening the file in write mode');

    $this->text = str_replace("\r\n", "\n", $this->text); // CRLF to LF

    $ok = @fwrite($handle, $this->text);
    if (!$ok) return false;
    fclose($handle);
    return true;
  }

  function delete() {
    return unlink($this->filepath());
  }

  function is_writeable() {
    return is_writeable($this->filepath());
  }
}


{'fraction_non_alphanumeric': 0.21541950113378686, 'fraction_numerical': 0.0015117157974300832, 'mean_word_length': 2.6815020862308763, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '3782075', 'n_tokens_mistral': 933, 'n_tokens_neox': 908, 'n_words': 195}