@@ -293,13 +293,11 @@ std::vector<String> splitStringByLines(const String& input, char delimiter = '\n
293
293
if (endIndex == -1 )
294
294
endIndex = input.length ();
295
295
String line = input.substring (startIndex, endIndex);
296
- if (line.length () > 0 && line != " \r " && line != " \n " && line != " \r\n " ){
297
- // Remove trailing \r if it exists
298
- if (line.endsWith (" \r " )) {
299
- line.remove (line.length () - 1 );
300
- }
301
- lines.push_back (line);
296
+ // Remove trailing \r if it exists
297
+ if (line.endsWith (" \r " )) {
298
+ line.remove (line.length () - 1 );
302
299
}
300
+ lines.push_back (line);
303
301
startIndex = endIndex + 1 ;
304
302
}
305
303
return lines;
@@ -309,19 +307,30 @@ std::vector<String> splitStringByLines(const String& input, char delimiter = '\n
309
307
std::vector<SMS> parseSMSData (const String& data) {
310
308
std::vector<SMS> smsList = std::vector<SMS>();
311
309
std::vector<String> lines = splitStringByLines (data);
312
-
313
- // Remove last line if it's "OK"
314
- if (lines.size () > 0 && lines[lines. size () - 1 ] == " OK " ) {
315
- lines.pop_back ( );
310
+
311
+ // Remove first line if it's empty
312
+ if (lines.size () > 0 && lines[0 ] == " " ) {
313
+ lines.erase (lines. begin () );
316
314
}
317
315
318
- for (int i = 0 ; i < lines.size (); i += 2 ){
316
+ // Remove last 2 lines if second to last line is "OK"
317
+ if (lines.size () >= 2 && lines.back () == " OK" ) {
318
+ lines.erase (lines.end () - 2 , lines.end ());
319
+ }
320
+
321
+ for (int i = 0 ; i < lines.size (); i ++){
319
322
if (lines[i].startsWith (" +CMGL:" )) {
323
+ String entry = lines[i];
320
324
String message = " " ;
321
- if (i + 1 < lines.size ()){
322
- message = lines[i + 1 ];
325
+ // Loop through the lines until the next +CMGL line and extract the message by concatenating the lines
326
+ for (int j = i + 1 ; j < lines.size (); j++) {
327
+ if (lines[j].startsWith (" +CMGL:" )) {
328
+ i = j - 1 ;
329
+ break ;
330
+ }
331
+ message += lines[j] + " \n " ;
323
332
}
324
- SMS sms = parseSMSEntry (lines[i] , message);
333
+ SMS sms = parseSMSEntry (entry , message);
325
334
smsList.push_back (sms);
326
335
}
327
336
}
0 commit comments