forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
char_validity_check.cpp
42 lines (39 loc) · 1.31 KB
/
char_validity_check.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "char_validity_check.h"
#include <cctype>
/**
* Returns whether or not the given (ASCII) character is usable.
* Called to check player name validity and world name validity.
* Only printable symbols not reserved by the filesystem are
* permitted.
* @param ch The char to check.
* @return true if the char is allowed in a name, false if not.
*/
bool is_char_allowed( int ch )
{
#if defined(_MSC_VER)
// This hardcoded check and rejection of \t is in here because
// std::isprint on Windows with MSVC has a bug where it considers
// it a printable character.
//
// A Microsoft representative has this to say:
// "Tab being reported as a print character by isprint() is a regression
// in the Universal C Runtime that started appearing with the update
// KB4338819. It will be fixed in a future servicing update, as
// well as will be fixed in the next major version of Windows."
//
// That was from July 27, 2018. As of April 8, 2020 this is still
// not functional.
if( ch == 9 ) {
return false;
}
#endif
if( !std::isprint( ch ) && ch <= 127 ) {
// above 127 are non-ASCII, therefore Unicode, therefore OK
return false;
}
if( ch == '\\' || ch == '/' ) {
// not valid in file names
return false;
}
return true;
}