Formatted src/services/postal_code

This commit is contained in:
Aaron Po
2026-07-19 04:10:33 -04:00
parent 59053fcddd
commit 34a036d7b3

View File

@@ -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_);
} }