util/CharUtil: add IsNonPrintableASCII()

Prepare to fix cc72ceb368
This commit is contained in:
Max Kellermann 2020-04-27 13:57:05 +02:00
parent 6423670eae
commit 814b2a218d
2 changed files with 37 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2011-2017 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2011-2020 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -70,12 +70,29 @@ IsWhitespaceFast(const char ch) noexcept
return IsWhitespaceOrNull(ch);
}
/**
* Is this a non-printable ASCII character? Returns false for
* non-ASCII characters.
*
* Note that this is not the opposide of IsNonPrintableASCII().
*/
constexpr bool
IsPrintableASCII(char ch) noexcept
{
return (signed char)ch >= 0x20;
}
/**
* Is this a non-printable character? Returns false for non-ASCII characters.
*
* Note that this is not the opposide of IsPrintableASCII()
*/
constexpr bool
IsNonPrintableASCII(char ch) noexcept
{
return (unsigned char)ch < 0x20;
}
constexpr bool
IsDigitASCII(char ch) noexcept
{

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011-2019 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2011-2020 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -62,12 +62,30 @@ IsWhitespaceFast(const wchar_t ch) noexcept
return IsWhitespaceOrNull(ch);
}
/**
* Is this a non-printable ASCII character? Returns false for
* non-ASCII characters.
*
* Note that this is not the opposide of IsNonPrintableASCII().
*/
constexpr bool
IsPrintableASCII(wchar_t ch) noexcept
{
return IsASCII(ch) && ch >= 0x20;
}
/**
* Is this a non-printable character? Returns false for non-ASCII
* characters.
*
* Note that this is not the opposide of IsPrintableASCII()
*/
constexpr bool
IsNonPrintableASCII(wchar_t ch) noexcept
{
return (unsigned)ch < 0x20;
}
constexpr bool
IsDigitASCII(wchar_t ch) noexcept
{