提交 4004977f 编写于 作者: P Peter Krempa

util: Fix docs for virBitmapParse

This patch changes the name of the @sep argument to @terminator and
clarifies it's usage. This patch also explicitly documents that
whitespace can't be used as @terminator as it is skipped multiple times
in the implementation.
上级 3f46ce78
...@@ -265,6 +265,7 @@ char *virBitmapFormat(virBitmapPtr bitmap) ...@@ -265,6 +265,7 @@ char *virBitmapFormat(virBitmapPtr bitmap)
/** /**
* virBitmapParse: * virBitmapParse:
* @str: points to a string representing a human-readable bitmap * @str: points to a string representing a human-readable bitmap
* @terminator: character separating the bitmap to parse
* @bitmap: a bitmap created from @str * @bitmap: a bitmap created from @str
* @bitmapSize: the upper limit of num of bits in created bitmap * @bitmapSize: the upper limit of num of bits in created bitmap
* *
...@@ -275,11 +276,17 @@ char *virBitmapFormat(virBitmapPtr bitmap) ...@@ -275,11 +276,17 @@ char *virBitmapFormat(virBitmapPtr bitmap)
* to set, and ^N, which means to unset the bit, and N-M for ranges of bits * to set, and ^N, which means to unset the bit, and N-M for ranges of bits
* to set. * to set.
* *
* To allow parsing of bitmaps within larger strings it is possible to set
* a termination character in the argument @terminator. When the character
* in @terminator is encountered in @str, the parsing of the bitmap stops.
* Pass 0 as @terminator if it is not needed. Whitespace characters may not
* be used as terminators.
*
* Returns the number of bits set in @bitmap, or -1 in case of error. * Returns the number of bits set in @bitmap, or -1 in case of error.
*/ */
int
int virBitmapParse(const char *str, virBitmapParse(const char *str,
char sep, char terminator,
virBitmapPtr *bitmap, virBitmapPtr *bitmap,
size_t bitmapSize) size_t bitmapSize)
{ {
...@@ -302,7 +309,7 @@ int virBitmapParse(const char *str, ...@@ -302,7 +309,7 @@ int virBitmapParse(const char *str,
if (!*bitmap) if (!*bitmap)
return -1; return -1;
while (*cur != 0 && *cur != sep) { while (*cur != 0 && *cur != terminator) {
/* /*
* 3 constructs are allowed: * 3 constructs are allowed:
* - N : a single CPU number * - N : a single CPU number
...@@ -326,7 +333,7 @@ int virBitmapParse(const char *str, ...@@ -326,7 +333,7 @@ int virBitmapParse(const char *str,
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (*cur == ',' || *cur == 0 || *cur == sep) { if (*cur == ',' || *cur == 0 || *cur == terminator) {
if (neg) { if (neg) {
if (virBitmapIsSet(*bitmap, start)) { if (virBitmapIsSet(*bitmap, start)) {
ignore_value(virBitmapClearBit(*bitmap, start)); ignore_value(virBitmapClearBit(*bitmap, start));
...@@ -366,7 +373,7 @@ int virBitmapParse(const char *str, ...@@ -366,7 +373,7 @@ int virBitmapParse(const char *str,
cur++; cur++;
virSkipSpaces(&cur); virSkipSpaces(&cur);
neg = false; neg = false;
} else if (*cur == 0 || *cur == sep) { } else if (*cur == 0 || *cur == terminator) {
break; break;
} else { } else {
goto parse_error; goto parse_error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册