util: new function virSkipToDigit()

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>
This commit is contained in:
Laine Stump 2021-01-07 19:55:43 -05:00
parent dc837a412f
commit 0e89a7b4e0
3 changed files with 20 additions and 0 deletions

View File

@ -3217,6 +3217,7 @@ virStorageFileBackendRegister;
virSkipSpaces;
virSkipSpacesAndBackslash;
virSkipSpacesBackwards;
virSkipToDigit;
virStrcpy;
virStringBufferIsPrintable;
virStringFilterChars;

View File

@ -752,6 +752,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

View File

@ -110,6 +110,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);