diff options
Diffstat (limited to 'parse_string.cpp')
-rw-r--r-- | parse_string.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/parse_string.cpp b/parse_string.cpp index a6bb418..7e23f5f 100644 --- a/parse_string.cpp +++ b/parse_string.cpp | |||
@@ -113,6 +113,33 @@ std::ostream &operator<<(std::ostream &os, const KernelConfigTypedValue &kctv) { | |||
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | bool parse(const std::string& s, Level* l) { | ||
117 | if (s.empty()) { | ||
118 | *l = Level::UNSPECIFIED; | ||
119 | return true; | ||
120 | } | ||
121 | if (s == "legacy") { | ||
122 | *l = Level::LEGACY; | ||
123 | return true; | ||
124 | } | ||
125 | size_t value; | ||
126 | if (!ParseUint(s, &value)) { | ||
127 | return false; | ||
128 | } | ||
129 | *l = static_cast<Level>(value); | ||
130 | return true; | ||
131 | } | ||
132 | |||
133 | std::ostream& operator<<(std::ostream& os, Level l) { | ||
134 | if (l == Level::UNSPECIFIED) { | ||
135 | return os; | ||
136 | } | ||
137 | if (l == Level::LEGACY) { | ||
138 | return os << "legacy"; | ||
139 | } | ||
140 | return os << static_cast<size_t>(l); | ||
141 | } | ||
142 | |||
116 | // Notice that strtoull is used even though KernelConfigIntValue is signed int64_t, | 143 | // Notice that strtoull is used even though KernelConfigIntValue is signed int64_t, |
117 | // because strtoull can accept negative values as well. | 144 | // because strtoull can accept negative values as well. |
118 | // Notice that according to man strtoul, strtoull can actually accept | 145 | // Notice that according to man strtoul, strtoull can actually accept |