63 { |
63 { |
64 for (; *str != '\0'; str++) |
64 for (; *str != '\0'; str++) |
65 if (!IsValidAsciiChar(*str, CS_ALPHANUMERAL)) *str = '?'; |
65 if (!IsValidAsciiChar(*str, CS_ALPHANUMERAL)) *str = '?'; |
66 } |
66 } |
67 |
67 |
68 void strtolower(char *str) |
68 /** |
69 { |
69 * Only allow certain keys. You can define the filter to be used. This makes |
70 for (; *str != '\0'; str++) *str = tolower(*str); |
70 * sure no invalid keys can get into an editbox, like BELL. |
71 } |
|
72 |
|
73 /** Only allow valid ascii-function codes. Filter special codes like BELL and |
|
74 * so on [we need a special filter here later] |
|
75 * @param key character to be checked |
71 * @param key character to be checked |
76 * @return true or false depending if the character is printable/valid or not */ |
72 * @param afilter the filter to use |
|
73 * @return true or false depending if the character is printable/valid or not |
|
74 */ |
77 bool IsValidAsciiChar(byte key, CharSetFilter afilter) |
75 bool IsValidAsciiChar(byte key, CharSetFilter afilter) |
78 { |
76 { |
79 // XXX This filter stops certain crashes, but may be too restrictive. |
|
80 bool firsttest = false; |
77 bool firsttest = false; |
81 |
78 |
82 switch (afilter) { |
79 switch (afilter) { |
83 case CS_ALPHANUMERAL: |
80 case CS_ALPHANUMERAL: |
84 firsttest = (key >= ' ' && key < 127); |
81 firsttest = (key >= ' ' && key < 127); |
85 break; |
82 break; |
86 |
83 |
87 case CS_NUMERAL://we are quite strict, here |
84 /* We are very strict here */ |
88 return (key >= 48 && key <= 57); |
85 case CS_NUMERAL: |
|
86 return (key >= '0' && key <= '9'); |
89 |
87 |
90 case CS_ALPHA: |
88 case CS_ALPHA: |
91 default: |
89 default: |
92 firsttest = ((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z')); |
90 firsttest = ((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z')); |
93 break; |
91 break; |
94 } |
92 } |
95 |
93 |
|
94 /* Allow some special chars too that are non-ASCII but still valid (like '^' above 'a') */ |
96 return (firsttest || (key >= 160 && |
95 return (firsttest || (key >= 160 && |
97 key != 0xAA && key != 0xAC && key != 0xAD && key != 0xAF && |
96 key != 0xAA && key != 0xAC && key != 0xAD && key != 0xAF && |
98 key != 0xB5 && key != 0xB6 && key != 0xB7 && key != 0xB9)); |
97 key != 0xB5 && key != 0xB6 && key != 0xB7 && key != 0xB9)); |
99 } |
98 } |
|
99 |
|
100 void strtolower(char *str) |
|
101 { |
|
102 for (; *str != '\0'; str++) *str = tolower(*str); |
|
103 } |