#include #include #include #include "Sms.h" #include "util.h" std::string GetSmsCommand(SMS& sms) { unsigned int pos = sms.message.find(" "); if (pos == std::string::npos) return sms.message; else return sms.message.substr(0, pos); } std::string GetSmsData(SMS& sms) { unsigned int pos = sms.message.find(" "); if (pos == std::string::npos) return ""; else { pos++; std::string data = sms.message.substr(pos, sms.message.length()-pos ); while (data.at(0) == ' ') data = data.substr(1, data.length() -1); return data; } } SMS::SMS() { } SMS::SMS(std::string _sender, std::string _message, std::string _timestamp) : sender(_sender), message(_message), timestamp(_timestamp) { } SMS 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; } } while(body.at(0) == ' ') //remove starting space from body body = body.substr( 1, body.length() -1); SMS newsms; newsms.sms_index = fields[0]; newsms.sender = fields[2]; Util::str_clean(&newsms.sender, "\""); newsms.timestamp = fields[4] + std::string(",") + fields[5]; Util::str_clean(&newsms.timestamp, "\""); newsms.message = body; return newsms; }