mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
util: string: Introduce virStringHasChars
The helper returns true if a string contains any of the given chars. virStringHasControlChars can be reimplemented using that helper. Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
ad97fecee7
commit
c0ce84ca98
@ -2692,6 +2692,7 @@ virStrcpy;
|
|||||||
virStrdup;
|
virStrdup;
|
||||||
virStringBufferIsPrintable;
|
virStringBufferIsPrintable;
|
||||||
virStringEncodeBase64;
|
virStringEncodeBase64;
|
||||||
|
virStringHasChars;
|
||||||
virStringHasControlChars;
|
virStringHasControlChars;
|
||||||
virStringIsEmpty;
|
virStringIsEmpty;
|
||||||
virStringIsPrintable;
|
virStringIsPrintable;
|
||||||
|
@ -1195,6 +1195,24 @@ virStringStripIPv6Brackets(char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virStringHasChars:
|
||||||
|
* @str: string to look for chars in
|
||||||
|
* @chars: chars to find in string @str
|
||||||
|
*
|
||||||
|
* Returns true if @str contains any of the chars in @chars.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
virStringHasChars(const char *str,
|
||||||
|
const char *chars)
|
||||||
|
{
|
||||||
|
if (!str)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return str[strcspn(str, chars)] != '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char control_chars[] =
|
static const char control_chars[] =
|
||||||
"\x01\x02\x03\x04\x05\x06\x07"
|
"\x01\x02\x03\x04\x05\x06\x07"
|
||||||
"\x08" /* \t \n */ "\x0B\x0C" /* \r */ "\x0E\x0F"
|
"\x08" /* \t \n */ "\x0B\x0C" /* \r */ "\x0E\x0F"
|
||||||
@ -1204,10 +1222,7 @@ static const char control_chars[] =
|
|||||||
bool
|
bool
|
||||||
virStringHasControlChars(const char *str)
|
virStringHasControlChars(const char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
return virStringHasChars(str, control_chars);
|
||||||
return false;
|
|
||||||
|
|
||||||
return str[strcspn(str, control_chars)] != '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -286,6 +286,8 @@ char *virStringReplace(const char *haystack,
|
|||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
||||||
|
|
||||||
void virStringStripIPv6Brackets(char *str);
|
void virStringStripIPv6Brackets(char *str);
|
||||||
|
bool virStringHasChars(const char *str,
|
||||||
|
const char *chars);
|
||||||
bool virStringHasControlChars(const char *str);
|
bool virStringHasControlChars(const char *str);
|
||||||
void virStringStripControlChars(char *str);
|
void virStringStripControlChars(char *str);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user