| 194 | } |
| 195 | |
| 196 | int64_t Config::SafeScan(const string &varName, const string §ion, int64_t defaultValue, |
| 197 | int64_t minValue, int64_t maxValue) { |
| 198 | int64_t scannedValue = 0; |
| 199 | |
| 200 | // Here we use %12lld to truncate long number string, because configure value |
| 201 | // has type of int32_t, who has the range [-2^31, 2^31-1] (10-digit number) |
| 202 | bool isSuccess = Scan(section, varName, "%12lld", &scannedValue); |
| 203 | |
| 204 | if (!isSuccess) { |
| 205 | scannedValue = defaultValue; |
| 206 | } else if (scannedValue > maxValue) { |
| 207 | scannedValue = maxValue; |
| 208 | } else if (scannedValue < minValue) { |
| 209 | scannedValue = minValue; |
| 210 | } |
| 211 | |
| 212 | return scannedValue; |
| 213 | } |
| 214 | |
| 215 | bool ToBool(string str) { |
| 216 | std::transform(str.begin(), str.end(), str.begin(), ::tolower); |