Changeset 56:e63ceb8090cd in SMSSender for lib/libdatatypes/src/snumber.cpp


Ignore:
Timestamp:
Feb 2, 2010 9:53:45 AM (13 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
3.0
Convert:
svn:3639001d-8e34-449c-bb86-3782b86c4877/branches/3.0@55
Message:
  • Renamed accountmodel to accounttreemodel
  • Implemented creation of new contact if number is unknown in vcmain
  • Areacode is now in its own field in vceditcontact
  • Accountlist in vcmain is now controlled by a model (Needs filtering of only active ones)
  • Settingspath is dynamic and user-based now
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/libdatatypes/src/snumber.cpp

    r43 r56  
    2525 *  aa      area code (2-digits)
    2626 *  aaa     area code (3-digits)
    27  *
    2827 *  AAA     area code trim zeros
    2928 *
     
    3433const QString SNumber::IsoFormat      = "'+'cc' 'aaa' 'u"; // +41 079 1234567
    3534const QString SNumber::IsoFormatShort = "'+'CC' 'AAA' 'u"; // +41 79 1234567
     35const QString SNumber::GuessFormat    = "%%guess%%";
    3636
    3737SNumber::SNumber() {
    3838    clear();
    3939}
    40 SNumber::SNumber(const QString& numberStr, const QString& format /* = SNumber::IsoFormat */) {
     40SNumber::SNumber(const QString& numberStr, const QString& format) {
    4141    setNumber(numberStr, format);
    4242}
     
    7272
    7373/* CC & AAA are not applicable here! */
    74 bool SNumber::setNumber(const QString& numberStr, const QString& format /* = SNumber::IsoFormat */){
     74bool SNumber::setNumber(const QString& numberStr, const QString& format){
     75    if (format == SNumber::GuessFormat) {
     76        QStringList formats;
     77        formats.append("'+'cc' 'aaa' 'u");// +41 079 1234567
     78        formats.append("'+'cc' 'aa' 'u"); // +41 79 1234567
     79        formats.append("'+'cc' 'a' 'u");  // +41 7 1234567
     80        formats.append("'+'c' 'aaa' 'u"); // +1 079 1234567
     81        formats.append("'+'c' 'aa' 'u");  // +1 79 1234567
     82        formats.append("'+'c' 'a' 'u");   // +1 7 1234567
     83        formats.append("'+'cc' 'aaau");   // +41 0791234567 (Attention! A part of the usernumber could be interpreted as the areacode)
     84        formats.append("'+'cc' 'aau");    // +41 791234567 (Attention! A part of the usernumber could be interpreted as the areacode)
     85        formats.append("'+'cc' 'au");     // +41 71234567 (Attention! A part of the usernumber could be interpreted as the areacode)
     86        formats.append("'+'c' 'aaau");    // +1 0791234567 (Attention! A part of the usernumber could be interpreted as the areacode)
     87        formats.append("'+'c' 'aau");     // +1 791234567 (Attention! A part of the usernumber could be interpreted as the areacode)
     88        formats.append("'+'c' 'au");      // +1 71234567 (Attention! A part of the usernumber could be interpreted as the areacode)
     89
     90        foreach(QString format_, formats) {
     91            if (setNumber(numberStr, format_)) {
     92                return true;
     93            }
     94        }
     95        return false;
     96    }
     97
    7598    clear();
    7699
    77     qDebug() << numberStr;
    78     qDebug() << format;
     100    qDebug() << "Checking " + format + " on " + numberStr;
    79101
    80102    const QLatin1Char quote('\'');
     
    85107    int  j = 0;
    86108    for (int i = 0; i < format.count(); i++) {
     109        if (numberStr.count() <= j) {
     110            clear();
     111            break;
     112        }
     113
    87114        if (format.at(i) == quote) {
    88115            inQuote = !inQuote;
     
    129156            j++;
    130157        } else {
     158            if (format.mid(i, 2) == "CC") {
     159                qWarning() << "CC not supported here!";
     160            } else if (format.mid(i, 3) == "AAA") {
     161                qWarning() << "AAA not supported here!";
     162            }
    131163            clear();
    132164            break;
     
    168200}
    169201
    170 QString SNumber::toString(const QString& format /* = SNumber::IsoFormat */) const {
     202QString SNumber::toString(const QString& format) const {
    171203    if (!isValid()) {
    172204        return "";
     
    219251}
    220252
    221 void SNumber::fromString(const QString& string, const QString& format /* = SNumber::IsoFormat */) {
    222     setNumber(string, format);
     253bool SNumber::readFromString(const QString& string, const QString& format) {
     254    return setNumber(string, format);
     255}
     256SNumber SNumber::fromString(const QString& string, const QString& format) {
     257    return SNumber(string, format);
    223258}
    224259
Note: See TracChangeset for help on using the changeset viewer.