MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / IsValidChar

Function IsValidChar

src/string.cpp:373–384  ·  view source on GitHub ↗

* 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 * @param afilter the filter to use * @return true or false depending if the character is printable/valid or not */

Source from the content-addressed store, hash-verified

371 * @return true or false depending if the character is printable/valid or not
372 */
373bool IsValidChar(char32_t key, CharSetFilter afilter)
374{
375 switch (afilter) {
376 case CS_ALPHANUMERAL: return IsPrintable(key);
377 case CS_NUMERAL: return (key >= '0' && key <= '9');
378 case CS_NUMERAL_SPACE: return (key >= '0' && key <= '9') || key == ' ';
379 case CS_NUMERAL_SIGNED: return (key >= '0' && key <= '9') || key == '-';
380 case CS_ALPHA: return IsPrintable(key) && !(key >= '0' && key <= '9');
381 case CS_HEXADECIMAL: return (key >= '0' && key <= '9') || (key >= 'a' && key <= 'f') || (key >= 'A' && key <= 'F');
382 default: NOT_REACHED();
383 }
384}
385
386/**
387 * Test if a unicode character is considered garbage to be skipped.

Callers 6

UpdateOskStateMethod · 0.85
OnClickMethod · 0.85
TranslateTTDPatchCodesFunction · 0.85
InsertStringMethod · 0.85
HandleKeyPressMethod · 0.85
PollEventMethod · 0.85

Calls 2

IsPrintableFunction · 0.85
NOT_REACHEDFunction · 0.85

Tested by

no test coverage detected