<commit_before>#include <Counter.h>
#include <Exception.h>
#include <Directory.h>
#include <fstream>
#include <iostream>

namespace Counter
{

void Counter::Init(const std::wstring &Regex, const std::wstring &Dir)
{
    regex = std::wregex(Regex);
    dir = Dir;
}

void Counter::Process()
{
    linesCnt = 0;
    ProcessDir(dir);
}

void Counter::ProcessFile(const std::wstring &Path)
{
    std::wcout << L"processing " << Path << "... ";

    int32_t linesInFile = 0;

    std::ifstream file(Path);

    std::string line;
    while (std::getline(file, line))
        linesInFile++;

    std::wcout << linesInFile << " lines" << std::endl;

    linesCnt += linesInFile;
}

void Counter::ProcessDir(const std::wstring &Path)
{
    std::vector<std::wstring> files, dirs;

    Directory::Parse(Path, files, dirs);

    for(const std::wstring &file : files)
        if(std::regex_match(file, regex))
            ProcessFile(Path + L"/" + file);

    for(const std::wstring &dir : dirs)
        ProcessDir(Path + L"/" + dir);
}

}<commit_msg>see [0beb024]<commit_after>#include <Counter.h>
#include <Exception.h>
#include <Directory.h>
#include <fstream>
#include <iostream>

namespace Counter
{

void Counter::Init(const std::wstring &Regex, const std::wstring &Dir)
{
    regex = std::wregex(Regex);
    dir = Dir;
}

void Counter::Process()
{
    linesCnt = 0;
    ProcessDir(dir);
}

void Counter::ProcessFile(const std::wstring &Path)
{
    std::wcout << L"processing " << Path << L"... ";

    int32_t linesInFile = 0;

    std::ifstream file(Path);

    std::string line;
    while (std::getline(file, line))
        linesInFile++;

    std::wcout << linesInFile << L" lines." << std::endl;

    linesCnt += linesInFile;
}

void Counter::ProcessDir(const std::wstring &Path)
{
    std::vector<std::wstring> files, dirs;

    Directory::Parse(Path, files, dirs);

    for(const std::wstring &file : files)
        if(std::regex_match(file, regex))
            ProcessFile(Path + L"/" + file);

    for(const std::wstring &dir : dirs)
        ProcessDir(Path + L"/" + dir);
}

}
{'fraction_non_alphanumeric': 0.1697931697931698, 'fraction_numerical': 0.005772005772005772, 'mean_word_length': 3.5714285714285716, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 15, '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': '161399', 'n_tokens_mistral': 756, 'n_tokens_neox': 716, 'n_words': 159}