<commit_before>use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::fmt;

use regex::Regex;

pub mod id;
pub mod id_type;
pub mod header;
pub mod hash;


use module::Module;
use storage::file::id::*;
use storage::file::id_type::FileIDType;
use storage::file::hash::FileHash;
use super::parser::{FileHeaderParser, Parser, ParserError};

use self::header::spec::*;
use self::header::data::*;

/*
 * Internal abstract view on a file. Does not exist on the FS and is just kept
 * internally until it is written to disk.
 */
pub struct File {
    pub owning_module_name  : &'static str,
    pub header              : FileHeaderData,
    pub data                : String,
    pub id                  : FileID,
}

impl File {

    pub fn owner_name(&self) -> &'static str {
        self.owning_module_name
    }

    pub fn header(&self) -> &FileHeaderData {
        &self.header
    }

    pub fn data(&self) -> &String {
        &self.data
    }

    pub fn contents(&self) -> (&FileHeaderData, &String) {
        (self.header(), self.data())
    }

    pub fn id(&self) -> &FileID {
        &self.id
    }

    pub fn matches_with(&self, r: &Regex) -> bool {
        r.is_match(&self.data[..]) || self.header.matches_with(r)
    }

}

impl Display for File {

    fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
        write!(fmt,
"[File] Owner : '{:?}'
        FileID: '{:?}'
        Header: '{:?}'
        Data  : '{:?}'",
               self.owning_module_name,
               self.header,<commit_msg>Add File::set_header()<commit_after>use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::fmt;

use regex::Regex;

pub mod id;
pub mod id_type;
pub mod header;
pub mod hash;


use module::Module;
use storage::file::id::*;
use storage::file::id_type::FileIDType;
use storage::file::hash::FileHash;
use super::parser::{FileHeaderParser, Parser, ParserError};

use self::header::spec::*;
use self::header::data::*;

/*
 * Internal abstract view on a file. Does not exist on the FS and is just kept
 * internally until it is written to disk.
 */
pub struct File {
    pub owning_module_name  : &'static str,
    pub header              : FileHeaderData,
    pub data                : String,
    pub id                  : FileID,
}

impl File {

    pub fn owner_name(&self) -> &'static str {
        self.owning_module_name
    }

    pub fn header(&self) -> &FileHeaderData {
        &self.header
    }

    pub fn set_header(&mut self, new_header: FileHeaderData) {
        self.header = new_header;
    }

    pub fn data(&self) -> &String {
        &self.data
    }

    pub fn contents(&self) -> (&FileHeaderData, &String) {
        (self.header(), self.data())
    }

    pub fn id(&self) -> &FileID {
        &self.id
    }

    pub fn matches_with(&self, r: &Regex) -> bool {
        r.is_match(&self.data[..]) || self.header.matches_with(r)
    }

}

impl Display for File {

    fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
        write!(fmt,
"[File] Owner : '{:?}'
        FileID: '{:?}'
        Header: '{:?}'
        Data  : '{:?}'",
               self.owning_module_name,
               self.header,
{'fraction_non_alphanumeric': 0.15408904325860437, 'fraction_numerical': 0.0, 'mean_word_length': 2.4698795180722892, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '5865753', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1025, 'n_words': 274}