based

Opinionated utility library
git clone git://git.dimitrijedobrota.com/based.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit d3258aa292b673d04de2314914c374cf04069537
parent faad524e338b7a26b4fc335b893881de39a2a8c4
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Fri, 30 May 2025 20:35:41 +0200

Add constexpr version of most common ctype checks

Diffstat:
A include/based/char/is/alnum.hpp | ++++++++++++++
A include/based/char/is/alpha.hpp | ++++++++++++++
A include/based/char/is/alpha_lower.hpp | +++++++++++
A include/based/char/is/alpha_upper.hpp | +++++++++++
A include/based/char/is/digit.hpp | ++++++++++++
A include/based/char/is/xdigit.hpp | ++++++++++++

6 files changed, 74 insertions(+), 0 deletions(-)


diff --git a/ include/based/char/is/alnum.hpp b/ include/based/char/is/alnum.hpp

@@ -0,0 +1,14 @@

#pragma once

#include "based/char/is/alpha.hpp"
#include "based/char/is/digit.hpp"

namespace based
{

constexpr bool is_alnum(char chr)
{
return is_alpha(chr) || is_digit(chr);
}

} // namespace based

diff --git a/ include/based/char/is/alpha.hpp b/ include/based/char/is/alpha.hpp

@@ -0,0 +1,14 @@

#pragma once

#include "based/char/is/alpha_lower.hpp"
#include "based/char/is/alpha_upper.hpp"

namespace based
{

constexpr bool is_alpha(char chr)
{
return is_alpha_lower(chr) || is_alpha_upper(chr);
}

} // namespace based

diff --git a/ include/based/char/is/alpha_lower.hpp b/ include/based/char/is/alpha_lower.hpp

@@ -0,0 +1,11 @@

#pragma once

namespace based
{

constexpr bool is_alpha_lower(char chr)
{
return chr >= 'a' && chr <= 'z';
}

} // namespace based

diff --git a/ include/based/char/is/alpha_upper.hpp b/ include/based/char/is/alpha_upper.hpp

@@ -0,0 +1,11 @@

#pragma once

namespace based
{

constexpr bool is_alpha_upper(char chr)
{
return chr >= 'A' && chr <= 'Z';
}

} // namespace based

diff --git a/ include/based/char/is/digit.hpp b/ include/based/char/is/digit.hpp

@@ -0,0 +1,12 @@

#pragma once

namespace based
{

constexpr bool is_digit(char chr)
{
return chr >= '0' && chr <= '9';
}

} // namespace based

diff --git a/ include/based/char/is/xdigit.hpp b/ include/based/char/is/xdigit.hpp

@@ -0,0 +1,12 @@

#pragma once

namespace based
{

constexpr bool is_xdigit(char chr)
{
return (chr >= 'a' && chr <= 'f') || (chr >= 'A' && chr <= 'F')
|| (chr >= '0' && chr <= '9');
}

} // namespace based