diff --git a/src/util/CharUtil.hxx b/src/util/CharUtil.hxx index 44c3ad1f8..7d573907d 100644 --- a/src/util/CharUtil.hxx +++ b/src/util/CharUtil.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2017 Max Kellermann + * Copyright 2011-2020 Max Kellermann * * 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 { diff --git a/src/util/WCharUtil.hxx b/src/util/WCharUtil.hxx index fed907eb7..6220f2449 100644 --- a/src/util/WCharUtil.hxx +++ b/src/util/WCharUtil.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2011-2019 Max Kellermann + * Copyright 2011-2020 Max Kellermann * * 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 {