Compare commits
No commits in common. "04a29581d11cb396433a6ffd80973e2048830dcd" and "22858e4b1b8e5f4140adc74d709dabc40da90413" have entirely different histories.
04a29581d1
...
22858e4b1b
3 changed files with 24 additions and 80 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -8,7 +8,7 @@
|
||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceRoot}/build/tipplektionen",
|
"program": "${workspaceRoot}/build/tipplektionen",
|
||||||
"args": ["--min-length", "2", "--max-length", "6", "-c", "ctienrsgul", "--capital"],
|
"args": ["--min-length", "2", "--max-length", "6", "-c", "ctienrsg"],
|
||||||
"cwd": "${workspaceRoot}",
|
"cwd": "${workspaceRoot}",
|
||||||
}]
|
}]
|
||||||
}
|
}
|
20
README.md
20
README.md
|
@ -28,16 +28,12 @@ Anschließend liegt im build-Verzeichnis die ausführbare Datei.
|
||||||
Die Option `-h` listet alle Möglichkeiten auf:
|
Die Option `-h` listet alle Möglichkeiten auf:
|
||||||
```
|
```
|
||||||
Erlaubte Optionen:
|
Erlaubte Optionen:
|
||||||
-h [ --help ] Ausgabe der Hilfe
|
-h [ --help ] Ausgabe der Hilfe
|
||||||
-c [ --characters ] arg Erlaubte Buchstaben
|
-c [ --characters ] arg Enthaltene Buchstaben
|
||||||
-m [ --must-have ] arg Buchstaben, die im Wort vorhanden sein *müssen*
|
--min-length arg Minimale Wortlänge
|
||||||
(nur in Verbindung mit --characters; Buchstaben
|
--max-length arg Maximale Wortlänge
|
||||||
müssen davon Subset sein.)
|
--line-length arg Maximale Zeilenlänge
|
||||||
--min-length arg Minimale Wortlänge
|
-n [ --num-lines ] arg Anzahl Zeilen
|
||||||
--max-length arg Maximale Wortlänge
|
--lowercase Ausgabe nur klein geschrieben
|
||||||
--line-length arg Maximale Zeilenlänge
|
-d [ --dictfile ] arg Pfad zur Wörterbuchdatei
|
||||||
-n [ --num-lines ] arg Anzahl Zeilen
|
|
||||||
-d [ --dictfile ] arg Pfad zur Wörterbuchdatei
|
|
||||||
-l [ --lowercase ] Ausgabe nur klein geschrieben
|
|
||||||
-s [ --starts-capital ] Wort muss mit einem Großbuchstaben beginnen
|
|
||||||
```
|
```
|
82
main.cpp
82
main.cpp
|
@ -16,66 +16,39 @@ namespace po = boost::program_options;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
icu::UnicodeString letters;
|
std::string letters;
|
||||||
icu::UnicodeString mustHaveLetters;
|
|
||||||
int wordLengthMin{1};
|
int wordLengthMin{1};
|
||||||
int wordLengthMax{1024};
|
int wordLengthMax{1024};
|
||||||
int lineLength{60};
|
int lineLength{60};
|
||||||
int numLines{4};
|
int numLines{4};
|
||||||
std::string wordsFile{"/usr/share/dict/ngerman"};
|
std::string wordsFile{"/usr/share/dict/ngerman"};
|
||||||
bool lowercase{false};
|
bool lowercase{false};
|
||||||
bool startsCapital{false};
|
|
||||||
|
|
||||||
po::options_description desc("Erlaubte Optionen");
|
po::options_description desc("Erlaubte Optionen");
|
||||||
desc.add_options()("help,h", "Ausgabe der Hilfe")(
|
desc.add_options()("help,h", "Ausgabe der Hilfe")(
|
||||||
"characters,c", po::value<icu::UnicodeString>(&letters), "Erlaubte Buchstaben")(
|
"characters,c", po::value<std::string>(&letters), "Enthaltene Buchstaben")(
|
||||||
"must-have,m", po::value<icu::UnicodeString>(&mustHaveLetters),
|
"min-length", po::value<int>(&wordLengthMin),
|
||||||
"Buchstaben, die im Wort vorhanden sein *müssen* (nur in Verbindung mit --characters; "
|
"Minimale Wortlänge")("max-length", po::value<int>(&wordLengthMax), "Maximale Wortlänge")(
|
||||||
"Buchstaben müssen davon Subset sein.)")("min-length", po::value<int>(&wordLengthMin),
|
"line-length", po::value<int>(&lineLength),
|
||||||
"Minimale Wortlänge")(
|
"Maximale Zeilenlänge")("num-lines,n", po::value<int>(&numLines), "Anzahl Zeilen")(
|
||||||
"max-length", po::value<int>(&wordLengthMax),
|
"lowercase", po::bool_switch(&lowercase), "Ausgabe nur klein geschrieben")(
|
||||||
"Maximale Wortlänge")("line-length", po::value<int>(&lineLength), "Maximale Zeilenlänge")(
|
"dictfile,d", po::value<std::string>(&wordsFile), "Pfad zur Wörterbuchdatei");
|
||||||
"num-lines,n", po::value<int>(&numLines), "Anzahl Zeilen")(
|
|
||||||
"dictfile,d", po::value<std::string>(&wordsFile), "Pfad zur Wörterbuchdatei")(
|
|
||||||
"lowercase,l", po::bool_switch(&lowercase),
|
|
||||||
"Ausgabe nur klein geschrieben")("starts-capital,s", po::bool_switch(&startsCapital),
|
|
||||||
"Wort muss mit einem Großbuchstaben beginnen");
|
|
||||||
|
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
try {
|
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
po::notify(vm);
|
||||||
po::notify(vm);
|
|
||||||
} catch (po::error &err) {
|
|
||||||
std::cerr << "Fehler beim Verarbeiten der Optionen:\n";
|
|
||||||
std::cerr << err.what() << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vm.contains("help")) {
|
if (vm.contains("help")) {
|
||||||
std::cout << desc << std::endl;
|
std::cout << desc << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mustHaveLetters.length() > 0) {
|
|
||||||
for (int i{0}; i < mustHaveLetters.length(); i++) {
|
|
||||||
auto ch = mustHaveLetters.charAt(i);
|
|
||||||
if (letters.indexOf(ch) == -1) {
|
|
||||||
std::cout
|
|
||||||
<< "Die Buchstaben von --must-have müssen ein Subset von --characters sein."
|
|
||||||
<< std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream infile(wordsFile);
|
std::ifstream infile(wordsFile);
|
||||||
std::string line;
|
std::string line;
|
||||||
icu::UnicodeString uline;
|
icu::UnicodeString uline;
|
||||||
std::vector<icu::UnicodeString> words;
|
std::vector<icu::UnicodeString> words;
|
||||||
icu::UnicodeString lettersUpper = letters;
|
icu::UnicodeString ucLetters = icu::UnicodeString::fromUTF8(letters);
|
||||||
lettersUpper.toUpper();
|
icu::UnicodeString ucLettersUpper = icu::UnicodeString::fromUTF8(letters).toUpper();
|
||||||
icu::UnicodeString mustHaveLettersUpper = mustHaveLetters;
|
|
||||||
mustHaveLettersUpper.toUpper();
|
|
||||||
long counter{0};
|
long counter{0};
|
||||||
|
|
||||||
if (!std::filesystem::exists(wordsFile)) {
|
if (!std::filesystem::exists(wordsFile)) {
|
||||||
|
@ -90,30 +63,11 @@ int main(int argc, char *argv[])
|
||||||
if (length < wordLengthMin || length > wordLengthMax)
|
if (length < wordLengthMin || length > wordLengthMax)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (mustHaveLetters.length() > 0) {
|
if (ucLetters.length() > 0) {
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
for (int i{0}; i < mustHaveLetters.length(); i++) {
|
for (int i{0}; i < uline.length(); i++) {
|
||||||
auto ch = mustHaveLetters.charAt(i);
|
|
||||||
auto chU = mustHaveLettersUpper.charAt(i);
|
|
||||||
if (uline.indexOf(ch) == -1 && uline.indexOf(chU) == -1) {
|
|
||||||
valid = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!valid)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (letters.length() > 0) {
|
|
||||||
bool valid = true;
|
|
||||||
for (int i{0}; i < length; i++) {
|
|
||||||
auto ch = uline.charAt(i);
|
auto ch = uline.charAt(i);
|
||||||
if (startsCapital && i == 0) {
|
if (ucLetters.indexOf(ch) == -1 && ucLettersUpper.indexOf(ch) == -1) {
|
||||||
if (lettersUpper.indexOf(ch) == -1) {
|
|
||||||
valid = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (letters.indexOf(ch) == -1 && lettersUpper.indexOf(ch) == -1) {
|
|
||||||
valid = false;
|
valid = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -129,17 +83,11 @@ int main(int argc, char *argv[])
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter == 0) {
|
|
||||||
std::cout << "Keine Wörter mit den angegebenen Kriterien gefunden." << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "Anzahl infrage kommender Wörter: " << counter << "\n" << std::endl;
|
std::cout << "Anzahl infrage kommender Wörter: " << counter << "\n" << std::endl;
|
||||||
|
|
||||||
std::random_device rdev;
|
std::random_device rdev;
|
||||||
std::mt19937 rng(rdev());
|
std::mt19937 rng(rdev());
|
||||||
std::uniform_int_distribution<std::mt19937::result_type> distrib(0, words.size() - 1);
|
std::uniform_int_distribution<std::mt19937::result_type> distrib(0, words.size() - 1);
|
||||||
|
|
||||||
for (int i{0}; i < numLines; i++) {
|
for (int i{0}; i < numLines; i++) {
|
||||||
icu::UnicodeString lectionLine;
|
icu::UnicodeString lectionLine;
|
||||||
while (lectionLine.length() < lineLength) {
|
while (lectionLine.length() < lineLength) {
|
||||||
|
|
Loading…
Reference in a new issue