diff options
author | Yuchen Zeng <zyc@google.com> | 2017-08-25 14:09:47 -0700 |
---|---|---|
committer | Yuchen Zeng <zyc@google.com> | 2017-08-25 14:09:47 -0700 |
commit | 6514a0df72d9425ae5058eab6dd120179b2105d1 (patch) | |
tree | 7d90edf6082a2a96ce06549a2679bf959e468732 /src/core/lib/support | |
parent | ba23e799dc1c4ea5f6c0139bf95cd04e0794e714 (diff) |
Add gpr_is_true
Diffstat (limited to 'src/core/lib/support')
-rw-r--r-- | src/core/lib/support/string.c | 13 | ||||
-rw-r--r-- | src/core/lib/support/string.h | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/core/lib/support/string.c b/src/core/lib/support/string.c index b65009754a..ec93303024 100644 --- a/src/core/lib/support/string.c +++ b/src/core/lib/support/string.c @@ -298,3 +298,16 @@ void *gpr_memrchr(const void *s, int c, size_t n) { } return NULL; } + +bool gpr_is_true(const char *s) { + if (s == NULL) { + return false; + } + static const char *truthy[] = {"yes", "true", "1"}; + for (size_t i = 0; i < GPR_ARRAY_SIZE(truthy); i++) { + if (0 == gpr_stricmp(s, truthy[i])) { + return true; + } + } + return false; +} diff --git a/src/core/lib/support/string.h b/src/core/lib/support/string.h index e11df8439d..5a56fa3a0a 100644 --- a/src/core/lib/support/string.h +++ b/src/core/lib/support/string.h @@ -19,6 +19,7 @@ #ifndef GRPC_CORE_LIB_SUPPORT_STRING_H #define GRPC_CORE_LIB_SUPPORT_STRING_H +#include <stdbool.h> #include <stddef.h> #include <grpc/support/port_platform.h> @@ -106,6 +107,8 @@ int gpr_stricmp(const char *a, const char *b); void *gpr_memrchr(const void *s, int c, size_t n); +/** Return true if lower(s) equals "true", "yes" or "1", otherwise false. */ +bool gpr_is_true(const char *s); #ifdef __cplusplus } #endif |