<commit_before># provides routing functionality and handles resources

url  = require 'url'
st   = require './status_codes'
mkPath = (require '../helpers/path').createPath
{ mparse, render } = require './repr'

literal = {}
templated = []  # order matters here
resource = (paths, description, responses_obj) ->
    for path in paths.split ' '
        path = mkPath path
        if (path.indexOf '{') == -1  # it is a literal URL
            literal[path] = { description, responses_obj }
        else
            [ regex, paramsExtractor ] = parseTemplated path
            templated.push { description, responses_obj, regex, paramsExtractor }

templateParamsRegex = /\{([^\/\.]+)(\.\.\.)?\}/g
parseTemplated = (path) ->
    tokens = []
    regex = path.replace templateParamsRegex, (_, token, greedy) ->
        tokens.push token
        if greedy then '(.*)' else '([^/]+)'
    regex = new RegExp '^' + regex + '$'

    paramsExtractor = (path) ->
        values = (path.match regex).slice 1
        params = {}
        for t, i in tokens
            params[t] = values[i]
        params

    [ regex, paramsExtractor ]

findTemplated = (path) ->
    for t in templated
        if t.regex.test path then return [ t, t.paramsExtractor path ]
    return []

<commit_msg>fix: ignore more whitespace in resource URLs<commit_after># provides routing functionality and handles resources

url  = require 'url'
st   = require './status_codes'
mkPath = (require '../helpers/path').createPath
{ mparse, render } = require './repr'

literal = {}
templated = []  # order matters here
resource = (paths, description, responses_obj) ->
    for path in paths.split /\s+/
        path = mkPath path
        if (path.indexOf '{') == -1  # it is a literal URL
            literal[path] = { description, responses_obj }
        else
            [ regex, paramsExtractor ] = parseTemplated path
            templated.push { description, responses_obj, regex, paramsExtractor }

templateParamsRegex = /\{([^\/\.]+)(\.\.\.)?\}/g
parseTemplated = (path) ->
    tokens = []
    regex = path.replace templateParamsRegex, (_, token, greedy) ->
        tokens.push token
        if greedy then '(.*)' else '([^/]+)'
    regex = new RegExp '^' + regex + '$'

    paramsExtractor = (path) ->
        values = (path.match regex).slice 1
        params = {}
        for t, i in tokens
            params[t] = values[i]
        params

    [ regex, paramsExtractor ]

findTemplated = (path) ->
    for t in templated
        if t.regex.test path then return [ t, t.paramsExtractor path ]
    return []


{'fraction_non_alphanumeric': 0.13874854255732608, 'fraction_numerical': 0.001554605518849592, 'mean_word_length': 2.3735255570117957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3173152', 'n_tokens_mistral': 769, 'n_tokens_neox': 756, 'n_words': 225}