6#include "addressformat_p.h"
7#include "addressformatparser_p.h"
11using namespace KContacts;
16}
static constexpr const field_map[] = {
17 {
'A', AddressFormatField::StreetAddress},
18 {
'C', AddressFormatField::Locality},
19 {
'D', AddressFormatField::DependentLocality},
20 {
'N', AddressFormatField::Name},
21 {
'O', AddressFormatField::Organization},
22 {
'P', AddressFormatField::PostOfficeBox},
23 {
'R', AddressFormatField::Country},
24 {
'S', AddressFormatField::Region},
25 {
'X', AddressFormatField::SortingCode},
26 {
'Z', AddressFormatField::PostalCode},
31 const auto it = std::lower_bound(std::begin(field_map), std::end(field_map), c.cell(), [](
auto lhs,
auto rhs) {
34 if (it == std::end(field_map) || (*it).c != c.cell() || c.row() != 0) {
35 return AddressFormatField::NoField;
44 fields |= parseField(c);
49std::vector<AddressFormatElement> AddressFormatParser::parseElements(
QStringView s)
51 std::vector<AddressFormatElement> elements;
53 for (
auto it = s.
begin(); it != s.
end(); ++it) {
57 auto e = AddressFormatElementPrivate::get(elem);
58 e->literal = std::move(literal);
59 elements.push_back(elem);
65 const auto f = parseField(*it);
66 if (f == AddressFormatField::NoField) {
67 qWarning() <<
"invalid format field element: %" << *it <<
"in" << s;
70 auto e = AddressFormatElementPrivate::get(elem);
72 elements.push_back(elem);
81 auto e = AddressFormatElementPrivate::get(elem);
82 e->literal = std::move(literal);
83 elements.push_back(elem);
AddressFormatField
Address field types.
bool isEmpty() const const
const_iterator begin() const const
const_iterator end() const const