[kmobiletools] KDE/kdepim/kmobiletools
Marco Gulino
marco at kmobiletools.org
Sat Jun 23 18:29:03 CEST 2007
SVN commit 679334 by gulino:
Adding parse() method and helpers (required for from7BitString).
M +44 -2 kmobiletools/libkmobiletools/sms.cpp
M +1 -0 tests/testlibkmobiletools/testlibkmobiletools.cpp
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/sms.cpp #679333:679334
@@ -65,6 +65,7 @@
{
if( n.value().isEmpty() ) return n.key().toUtf8();
// adapted from kmime_header_parsing.cpp
+ // Copyright (c) 2001-2002 Marc Mutz <mutz at kde.org>
QByteArray rv;
if ( KMime::isUsAscii( n.value() ) ) {
QByteArray tmp = n.value().toLatin1();
@@ -76,6 +77,22 @@
rv += " <" + n.key().toUtf8() + '>';
return rv;
}
+ bool parsePhoneNumberString(const QString &s)
+ {
+ /// @TODO handle more charset
+ kDebug() << k_funcinfo << "() " << s << endl;
+ QString number, name;
+ QRegExp src;
+ src.setMinimal(true);
+ if(! s.contains('\"') )
+ src.setPattern("(.*)<(.*)>");
+ else src.setPattern("^\"(.*)\"[\\s]*<(.*)>");
+ kDebug() << "Regexp Pattern: " << src.pattern() << endl;
+ if( src.indexIn( s.trimmed() )==-1 ) { kDebug() << " search failed\n"; return false;}
+ numbers[src.cap(2)]=src.cap(1);
+ kDebug() << "adding contact: <<" << src.cap(1).trimmed() << ">> <<" << src.cap(2).trimmed() << ">>\n";
+ return true;
+ }
};
class DestinationPrivate {
public:
@@ -99,8 +116,33 @@
bool Sender::parse(const char *&scursor, const char *const send, bool isCRLF)
{
- kDebug() << k_funcinfo << "() " << scursor << ", " << send << ", " << isCRLF << endl;
- return false;
+/// @TODO handle more charset
+ kDebug() << k_funcinfo << "() " << scursor << ", " << int(send-scursor) << ", " << isCRLF << endl;
+// return false;
+ QStringList singlenums;
+ // strip out type()
+ QString stype=QString("%1: ").arg(type() );
+ if (stype==QString(scursor).left(stype.size() ) )
+ scursor=&scursor[stype.size() ];
+ else return false;
+ bool hadQuotes=false;
+ char *start=(char*) scursor;
+ for( int i=0; i<(send-scursor); i++){
+// kDebug() << "checking char '" << scursor[i] << "' (" << int(scursor[i]) << ")\n";
+ if(scursor[i]=='"' && scursor[i-1]!='\\')
+ hadQuotes=!hadQuotes;
+ if( !hadQuotes && scursor[i]==',' )
+ {
+ singlenums+=QString(start).left(i-(start-scursor));
+ start=(char*) &scursor[i+1];
+ }
+ }
+ singlenums+=QString(const_cast<char*>(start) );
+// kDebug() << "Single nums found: >>>\n" << singlenums.join("|||\n|||") << "|||;" << endl;
+ bool ret=true;
+ for( int i=0; i<singlenums.size(); i++ )
+ ret&=d->parsePhoneNumberString( singlenums.at(i) );
+ return ret;
}
QByteArray Sender::as7BitString(bool withHeaderType) const
--- trunk/KDE/kdepim/kmobiletools/tests/testlibkmobiletools/testlibkmobiletools.cpp #679333:679334
@@ -75,6 +75,7 @@
out << "Added numbers: Sender=" << sms->sender()->as7BitString() << endl;
sms->addDestination("+22123456789", "Destination Name #1");
sms->addDestination("+33345678923", "Destination Name #2 testing some special chars.. #@1\"<>, ");
+ sms->sender()->from7BitString("Sender: Sender Name #1 <+33345678923>, \"Sender 2\" <1234543>, \"Sender 3 with ,commas,\" <224123>, \"Sender 4 with \\\"quotes\\\"\" <1234567>");
out << endl;
sms->assemble();
out << "****************** SMS Serialization ******************\n"
More information about the kmobiletools
mailing list