summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/string.c b/string.c
index d02542699..bbf8627d3 100644
--- a/string.c
+++ b/string.c
@@ -65,18 +65,15 @@ void str_validate(char *str)
if (!IsValidAsciiChar(*str, CS_ALPHANUMERAL)) *str = '?';
}
-void strtolower(char *str)
-{
- for (; *str != '\0'; str++) *str = tolower(*str);
-}
-
-/** Only allow valid ascii-function codes. Filter special codes like BELL and
- * so on [we need a special filter here later]
+/**
+ * Only allow certain keys. You can define the filter to be used. This makes
+ * sure no invalid keys can get into an editbox, like BELL.
* @param key character to be checked
- * @return true or false depending if the character is printable/valid or not */
+ * @param afilter the filter to use
+ * @return true or false depending if the character is printable/valid or not
+ */
bool IsValidAsciiChar(byte key, CharSetFilter afilter)
{
- // XXX This filter stops certain crashes, but may be too restrictive.
bool firsttest = false;
switch (afilter) {
@@ -84,8 +81,9 @@ bool IsValidAsciiChar(byte key, CharSetFilter afilter)
firsttest = (key >= ' ' && key < 127);
break;
- case CS_NUMERAL://we are quite strict, here
- return (key >= 48 && key <= 57);
+ /* We are very strict here */
+ case CS_NUMERAL:
+ return (key >= '0' && key <= '9');
case CS_ALPHA:
default:
@@ -93,7 +91,13 @@ bool IsValidAsciiChar(byte key, CharSetFilter afilter)
break;
}
+ /* Allow some special chars too that are non-ASCII but still valid (like '^' above 'a') */
return (firsttest || (key >= 160 &&
key != 0xAA && key != 0xAC && key != 0xAD && key != 0xAF &&
key != 0xB5 && key != 0xB6 && key != 0xB7 && key != 0xB9));
}
+
+void strtolower(char *str)
+{
+ for (; *str != '\0'; str++) *str = tolower(*str);
+}