<commit_before>use collections::hashmap::HashMap;
use collections::enum_set::{EnumSet};
use pcre::{CompileOption, StudyOption, ExtraOption, Pcre, Match};
use http::headers::content_type::MediaType;
use std::io::File;
use request;
use pcre;
use http::status;
use sync::{RWArc, Arc};
use route::Router;
use request::Request;
use http::server::ResponseWriter;


pub struct RegexRouter<'a> {
    routes: RWArc<~[RegexRoute]>,
    reverse_routes: Arc<HashMap<~str, ~str>>,
    compiled_routes: RWArc<Pcre>,
}

impl<'a> Router for RegexRouter<'a> {
    fn route(&self, request: &mut request::Request, response: &mut ResponseWriter) {
        // use the massive regex to route
        let uri = request.uri.clone();
        let regex_result = self.compiled_routes.write(|re: &mut Pcre| {re.exec(uri)});
        // Shortened the code by request. If this is not as easy to understand, you can
        // look at the more verbose version that used to be here in git history
        // Convert the get the mark on the match and change it to an uint 
        // then find the route at that uint and call the fptr for it
        regex_result.and_then::<Option<uint>>(|rr: Match| {
            rr.mark.and_then(|m: ~str| {from_str::<uint>(m)}).and_then(|i: uint| {
                self.routes.read(|x: &~[RegexRoute]| { 
                    match x[i] {
                        Simple(s) => {(s.fptr)(request, response);},
                        Regex(s) => {(s.fptr)(request, response);},
                        Static(_) => {debug!("TODO: impl StaticServe");},
                    };
                    None
                })
            })
        });
    }
<commit_msg>Clarified a few comments that were poorly written<commit_after>use collections::hashmap::HashMap;
use collections::enum_set::{EnumSet};
use pcre::{CompileOption, StudyOption, ExtraOption, Pcre, Match};
use http::headers::content_type::MediaType;
use std::io::File;
use request;
use pcre;
use http::status;
use sync::{RWArc, Arc};
use route::Router;
use request::Request;
use http::server::ResponseWriter;


pub struct RegexRouter<'a> {
    routes: RWArc<~[RegexRoute]>,
    reverse_routes: Arc<HashMap<~str, ~str>>,
    compiled_routes: RWArc<Pcre>,
}

impl<'a> Router for RegexRouter<'a> {
    fn route(&self, request: &mut request::Request, response: &mut ResponseWriter) {
        // use the massive compiled regex to route
        let uri = request.uri.clone();
        let regex_result = self.compiled_routes.write(|re: &mut Pcre| {re.exec(uri)});
        // Get the mark on the match object and change it to an uint 
        // then find the route at that uint and call the fptr for it
        regex_result.and_then::<Option<uint>>(|rr: Match| {
            rr.mark.and_then(|m: ~str| {from_str::<uint>(m)}).and_then(|i: uint| {
                self.routes.read(|x: &~[RegexRoute]| { 
                    match x[i] {
                        Simple(s) => {(s.fptr)(request, response);},
                        Regex(s) => {(s.fptr)(request, response);},
                        Static(_) => {debug!("TODO: impl StaticServe");},
                    };
                    None
                })
            })
        });
    }

{'fraction_non_alphanumeric': 0.14509068167604752, 'fraction_numerical': 0.0, 'mean_word_length': 2.5309050772626933, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, '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': '1326465', 'n_tokens_mistral': 979, 'n_tokens_neox': 969, 'n_words': 264}