Simplified extracting of calling code from phone number.

This commit is contained in:
23rd
2021-08-29 22:15:35 +03:00
committed by John Preston
parent 44c188024e
commit 558e1d96fd
8 changed files with 18 additions and 19 deletions

View File

@@ -344,6 +344,9 @@ FormatResult CountriesInstance::format(FormatArgs args) {
if (bestCountryPtr == nullptr) {
return FormatResult{ .formatted = phoneNumber };
}
if (args.onlyCode) {
return FormatResult{ .code = bestCallingCodePtr->callingCode };
}
const auto codeSize = int(bestCallingCodePtr->callingCode.size());
@@ -450,4 +453,8 @@ CountriesInstance &Instance() {
return SingleInstance;
}
QString ExtractPhoneCode(const QString &phone) {
return Instance().format({ .phone = phone, .onlyCode = true }).code;
}
} // namespace Countries

View File

@@ -27,6 +27,7 @@ struct Info {
struct FormatResult {
QString formatted;
QVector<int> groups;
QString code;
};
struct FormatArgs {
@@ -34,6 +35,7 @@ struct FormatArgs {
bool onlyGroups = false;
bool skipCode = false;
bool incomplete = false;
bool onlyCode = false;
};
class CountriesInstance final {
@@ -63,4 +65,6 @@ private:
CountriesInstance &Instance();
[[nodiscard]] QString ExtractPhoneCode(const QString &phone);
} // namespace Countries