1
0
Fork 0
forked from hashirama/Hakurei

add debug feature

This commit is contained in:
千住柱間 2024-05-10 22:11:35 -04:00
parent 6fab84f077
commit 8b791f04bc
Signed by: hashirama
GPG key ID: 53E62470A86BC185

View file

@ -11,13 +11,21 @@ struct Entry {
};
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <search_string>" << std::endl;
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <search_string> [--debug]" << std::endl;
return 1;
}
const char* filename = "dict.bin";
std::string search_string = argv[1];
bool debug_mode = false; // Debug mode flag
// Check if --debug is passed
if (argc == 3 && std::string(argv[2]) == "--debug") {
debug_mode = true;
}
std::string raw_output; // To store raw output
// The trie dictionary type from the four types
using trie_type = xcdat::trie_15_type;
@ -54,11 +62,17 @@ int main(int argc, char* argv[]) {
substrings.push_back(substring);
}
std::cout << search_string << " - " << smallest_prefix << " = ";
if (debug_mode) {
raw_output += search_string + " - " + smallest_prefix.data() + " = "; // Accumulate raw output
}
size_t pos = search_string.find(smallest_prefix);
if (pos != std::string::npos) {
search_string.erase(0, pos + smallest_prefix.length());
}
std::cout << search_string << std::endl;
if (debug_mode) {
raw_output += search_string + '\n'; // Add the result to raw output
}
// Remove leading whitespace, if any
while (!search_string.empty() && std::isspace(search_string.front())) {
search_string.erase(0, 1);
@ -69,6 +83,10 @@ int main(int argc, char* argv[]) {
}
}
// Print the stored raw output if debug mode is active
if (debug_mode) {
std::cout << "Stored raw output:" << std::endl << raw_output << std::endl;
}
for (const auto& sub : substrings) {
std::cout << sub << std::endl;