feat(string): add functions to categorize strings

This commit is contained in:
2024-11-10 19:24:40 +08:00
parent 7a80a80a12
commit 09bbcecc28
4 changed files with 83 additions and 2 deletions

View File

@ -377,6 +377,52 @@ public:
return RFind([Char](ElementType C) { return C != Char; }, Index);
}
public:
/** @return true if the string only contains valid characters, false otherwise. */
NODISCARD constexpr bool IsValid() const
{
for (ElementType Char : *this)
{
if (!TChar<ElementType>::IsValid(Char)) return false;
}
return true;
}
/** @return true if the string only contains ASCII characters, false otherwise. */
NODISCARD constexpr bool IsASCII() const
{
for (ElementType Char : *this)
{
if (!TChar<ElementType>::IsASCII(Char)) return false;
}
return true;
}
/** @return true if the string only contains numeric characters, false otherwise. */
NODISCARD constexpr bool IsNumeric() const
{
for (ElementType Char : *this)
{
if (!TChar<ElementType>::IsDigit(Char)) return false;
}
return true;
}
/** @return true if the string only contains numeric characters, false otherwise. */
NODISCARD constexpr bool IsNumeric(unsigned Base) const
{
for (ElementType Char : *this)
{
if (!TChar<ElementType>::IsDigit(Char, Base)) return false;
}
return true;
}
public:
/**