mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-08-01 13:48:56 +00:00
StringUtil: Add IsPrintableCharacter and use it
Add a function that safely returns whether a character is printable i.e. whether 0x20 <= c <= 0x7e is true. This is done in several places in our codebase and it's easy to run into undefined behaviour if the C version defined in <cctype> is used instead of this one, since its behaviour is undefined if the character is not representable as an unsigned char. This fixes MemoryViewWidget.
This commit is contained in:
parent
1cc7ef356b
commit
89b0ab2d22
7 changed files with 22 additions and 27 deletions
|
@ -222,3 +222,11 @@ std::string ThousandSeparate(I value, int spaces = 0)
|
|||
return stream.str();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Returns whether a character is printable, i.e. whether 0x20 <= c <= 0x7e is true.
|
||||
/// Use this instead of calling std::isprint directly to ensure
|
||||
/// the C locale is being used and to avoid possibly undefined behaviour.
|
||||
inline bool IsPrintableCharacter(char c)
|
||||
{
|
||||
return std::isprint(c, std::locale::classic());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue