<commit_before>use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::io;

pub struct Cartridge(pub Vec<u8>);

impl Cartridge {
    /// Load rom file
    pub fn new<P: AsRef<Path>>(path: P) -> io::Result<Cartridge> {
        let mut rom: Vec<u8> = Vec::new();
        let mut file = File::open(path)?;
        let _ = file.read_to_end(&mut rom)?;
        Ok(Cartridge(rom))
    }

    /// Read a byte from the rom
    pub fn read_byte(&self, addr: usize) -> u8 {
        self.0[addr]
    }

    /// Read a range of bytes from the rom
    pub fn read_range(&self, addr: usize, end: usize) -> Vec<u8> {
        let mut a: Vec<u8> = Vec::new();
        for x in addr..end {
            a.push(self.0[x])
        }
        a
    }
}
<commit_msg>read title<commit_after>use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::io;

pub struct Cartridge(pub Vec<u8>);

impl Cartridge {

    /// Load rom file
    pub fn new<P: AsRef<Path>>(path: P) -> io::Result<Cartridge> {
        let mut rom: Vec<u8> = Vec::new();
        let mut file = File::open(path)?;
        let _ = file.read_to_end(&mut rom)?;
        Ok(Cartridge(rom))
    }

    /// Read a byte from the rom
    pub fn read_byte(&self, addr: usize) -> u8 {
        self.0[addr]
    }

    /// Read a range of bytes from the rom
    pub fn read_range(&self, addr: usize, end: usize) -> Vec<u8> {
        let mut a: Vec<u8> = Vec::new();
        for x in addr..end {
            a.push(self.0[x])
        }
        a
    }

    pub fn read_title(&self) -> String {
        let mut title = String::with_capacity(16);
        for letter in self.read_range(0x0134, 0x0142) {
            if letter == 0 {
                break;
            }
            title.push(letter as char)
        }
        title
    }


}

#[test]
fn get_name() {
    let rom = Cartridge::new("./rom/tetris.gb").unwrap();
    assert_eq!(rom.read_title(), "TETRIS")
}


{'fraction_non_alphanumeric': 0.1592920353982301, 'fraction_numerical': 0.014055179593961478, 'mean_word_length': 2.0220125786163523, 'pattern_counts': {'":': 0, '<': 17, '<?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': '4471781', 'n_tokens_mistral': 700, 'n_tokens_neox': 686, 'n_words': 182}