Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
[libcontacts] Skip validation when normalizing numbers
Browse files Browse the repository at this point in the history
In most cases, there is no benefit to validating numbers as they are
normalized, since the data has come from the system. Validation of
data already present in the system is counterproductive since it can
cause us not to process some details.
  • Loading branch information
matthewvogt committed Feb 10, 2014
1 parent 285aff6 commit f73cd4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/seasidecache.cpp
Expand Up @@ -1241,22 +1241,23 @@ QUrl SeasideCache::filteredAvatarUrl(const QContact &contact, const QStringList
return QUrl();
}

QString SeasideCache::normalizePhoneNumber(const QString &input)
QString SeasideCache::normalizePhoneNumber(const QString &input, bool validate)
{
const QtContactsSqliteExtensions::NormalizePhoneNumberFlags normalizeFlags(QtContactsSqliteExtensions::KeepPhoneNumberDialString |
QtContactsSqliteExtensions::ValidatePhoneNumber);
QtContactsSqliteExtensions::NormalizePhoneNumberFlags normalizeFlags(QtContactsSqliteExtensions::KeepPhoneNumberDialString);
if (validate) {
// If the number if not valid, return empty
normalizeFlags |= QtContactsSqliteExtensions::ValidatePhoneNumber;
}

// If the number if not valid, return null
return QtContactsSqliteExtensions::normalizePhoneNumber(input, normalizeFlags);
}

QString SeasideCache::minimizePhoneNumber(const QString &input)
QString SeasideCache::minimizePhoneNumber(const QString &input, bool validate)
{
// TODO: use a configuration variable to make this configurable
const int maxCharacters = QtContactsSqliteExtensions::DefaultMaximumPhoneNumberCharacters;

// If the number if not valid, return null
QString validated(normalizePhoneNumber(input));
QString validated(normalizePhoneNumber(input, validate));
if (validated.isNull())
return validated;

Expand Down
4 changes: 2 additions & 2 deletions src/seasidecache.h
Expand Up @@ -326,8 +326,8 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject
static QString generateDisplayLabelFromNonNameDetails(const QContact &contact);
static QUrl filteredAvatarUrl(const QContact &contact, const QStringList &metadataFragments = QStringList());

static QString normalizePhoneNumber(const QString &input);
static QString minimizePhoneNumber(const QString &input);
static QString normalizePhoneNumber(const QString &input, bool validate = false);
static QString minimizePhoneNumber(const QString &input, bool validate = false);

bool event(QEvent *event);

Expand Down

0 comments on commit f73cd4c

Please sign in to comment.