<commit_before># search.py
# format a search spec as S-expression

import re

# repr(str) would just nearly do, but it tends to
# chose whether to use single or double quote. Meh.

quotetable = { '\\\\': '\\\\', # Careful!
               '"' :  '\\"',
               '\n': '\\n',
               '\t': '\\t',
               # add others as necessary
}


quotepatt = re.compile('[' + ''.join(quotetable.keys()) + ']')


def quotestring(str):
    "Returns escaped and double-quoted string"
    return '"' + re.sub(quotepatt, lambda(x): quotetable[x.group()], str) + '"'


def render(x):<commit_msg>re #8308: avoid re by using string replace<commit_after># search.py
# format a search spec as S-expression

quotetable = (('"',  '\\"'),
              ('\n', '\\n'),
              ('\t', '\\t'),
              # add others as necessary
              )


def quotestring(str):
    "Returns escaped and double-quoted string"
    for orig, target in quotetable:
        str = str.replace(orig, target)
    return '"' + str + '"'


def render(x):
{'fraction_non_alphanumeric': 0.17664092664092665, 'fraction_numerical': 0.003861003861003861, 'mean_word_length': 2.1712538226299696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3685536', 'n_tokens_mistral': 345, 'n_tokens_neox': 328, 'n_words': 97}