1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <string_view>
20 
21 namespace android {
22 namespace base {
23 
24 // Parse the given string as yes or no inactivation of some sort. Return one of the
25 // ParseBoolResult enumeration values.
26 //
27 // The following values parse as true:
28 //
29 //   1
30 //   on
31 //   true
32 //   y
33 //   yes
34 //
35 //
36 // The following values parse as false:
37 //
38 //   0
39 //   false
40 //   n
41 //   no
42 //   off
43 //
44 // Anything else is a parse error.
45 //
46 // The purpose of this function is to have a single canonical parser for yes-or-no indications
47 // throughout the system.
48 
49 enum class ParseBoolResult {
50   kError,
51   kFalse,
52   kTrue,
53 };
54 
55 ParseBoolResult ParseBool(std::string_view s);
56 
57 }  // namespace base
58 }  // namespace android
59