<commit_before>#ifndef VALIDATEDINPUT_H_INCLUDED
#define VALIDATEDINPUT_H_INCLUDED

#include <string>
#include <windows.h>
#include <iostream>

// does not deal with INT overflows
inline unsigned int get_limited_input(const unsigned int upper_limit, const unsigned int lower_limit = 1, const std::string& input_message = "", const std::string& error_message = "") {
    unsigned int ret;

    std::string temp;

    while (!(ret >= lower_limit and ret <= upper_limit)) {
        if (input_message != "") {
            std::cout << input_message;
        }

        ret = 0;

        getline(std::cin, temp);

        for (unsigned int i = 0; i < temp.size(); i++) {
            if (isdigit(temp.c_str()[i]))
                ret = ret * 10 + (static_cast<unsigned int>(temp.c_str()[i]) - 48);
            else
                break;
        }

        if (!(ret >= lower_limit and ret <= upper_limit) and error_message != "") {
            std::cout << error_message << std::endl;
        }
    }
    return ret;
}

inline void error_exit(const std::string& error_message, const HANDLE hStdin = 0, const DWORD fdwSaveOldMode = 0, const bool exitProgram = false, const int exitCode = 0) {
    std::cerr << error_message << std::endl;

    // Restore input mode on exit.
    /* Windows Specific Function */
    if (hStdin and fdwSaveOldMode)
        SetConsoleMode(hStdin, fdwSaveOldMode);

    // Only terminate the program if desired
    if (exitProgram) {
        std::cerr << "Process will now terminate\n";
        ExitProcess(exitCode);
    }
}

// does not deal with INT overflows; though if you have this many options you might want to reconsider what you're doing...
inline unsigned int get_list_input(const unsigned int number_options, const std::string& input_message = "  ") {
    HANDLE hStdin;
    DWORD fdwSaveOldMode, fdwMode;

    /* Windows Specific functions */
    // Get the standard input handle.
    hStdin = GetStdHandle(STD_INPUT_HANDLE);
    if (hStdin == INVALID_HANDLE_VALUE)
        error_exit("GetStdHandle", hStdin, fdwSaveOldMode);

    // Save the current input mode, to be restored on exit.
    if (! GetConsoleMode(hStdin, &fdwSaveOldMode) )<commit_msg>removes unused brackets, better spacing<commit_after>#ifndef VALIDATEDINPUT_H_INCLUDED
#define VALIDATEDINPUT_H_INCLUDED

#include <string>
#include <windows.h>
#include <iostream>

// does not deal with INT overflows
inline unsigned int get_limited_input(const unsigned int upper_limit, const unsigned int lower_limit = 1, const std::string& input_message = "", const std::string& error_message = "") {
    unsigned int ret;

    std::string temp;

    while (!(ret >= lower_limit and ret <= upper_limit)) {
        if (input_message != "")
            std::cout << input_message;

        ret = 0;

        getline(std::cin, temp);

        for (unsigned int i = 0; i < temp.size(); i++)
            if (isdigit(temp.c_str()[i]))
                ret = ret * 10 + (static_cast<unsigned int>(temp.c_str()[i]) - 48);
            else
                break;

        if (!(ret >= lower_limit and ret <= upper_limit) and error_message != "")
            std::cout << error_message << std::endl;
    }

    return ret;
}

inline void error_exit(const std::string& error_message, const HANDLE hStdin = 0, const DWORD fdwSaveOldMode = 0, const bool exitProgram = false, const int exitCode = 0) {
    std::cerr << error_message << std::endl;

    // Restore input mode on exit.
    /* Windows Specific Function */
    if (hStdin and fdwSaveOldMode)
        SetConsoleMode(hStdin, fdwSaveOldMode);

    // Only terminate the program if desired
    if (exitProgram) {
        std::cerr << "Process will now terminate\n";
        ExitProcess(exitCode);
    }
}

// does not deal with INT overflows; though if you have this many options you might want to reconsider what you're doing...
inline unsigned int get_list_input(const unsigned int number_options, const std::string& input_message = "  ") {
    HANDLE hStdin;
    DWORD fdwSaveOldMode, fdwMode;

    /* Windows Specific functions */
    // Get the standard input handle.
    hStdin = GetStdHandle(STD_INPUT_HANDLE);
    if (hStdin == INVALID_HANDLE_VALUE)
        error_exit("GetStdHandle", hStdin, fdwSaveOldMode);

    // Save the current input mode, to be restored on exit.
    if (! GetConsoleMode(hStdin, &fdwSaveOldMode) )
{'fraction_non_alphanumeric': 0.11075441412520064, 'fraction_numerical': 0.004586104104563174, 'mean_word_length': 2.9726775956284155, 'pattern_counts': {'":': 0, '<': 41, '<?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': '4577420', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1280, 'n_words': 406}