Changeset 56:e63ceb8090cd in SMSSender for lib/libdatatypes/src/snumber.cpp
- Timestamp:
- Feb 2, 2010 9:53:45 AM (13 years ago)
- Branch:
- 3.0
- Convert:
- svn:3639001d-8e34-449c-bb86-3782b86c4877/branches/3.0@55
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/libdatatypes/src/snumber.cpp
r43 r56 25 25 * aa area code (2-digits) 26 26 * aaa area code (3-digits) 27 *28 27 * AAA area code trim zeros 29 28 * … … 34 33 const QString SNumber::IsoFormat = "'+'cc' 'aaa' 'u"; // +41 079 1234567 35 34 const QString SNumber::IsoFormatShort = "'+'CC' 'AAA' 'u"; // +41 79 1234567 35 const QString SNumber::GuessFormat = "%%guess%%"; 36 36 37 37 SNumber::SNumber() { 38 38 clear(); 39 39 } 40 SNumber::SNumber(const QString& numberStr, const QString& format /* = SNumber::IsoFormat */) {40 SNumber::SNumber(const QString& numberStr, const QString& format) { 41 41 setNumber(numberStr, format); 42 42 } … … 72 72 73 73 /* CC & AAA are not applicable here! */ 74 bool SNumber::setNumber(const QString& numberStr, const QString& format /* = SNumber::IsoFormat */){ 74 bool 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 75 98 clear(); 76 99 77 qDebug() << numberStr; 78 qDebug() << format; 100 qDebug() << "Checking " + format + " on " + numberStr; 79 101 80 102 const QLatin1Char quote('\''); … … 85 107 int j = 0; 86 108 for (int i = 0; i < format.count(); i++) { 109 if (numberStr.count() <= j) { 110 clear(); 111 break; 112 } 113 87 114 if (format.at(i) == quote) { 88 115 inQuote = !inQuote; … … 129 156 j++; 130 157 } 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 } 131 163 clear(); 132 164 break; … … 168 200 } 169 201 170 QString SNumber::toString(const QString& format /* = SNumber::IsoFormat */) const {202 QString SNumber::toString(const QString& format) const { 171 203 if (!isValid()) { 172 204 return ""; … … 219 251 } 220 252 221 void SNumber::fromString(const QString& string, const QString& format /* = SNumber::IsoFormat */) { 222 setNumber(string, format); 253 bool SNumber::readFromString(const QString& string, const QString& format) { 254 return setNumber(string, format); 255 } 256 SNumber SNumber::fromString(const QString& string, const QString& format) { 257 return SNumber(string, format); 223 258 } 224 259
Note: See TracChangeset
for help on using the changeset viewer.