<commit_before>use std::io::IoResult;
use std::collections::hashmap::HashMap;
use std::str::from_utf8;

use super::{get_file_reader, get_file_writer};

macro_rules! parse_word(
    ($iter:ident, $word:ident, $breaker:pat, $next:expr) => (
        match $iter.next() {
            Some(Ok($breaker)) => break,
            Some(Ok(c)) => $word.push(c),
            Some(Err(e)) => return Err(e),
            None => $next
        }
    );
)

pub fn generate(list: Path, module: Path) -> IoResult<()> {
    let mut reader = get_file_reader(list);
    let mut writer = get_file_writer(module);

    try!(writer.write(
b"// This automatically generated file is included in response.rs.
use std::path::BytesContainer;

use http::headers::content_type::MediaType;

pub fn get_content_type(path: &Path) -> Option<MediaType> {
    let path_str = path.container_as_str().unwrap();
    let ext_pos = regex!(\".[a-z0-9]+$\").find(path_str);
    let mut ext;
    match ext_pos {
        Some((start, _)) => {
            ext = path_str.as_slice().slice_from(start);
        },
        None => return None
    }
<commit_msg>(feat) Refactored to modularize generator.<commit_after>use std::io::IoResult;
use std::collections::hashmap::HashMap;
use std::str::from_utf8;

use super::{get_file_reader, get_file_writer};

macro_rules! parse_word(
    ($iter:ident, $word:ident, $breaker:pat, $next:expr) => (
        // Loop to parse a word out of a line
        match $iter.next() {
            Some(Ok($breaker)) => break,
            Some(Ok(c)) => $word.push(c),
            Some(Err(e)) => return Err(e),
            None => $next
        }
    );
)

// Generate response/mimegen.rs
pub fn generate(list: Path, module: Path) -> IoResult<()> {
    let mut reader = get_file_reader(list);
    let mut writer = get_file_writer(module);

    try!(writer.write(
b"// This automatically generated file is included in response/mimes.rs.

use http::headers::content_type::MediaType;

pub fn get_generated_content_type(ext: &str) -> Option<MediaType> {
{'fraction_non_alphanumeric': 0.15919172005914242, 'fraction_numerical': 0.001971414489896501, 'mean_word_length': 3.282700421940928, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '4592470', 'n_tokens_mistral': 677, 'n_tokens_neox': 670, 'n_words': 150}