mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-29 09:29:10 +00:00
(svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
allow certain patterns (like numbers only)
This commit is contained in:
30
string.c
30
string.c
@@ -62,10 +62,38 @@ char* CDECL str_fmt(const char* str, ...)
|
||||
void str_validate(char *str)
|
||||
{
|
||||
for (; *str != '\0'; str++)
|
||||
if (!IsValidAsciiChar(*str)) *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]
|
||||
* @param key character to be checked
|
||||
* @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) {
|
||||
case CS_ALPHANUMERAL:
|
||||
firsttest = (key >= ' ' && key < 127);
|
||||
break;
|
||||
|
||||
case CS_NUMERAL://we are quite strict, here
|
||||
return (key >= 48 && key <= 57);
|
||||
|
||||
case CS_ALPHA:
|
||||
default:
|
||||
firsttest = ((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z'));
|
||||
break;
|
||||
}
|
||||
|
||||
return (firsttest || (key >= 160 &&
|
||||
key != 0xAA && key != 0xAC && key != 0xAD && key != 0xAF &&
|
||||
key != 0xB5 && key != 0xB6 && key != 0xB7 && key != 0xB9));
|
||||
}
|
||||
|
Reference in New Issue
Block a user