#include <iostream>
#include <z/util/dictionary.hpp>
int main(int argc, char **argv) {
std::cout << "Loading..." << std::flush;
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;
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.