5 #include <blockfilter.h>
39 bool LegacyParsePrechecks(
const std::string& str)
43 if (str.size() >= 1 && (
IsSpace(str[0]) ||
IsSpace(str[str.size() - 1])))
50 bool LegacyParseInt32(
const std::string& str, int32_t* out)
52 if (!LegacyParsePrechecks(str))
56 long int n = strtol(str.c_str(), &endp, 10);
57 if (out) *out = (int32_t)n;
61 return endp && *endp == 0 && !errno &&
62 n >= std::numeric_limits<int32_t>::min() &&
63 n <= std::numeric_limits<int32_t>::max();
66 bool LegacyParseInt64(
const std::string& str, int64_t* out)
68 if (!LegacyParsePrechecks(str))
72 long long int n = strtoll(str.c_str(), &endp, 10);
73 if (out) *out = (int64_t)n;
76 return endp && *endp == 0 && !errno &&
77 n >= std::numeric_limits<int64_t>::min() &&
78 n <= std::numeric_limits<int64_t>::max();
81 bool LegacyParseUInt32(
const std::string& str, uint32_t* out)
83 if (!LegacyParsePrechecks(str))
85 if (str.size() >= 1 && str[0] ==
'-')
89 unsigned long int n = strtoul(str.c_str(), &endp, 10);
90 if (out) *out = (uint32_t)n;
94 return endp && *endp == 0 && !errno &&
95 n <= std::numeric_limits<uint32_t>::max();
98 bool LegacyParseUInt8(
const std::string& str, uint8_t* out)
101 if (!LegacyParseUInt32(str, &
u32) ||
u32 > std::numeric_limits<uint8_t>::max()) {
104 if (out !=
nullptr) {
105 *out =
static_cast<uint8_t
>(
u32);
110 bool LegacyParseUInt64(
const std::string& str, uint64_t* out)
112 if (!LegacyParsePrechecks(str))
114 if (str.size() >= 1 && str[0] ==
'-')
116 char* endp =
nullptr;
118 unsigned long long int n = strtoull(str.c_str(), &endp, 10);
119 if (out) *out = (uint64_t)n;
122 return endp && *endp == 0 && !errno &&
123 n <= std::numeric_limits<uint64_t>::max();
129 return strtoll(str.c_str(),
nullptr, 10);
157 (void)
Join(random_string_vector, random_string_1);
164 }
catch (
const std::runtime_error&) {
171 }
catch (
const std::runtime_error&) {
175 }
catch (
const std::runtime_error&) {
183 std::string host_out;
186 (void)
ToLower(random_string_1);
187 (void)
ToUpper(random_string_1);
189 (void)
TrimString(random_string_1, random_string_2);
192 (void)
_(random_string_1.c_str());
195 }
catch (
const std::runtime_error&) {
202 data_stream << random_string_1;
204 data_stream >> limited_string;
205 assert(data_stream.empty());
206 assert(s.size() <= random_string_1.size());
208 if (!random_string_1.empty()) {
211 }
catch (
const std::ios_base::failure&) {
217 data_stream << limited_string;
218 std::string deserialized_string;
219 data_stream >> deserialized_string;
220 assert(data_stream.empty());
221 assert(deserialized_string == random_string_1);
239 const bool ok_i32 =
ParseInt32(random_string_1, &i32);
240 const bool ok_i64 =
ParseInt64(random_string_1, &i64);
242 const bool ok_u64 =
ParseUInt64(random_string_1, &u64);
250 const bool ok_i32_legacy = LegacyParseInt32(random_string_1, &i32_legacy);
251 const bool ok_i64_legacy = LegacyParseInt64(random_string_1, &i64_legacy);
252 const bool ok_u32_legacy = LegacyParseUInt32(random_string_1, &u32_legacy);
253 const bool ok_u64_legacy = LegacyParseUInt64(random_string_1, &u64_legacy);
254 const bool ok_u8_legacy = LegacyParseUInt8(random_string_1, &u8_legacy);
256 assert(ok_i32 == ok_i32_legacy);
257 assert(ok_i64 == ok_i64_legacy);
258 assert(ok_u32 == ok_u32_legacy);
259 assert(ok_u64 == ok_u64_legacy);
260 assert(ok_u8 == ok_u8_legacy);
263 assert(i32 == i32_legacy);
266 assert(i64 == i64_legacy);
272 assert(u64 == u64_legacy);
280 const int locale_independent_atoi_result = LocaleIndependentAtoi<int>(random_string_1);
281 const int64_t atoi64_result =
atoi64_legacy(random_string_1);
282 assert(locale_independent_atoi_result == std::clamp<int64_t>(atoi64_result, std::numeric_limits<int>::min(), std::numeric_limits<int>::max()));
286 const int64_t atoi64_result =
atoi64_legacy(random_string_1);
287 const int64_t locale_independent_atoi_result = LocaleIndependentAtoi<int64_t>(random_string_1);
288 assert(atoi64_result == locale_independent_atoi_result);