<commit_before>/**
    Multithreading workaround code

    @author <NAME>
*/
#include <string>
#include <iostream>
#include <thread>
#include <vector>
#include <mutex>
#include <ctime>
#include <limits.h>
#include <unistd.h>
#include <cstring>

using namespace std;
/// To prevent multiple threads from using stdout at the same time, lock this mutex, then print, then unlock it to let another thread use it.
mutex printing;

/**
 ## Call the given command in bash

 ### Arguments
 * `std::string command` - Command to run. Note that non-interpreters wrappers like nice may not work with aliased commands.
 
 * `int nice` - nice value to run command at (added to avoid issues with nice not working with aliases). Defualts to zero.

  ### Returns the return value of the given function
*/
int bash(std::string command,int nice=0){
    string shell = "\
    #!/bin/bash \n\
    source ~/.bashrc\n\
    renice -n "+to_string(nice)+" -p $$\n\
    ";
    int i,ret = system((shell+command).c_str());
    i=WEXITSTATUS(ret); // Get return value.
    return i;
}

/**
## Replace all instances of a string in another string with a third string. Credit to <NAME> on stack overflow for supplying the code in response to a question asked by NullVoxPopuli.
*/
std::string ReplaceString(std::string subject, const std::string& search, const std::string& replace) {
    size_t pos = 0;
    while ((pos = subject.find(search, pos)) != std::string::npos) {
         subject.replace(pos, search.length(), replace);
         pos += replace.length();
    }
    return subject;
}


/**
## Apply regex transformations to input string.

### Arguments:
* `string& input` - Input string reference to modify in place.
<commit_msg>Update documentation<commit_after>/**
    Multithreading workaround code

    @author <NAME>
*/
#include <string>
#include <iostream>
#include <thread>
#include <vector>
#include <mutex>
#include <ctime>
#include <limits.h>
#include <unistd.h>
#include <cstring>

using namespace std;
/// To prevent multiple threads from using stdout at the same time, lock this mutex, then print, then unlock it to let another thread use it.
mutex printing;

/**
 ## Call the given command in bash

 ### Arguments
 * `std::string command` - Command to run. Note that non-interpreters wrappers like nice may not work with aliased commands.

 * `int nice` - nice value to run command at (added to avoid issues with nice not working with aliases). Defualts to zero.

  ### Returns the return value of the given function
*/
int bash(std::string command,int nice=0){
    string shell = "\
    #!/bin/bash \n\
    source ~/.bashrc\n\
    renice -n "+to_string(nice)+" -p $$\n\
    ";
    int i,ret = system((shell+command).c_str());
    i=WEXITSTATUS(ret); // Get return value.
    return i;
}

/**
 ## Replace all instances of a string in another string with a third string. Credit to <NAME> on stack overflow for supplying the code in response to a question asked by NullVoxPopuli.

 ### Arguments:
 * `std::string subject` - String to do replacements in.

 * `const std::string& search` - Substring to replace with the `replace` string.

 * `const std::string& replace` - Substring to replace the `search` string with.
*/
std::string ReplaceString(std::string subject, const std::string& search, const std::string& replace) {
    size_t pos = 0;
    while ((pos = subject.find(search, pos)) != std::string::npos) {
         subject.replace(pos, search.length(), replace);
         pos += replace.length();
    }
    return subject;
}


/**
## Apply regex transformations to input string.

### Arguments:
* `string& input` - Input string reference to modify in place.

{'fraction_non_alphanumeric': 0.12455516014234876, 'fraction_numerical': 0.0010949904188338351, 'mean_word_length': 3.602015113350126, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '2579471', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1062, 'n_words': 433}