When RNG2C generates codes for builtin 'Bool.on_off', it includes virStringParseOnOff in those codes. Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx> --- src/util/virstring.c | 22 ++++++++++++++++++++++ src/util/virstring.h | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index e9e792f..2d0bb23 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1404,3 +1404,25 @@ int virStringParseYesNo(const char *str, bool *result) return 0; } + + +/** + * virStringParseOnOff: + * @str: "on|off" to parse, must not be NULL. + * @result: pointer to the boolean result of @str conversion + * + * Parses a "on|off" string and converts it into a boolean. + * + * Returns 0 on success and -1 on error. + */ +int virStringParseOnOff(const char *str, bool *result) +{ + if (STREQ(str, "on")) + *result = true; + else if (STREQ(str, "off")) + *result = false; + else + return -1; + + return 0; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index 360c683..c528e44 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -185,6 +185,11 @@ int virStringParsePort(const char *str, int virStringParseYesNo(const char *str, bool *result) G_GNUC_WARN_UNUSED_RESULT; + +int virStringParseOnOff(const char *str, + bool *result) + G_GNUC_WARN_UNUSED_RESULT; + /** * VIR_AUTOSTRINGLIST: * -- 2.17.1