Code improvements

Introduced CharOps namespace.
Moved some functions from StringOps to CharOps.
This commit is contained in:
Valentino Orlandi 2023-12-01 21:57:40 +01:00
parent 3d43937b1e
commit 4d0d9caec1
Signed by: elB4RTO
GPG Key ID: 1719E976DB2D4E71
1 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,71 @@
#ifndef LOGDOCTOR__UTILITIES__CHARS_H
#define LOGDOCTOR__UTILITIES__CHARS_H
//! CharOps
/*!
Utilities for chars
*/
namespace CharOps
{
//! Checks whether a character is numeric
/*!
\param chr The target character
\return The result of the check
*/
inline bool isNumeric( const char& chr )
{
return chr > 47 && chr < 58; // 0-9
}
//! Checks whether a character is alphabetic
/*!
\param chr The target character
\return The result of the check
*/
inline bool isAlphabetic( const char& chr )
{
return (chr > 96 && chr < 123) // a-z
|| (chr > 64 && chr < 91); // A-Z
}
//! Checks whether a character is alphanumeric
/*!
\param chr The target character
\return The result of the check
*/
inline bool isAlnum( const char& chr )
{
return isAlphabetic( chr )
|| isNumeric( chr );
}
//! Checks whether a character is hexadecimal
/*!
\param chr The target character
\return The result of the check
*/
inline bool isHex( const char& chr )
{
return (chr > 47 && chr < 58) // 0-9
|| (chr > 64 && chr < 71) // A-F
|| (chr > 96 && chr < 103); // a-f
}
//! Checks whether a character can be part of an IPv4/IPv6
/*!
\param chr The target character
\return The result of the check
*/
inline bool isIP( const char& chr )
{
return chr == 46 // .
|| chr == 58 // :
|| isHex( chr );
}
} // namespace CharOps
#endif // LOGDOCTOR__UTILITIES__CHARS_H