<commit_before>use std::fs;
use std::io;
use std::io::Read;

pub struct Buffer {
    pub contents: String,
}

impl Buffer {

    pub fn load_from_file(path: String) -> Result<Buffer, io::Error> {
        Ok(Buffer { contents: try!(read_file(path)) })
    }

    pub fn empty() -> Buffer {
    	Buffer{contents: "".to_string()}
    }

    fn print(&self) {
        println!("{}", self.contents)
    }

    pub fn head(&self, n: usize) -> String {
        self.contents[..n].to_string()
    }

    pub fn line(&self, i: i32) -> &str {
        match self.contents.split('\n').nth(i as usize) {
            Some(s) => s,
            None => "",
        }
    }
}

fn open_file(path: String) {
    match read_file(path) {
        Ok(contents) => println!("{}", contents),
        Err(e) => println!("Could not open file: {}", e),
    }
}

fn read_file(path: String) -> Result<String, io::Error> {
    let mut f = try!(fs::File::open(path));<commit_msg>buffers have a file name<commit_after>use std::fs;
use std::io;
use std::io::Read;

pub struct Buffer {
    pub contents: String,
    pub file_path: Option<String>,
}

impl Buffer {

    /** Creators **/

    pub fn load_from_file(path: String) -> Result<Buffer, io::Error> {
        Ok(Buffer {
	    contents: try!(read_file(&path)),
	    file_path: Some(path)
	})
    }

    pub fn empty() -> Buffer {
    	Buffer{contents: "".to_string(), file_path: None}
    }

    /** Observers **/

    pub fn head(&self, n: usize) -> String {
        self.contents[..n].to_string()
    }

    pub fn line(&self, i: i32) -> &str {
        match self.contents.split('\n').nth(i as usize) {
            Some(s) => s,
            None => "",
        }
    }
}

fn read_file(path: &String) -> Result<String, io::Error> {
    let mut f = try!(fs::File::open(path));
{'fraction_non_alphanumeric': 0.18252643294379522, 'fraction_numerical': 0.0022259321090706734, 'mean_word_length': 2.411764705882353, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 24, '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': '4066069', 'n_tokens_mistral': 632, 'n_tokens_neox': 627, 'n_words': 146}