From 6282c4e163751149ade6d5407229644fd41d5fbb Mon Sep 17 00:00:00 2001
From: Laine Stump <laine@redhat.com>
Date: Thu, 7 Jan 2021 19:55:43 -0500
Subject: [PATCH 080/108] util: new function virSkipToDigit()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This function skips over the beginning of a string until it reaches a
decimal digit (0-9) or the NULL at the end of the string. The original
pointer is modified in place (similar to virSkipSpaces()).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 0e89a7b4e0defb2b3711c1e854a51d296d7b6f7f)
---
 src/libvirt_private.syms |  1 +
 src/util/virstring.c     | 18 ++++++++++++++++++
 src/util/virstring.h     |  1 +
 3 files changed, 20 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 997039868e..4d54c5e42f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3172,6 +3172,7 @@ virStorageFileBackendRegister;
 virSkipSpaces;
 virSkipSpacesAndBackslash;
 virSkipSpacesBackwards;
+virSkipToDigit;
 virStrcpy;
 virStringBufferIsPrintable;
 virStringFilterChars;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index e9e792f3bf..56c5e37def 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -817,6 +817,24 @@ virSkipSpacesAndBackslash(const char **str)
     *str = cur;
 }
 
+
+/**
+ * virSkipToDigit:
+ * @str: pointer to the char pointer used
+ *
+ * Skip over any character that is not 0-9
+ */
+void
+virSkipToDigit(const char **str)
+{
+    const char *cur = *str;
+
+    while (*cur && !g_ascii_isdigit(*cur))
+        cur++;
+    *str = cur;
+}
+
+
 /**
  * virTrimSpaces:
  * @str: string to modify to remove all trailing spaces
diff --git a/src/util/virstring.h b/src/util/virstring.h
index 360c68395c..878da86c33 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -117,6 +117,7 @@ int virDoubleToStr(char **strp, double number)
 
 void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1);
 void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1);
+void virSkipToDigit(const char **str) ATTRIBUTE_NONNULL(1);
 void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1);
 void virSkipSpacesBackwards(const char *str, char **endp)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-- 
2.33.0

