43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
|
|
#include <filesystem>
|
||
|
|
#include <fstream>
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
#include "../CodeDweller/mishmash.hpp"
|
||
|
|
|
||
|
|
std::string read_file(const std::string& filename) {
|
||
|
|
const auto size = std::filesystem::file_size(filename);
|
||
|
|
std::string results;
|
||
|
|
results.resize(size);
|
||
|
|
std::ifstream f{filename};
|
||
|
|
if (f.is_open()) {
|
||
|
|
f.read(results.data(), size);
|
||
|
|
f.close();
|
||
|
|
}
|
||
|
|
return results;
|
||
|
|
}
|
||
|
|
|
||
|
|
std::vector<std::string> split(const std::string& s, const std::string& delimiter) {
|
||
|
|
std::vector<std::string> results{};
|
||
|
|
size_t position{}, previous{};
|
||
|
|
while ((position = s.find(delimiter, previous)) != std::string::npos) {
|
||
|
|
results.push_back(s.substr(previous, (position - previous)));
|
||
|
|
previous = position + delimiter.length();
|
||
|
|
}
|
||
|
|
if (previous < delimiter.length()) {
|
||
|
|
results.push_back(s.substr(previous));
|
||
|
|
}
|
||
|
|
return results;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(int argc, char** argv) {
|
||
|
|
if (argc <= 1) {
|
||
|
|
std::cout << "usage: give a dictionary/words file as an arg\n";
|
||
|
|
std::cout << "\t./test_cpp_code <path to words file>" << std::endl;
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
const auto words = split(read_file(argv[1]), "\n");
|
||
|
|
for (const auto& word: words) {
|
||
|
|
const auto hash = codedweller::mishmash(word);
|
||
|
|
std::cout << word << "\t" << std::hex << std::setw(8) << std::setfill('0') << hash << std::endl;
|
||
|
|
}
|
||
|
|
}
|