libzed 1.9.9
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
dictionary.cpp
#include <iostream>
#include <z/util/dictionary.hpp>
int main(int argc, char **argv) {
std::cout << "Loading..." << std::flush;
// Load the dictionary, pausing every 1 second to do other processes
while (dict.read("/usr/share/dict/words", 1'000'000)) {
std::cout << '.' << std::flush;
}
std::cout << " Loaded " << dict.length() << " words." << std::endl;
std::cout << "Filtering out words that begin with A... " << std::flush;
dict = dict.filter([](auto item) { return z::core::toLower(item[0]) != 'a'; });
std::cout << "we now only have " << dict.length() << " words." << std::endl;
for (int i = 1; i < argc; i++) {
('"'_zs + argv[i] + "\" is " + (dict.isWord(argv[i]) ? "" : "NOT ") + "a word.").writeln(std::cout);
}
}
int length() const noexcept override
Get the length of the array.
Definition array.hpp:1011
A class for performing searches on a dictionary of words.
Definition dictionary.hpp:15
bool isWord(const zstring &word) const noexcept
Check if the given string is a valid word in the dictionary (case is ignored).
dictionary filter(std::function< bool(const zstring &)> lambda) const
Filters the dictionary based on a predicate and returns a new dictionary containing the words that sa...
bool read(const zstring &filename, const core::timeout &time=-1, bool assumePresorted=false)
Read this dictionary's word list as text from a file.
uint32_t toLower(uint32_t ch, bool alternate=false) noexcept
Convert the given character to lowercase.