aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2021-10-14 16:19:40 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2021-10-14 16:19:40 -0400
commit248b0ccc87b7fcb4a260790d38f3e59a971abf31 (patch)
tree90e180acdb379484586e0ee25f12414ad74e7457 /source
parent6bee64ac64f28833f06efcebe832838d59ca3423 (diff)
downloadjdtalk-248b0ccc87b7fcb4a260790d38f3e59a971abf31.tar.gz
Acronym processing
Diffstat (limited to 'source')
-rw-r--r--source/app.d27
1 files changed, 27 insertions, 0 deletions
diff --git a/source/app.d b/source/app.d
index e816d8b..08cd3f4 100644
--- a/source/app.d
+++ b/source/app.d
@@ -24,6 +24,7 @@ int main(string[] args)
bool rCase = false;
bool hCase = false;
bool haxor = false;
+ string acronym;
string custom_format = null;
string pattern = null;
string dataRoot = absolutePath(getcwd());
@@ -35,6 +36,7 @@ int main(string[] args)
auto opt = getopt(
args,
"format|f", "Produce words with formatted string", &custom_format,
+ "acronym|a", "Expand characters to acronym", &acronym,
"limit|c", format("(default: %d)", limit), &limit,
"pattern|p", "Limit output to a root word", &pattern,
"exact|e", format("Exact matches only (default: %s)", exactMatch ? "true" : "false"), &exactMatch,
@@ -62,12 +64,23 @@ int main(string[] args)
return 1;
}
+ if (acronym) {
+ char result = 0;
+ if ((result = acronymSafe(dict, acronym)) > 0) {
+ stderr.writefln("No words start with: '%c'", result);
+ return 1;
+ }
+ }
+
while(true) {
string output;
if (salad) {
output = talkSalad(dict, salad);
}
+ else if (acronym) {
+ output = talkAcronym(dict, acronym);
+ }
else if (custom_format) {
output = talkf(dict, custom_format);
}
@@ -94,6 +107,20 @@ int main(string[] args)
output = leetSpeak(output);
}
+ if (output == null) {
+ writeln("An error has occurred.");
+ return 1;
+ }
+
+ if (acronym) {
+ // Capitalize each word in the acronym
+ string[] parts;
+ foreach (word; output.split(" ")) {
+ parts ~= word.capitalize;
+ }
+ output = parts.join(" ");
+ }
+
writeln(output);
if (limit > 0) {