summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/prompt.cc
diff options
context:
space:
mode:
authorNicholas Feinberg <pleasingfung@gmail.com>2014-07-28 23:04:00 -0700
committerNicholas Feinberg <pleasingfung@gmail.com>2014-07-28 23:04:00 -0700
commitc7140f0f8afd4b6418f178b2099b4cd9c674e2c5 (patch)
treef1b2e90fd880f5b1afd7b49a6623a00a60f0605f /crawl-ref/source/prompt.cc
parent583dd66ff5df83761feed2582c87112a0ca7db01 (diff)
downloadcrawl-ref-c7140f0f8afd4b6418f178b2099b4cd9c674e2c5.tar.gz
crawl-ref-c7140f0f8afd4b6418f178b2099b4cd9c674e2c5.zip
Move letter <-> index from stuff.cc to prompt.cc (wheals)
Diffstat (limited to 'crawl-ref/source/prompt.cc')
-rw-r--r--crawl-ref/source/prompt.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/crawl-ref/source/prompt.cc b/crawl-ref/source/prompt.cc
index 8cd444eeaf..23c6e990a8 100644
--- a/crawl-ref/source/prompt.cc
+++ b/crawl-ref/source/prompt.cc
@@ -13,6 +13,7 @@
#include "message.h"
#include "options.h"
#include "state.h"
+#include "viewchar.h"
// Like yesno, but requires a full typed answer.
// Unlike yesno, prompt should have no trailing space.
@@ -310,3 +311,21 @@ double prompt_for_float(const char* prompt)
return ret;
}
+
+
+char index_to_letter(int the_index)
+{
+ ASSERT_RANGE(the_index, 0, ENDOFPACK);
+ return the_index + ((the_index < 26) ? 'a' : ('A' - 26));
+}
+
+int letter_to_index(int the_letter)
+{
+ if (the_letter >= 'a' && the_letter <= 'z')
+ return the_letter - 'a'; // returns range [0-25] {dlb}
+ else if (the_letter >= 'A' && the_letter <= 'Z')
+ return the_letter - 'A' + 26; // returns range [26-51] {dlb}
+
+ die("slot not a letter: %s (%d)", the_letter ?
+ stringize_glyph(the_letter).c_str() : "null", the_letter);
+}