#include "SmsHelper.h" #include #include #include "Sms.h" #include "util.h" #include "SmsPdu.h" namespace SmsHelper { SMS FromRawString(const std::string& input) { std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " std::vector lines = Util::str_split(smsline, "\r\n"); std::vector fields = Util::str_split(lines[0],","); std::string body; for (unsigned i=1; i 0) body += "\r\n"; body += body_line; } } body = Util::str_trim(body); SMS sms; sms.SetIndex( fields[0] ); std::string sender = fields[2]; sender = Util::str_replace(sender, "\""); sms.SetSender(sender); std::string timestamp = fields[4] + std::string(",") + fields[5]; timestamp = Util::str_replace(timestamp, "\""); sms.SetTimestamp(timestamp); sms.SetMessage( body ); return sms; } SMS FromPduString(const std::string& input) { std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " std::vector lines = Util::str_split(smsline, "\r\n"); std::vector fields = Util::str_split(lines[0],","); SMS sms = SmsPdu::ParseSmsPdu(lines[1]); sms.SetIndex(fields[0]); return sms; } }