mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Formatted src/services/postal_code
This commit is contained in:
@@ -18,27 +18,27 @@ XegerPostalCodeService::XegerPostalCodeService()
|
|||||||
: rng_(std::random_device{}()) {}
|
: rng_(std::random_device{}()) {}
|
||||||
|
|
||||||
std::string XegerPostalCodeService::GeneratePostalCode(const City& city) {
|
std::string XegerPostalCodeService::GeneratePostalCode(const City& city) {
|
||||||
const PostalCodeSpec& spec = city.postal_code;
|
const PostalCodeSpec& spec = city.postal_code;
|
||||||
|
|
||||||
std::vector<std::string_view> city_patterns;
|
std::vector<std::string_view> city_patterns;
|
||||||
for (const std::string& pattern : spec.city_regexes) {
|
for (const std::string& pattern : spec.city_regexes) {
|
||||||
if (!pattern.empty()) {
|
if (!pattern.empty()) {
|
||||||
city_patterns.push_back(pattern);
|
city_patterns.push_back(pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view pattern;
|
std::string_view pattern;
|
||||||
if (!city_patterns.empty()) {
|
if (!city_patterns.empty()) {
|
||||||
std::uniform_int_distribution<size_t> dist(0, city_patterns.size() - 1);
|
std::uniform_int_distribution<size_t> dist(0, city_patterns.size() - 1);
|
||||||
pattern = city_patterns[dist(rng_)];
|
pattern = city_patterns[dist(rng_)];
|
||||||
} else if (!spec.country_format_regex.empty()) {
|
} else if (!spec.country_format_regex.empty()) {
|
||||||
pattern = spec.country_format_regex;
|
pattern = spec.country_format_regex;
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error(std::format(
|
throw std::runtime_error(std::format(
|
||||||
"XegerPostalCodeService: no postal-code pattern available for "
|
"XegerPostalCodeService: no postal-code pattern available for "
|
||||||
"city '{}'",
|
"city '{}'",
|
||||||
city.city));
|
city.city));
|
||||||
}
|
}
|
||||||
|
|
||||||
return GenerateStringFromRegex(pattern, rng_);
|
return GenerateStringFromRegex(pattern, rng_);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user