aboutsummaryrefslogtreecommitdiff
path: root/lib/jdtalk/core.d
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2021-04-01 13:29:39 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2021-04-01 13:29:39 -0400
commit6bee64ac64f28833f06efcebe832838d59ca3423 (patch)
treecead7e3a8e95c605988f68ff7ababb09e8dac306 /lib/jdtalk/core.d
parenta4665aa3c580b7bb078dc537bf414419b9d65b73 (diff)
downloadjdtalk-6bee64ac64f28833f06efcebe832838d59ca3423.tar.gz
Add talkf formatter function
Diffstat (limited to 'lib/jdtalk/core.d')
-rw-r--r--lib/jdtalk/core.d25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/jdtalk/core.d b/lib/jdtalk/core.d
index c0fc376..aafe64a 100644
--- a/lib/jdtalk/core.d
+++ b/lib/jdtalk/core.d
@@ -186,3 +186,28 @@ string talkSalad(ref dict_t dict, int words) {
}
return salad.join(" ");
}
+
+string talkf(ref dict_t dict, string fmt) {
+ string[] output;
+ for (int i = 0; i < fmt.length; i++) {
+ if (fmt[i] == '%' && (i + 1) < fmt.length) {
+ switch (fmt[i + 1]) {
+ case 'a':
+ output ~= word(dict.adjective);
+ break;
+ case 'n':
+ output ~= word(dict.noun);
+ break;
+ case 'd':
+ output ~= word(dict.adverb);
+ break;
+ case 'v':
+ output ~= word(dict.verb);
+ break;
+ default:
+ continue;
+ }
+ }
+ }
+ return output.join(" ");
+}