From 248b0ccc87b7fcb4a260790d38f3e59a971abf31 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 14 Oct 2021 16:19:40 -0400 Subject: Acronym processing --- source/app.d | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source') 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) { -- cgit