From e59c6c88c98e27c614baa42ff56a2910e7dfd8f8 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 4 Feb 2024 12:52:46 +0100 Subject: [PATCH] Tier1: add V_IsAllDigit() This function checks if a string consists of only numeric characters. --- r5dev/public/tier1/strtools.h | 1 + r5dev/tier1/strtools.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/r5dev/public/tier1/strtools.h b/r5dev/public/tier1/strtools.h index 0188f310..baa6312e 100644 --- a/r5dev/public/tier1/strtools.h +++ b/r5dev/public/tier1/strtools.h @@ -67,6 +67,7 @@ const char* V_strnchr(const char* pStr, char c, ssize_t n); bool V_isspace(int c); inline bool V_isalnum(char c) { return isalnum((unsigned char)c) != 0; } +bool V_IsAllDigit(const char* pString); // this is locale-unaware and therefore faster version of standard isdigit() // It also avoids sign-extension errors. diff --git a/r5dev/tier1/strtools.cpp b/r5dev/tier1/strtools.cpp index 727bc5e0..4e7b5527 100644 --- a/r5dev/tier1/strtools.cpp +++ b/r5dev/tier1/strtools.cpp @@ -242,6 +242,21 @@ bool V_isspace(int c) #endif } +bool V_IsAllDigit(const char* pString) +{ + while (*pString) + { + if (!V_isdigit(*pString)) + { + return false; + } + + pString++; + } + + return true; +} + //----------------------------------------------------------------------------- // Purpose: // Input : *in -