Simplified extracting of calling code from phone number.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user