]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2019 Red Hat Ltd | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #include "CommandHandler.h" | |
16 | ||
17 | #include "common/strtol.h" | |
18 | #include "include/ceph_assert.h" | |
19 | ||
20 | #include <ostream> | |
21 | #include <string> | |
22 | #include <string_view> | |
23 | ||
24 | int CommandHandler::parse_bool(std::string_view str, bool* result, std::ostream& ss) | |
25 | { | |
26 | ceph_assert(result != nullptr); | |
27 | ||
28 | std::string interr; | |
29 | int64_t n = strict_strtoll(str.data(), 10, &interr); | |
30 | ||
31 | if (str == "false" || str == "no" | |
32 | || (interr.length() == 0 && n == 0)) { | |
33 | *result = false; | |
34 | return 0; | |
35 | } else if (str == "true" || str == "yes" | |
36 | || (interr.length() == 0 && n == 1)) { | |
37 | *result = true; | |
38 | return 0; | |
39 | } else { | |
40 | ss << "value must be false|no|0 or true|yes|1"; | |
41 | return -EINVAL; | |
42 | } | |
43 | } |