File kdump-Implement-KString-isHexNumber.patch of Package kdump.23238
From: Petr Tesarik <ptesarik@suse.com>
Date: Fri, 26 Feb 2021 10:41:14 +0100
Subject: Implement KString::isHexNumber
References: bsc#1180513
Upstream: merged
Git-commit: 1d8f3b99efc2b690fae3883edee318033c4eb6a9
Check whether a string is a valid hexadecimal number.
Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
kdumptool/stringutil.cc | 15 +++++++++++++++
kdumptool/stringutil.h | 8 ++++++++
2 files changed, 23 insertions(+)
--- a/kdumptool/stringutil.cc
+++ b/kdumptool/stringutil.cc
@@ -307,6 +307,21 @@ bool KString::isNumber()
}
// -----------------------------------------------------------------------------
+bool KString::isHexNumber()
+ throw ()
+{
+ iterator it = begin();
+
+ if (it == end())
+ return false;
+ do {
+ if (!isxdigit(*it))
+ return false;
+ } while (++it != end());
+ return true;
+}
+
+// -----------------------------------------------------------------------------
KString& KString::trim(const char *chars)
throw ()
{
--- a/kdumptool/stringutil.h
+++ b/kdumptool/stringutil.h
@@ -248,6 +248,14 @@ class KString : public std::string {
throw ();
/**
+ * Checks if the string is a hexadecimal number (no leading '0x').
+ *
+ * @return true if it's a hex number, false otherwise
+ */
+ bool isHexNumber()
+ throw ();
+
+ /**
* Remove trailing or leading stuff.
*
* @param[in] chars the characters to remove (default: white space)