PStringUtils::IsInt: accept an optional leading sign

IsInt now recognises (possibly signed) integers such as "-5" or "+42",
making it slightly more permissive than TString::IsDigit(). A lone sign,
a double sign, or a sign following a digit are still rejected. strToNum
test expectations updated accordingly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-06 14:14:11 +02:00
parent aa5cdf8d6a
commit 07f9c744b3
3 changed files with 29 additions and 12 deletions
+5 -3
View File
@@ -67,11 +67,13 @@ class PStringUtils
static std::vector<std::string> Split(const std::string &str, const std::string &delimiters);
/**
* <p>Returns true if the string is a non-empty sequence of decimal
* digits only. Mirrors TString::IsDigit().
* <p>Returns true if the string is a (possibly signed) integer literal,
* i.e. a non-empty sequence of decimal digits with an optional single
* leading sign (+/-). Slightly more permissive than TString::IsDigit(),
* which rejects a sign, so that e.g. "-5" is also recognised.
*
* @param str string to be checked
* @return true if str consists of digits only
* @return true if str is a (possibly signed) integer
*/
static bool IsInt(const std::string &str);