Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of GSM_Library by
Diff: gsmqueue.cpp
- Revision:
- 13:9ac5ff131214
- Parent:
- 10:32d5604accfd
- Child:
- 24:7d2ff444d6d8
--- a/gsmqueue.cpp Fri Mar 06 00:30:41 2015 +0000
+++ b/gsmqueue.cpp Fri Mar 06 01:11:58 2015 +0000
@@ -29,9 +29,9 @@
//Does the character match the begin char?
if (*queueHead == *str){
//Check the remaining characters
- char* sPos = str + 1;
+ char* sPos = str;
char* qPos = 0;
- for (qPos = incrementIndex(queueHead); qPos != QUEUETAIL; qPos = incrementIndex(qPos)){
+ for (qPos = queueHead; qPos != QUEUETAIL; qPos = incrementIndex(qPos)){
//Compare the next char
if (*qPos == *sPos)
{
@@ -95,21 +95,23 @@
//Does not read negative integers; returns -1 if unsuccessful
int parseInt()
{
- char* qPos = queueHead;
+ //Check if queue is empty first
+ if (queueHead == QUEUETAIL) return -1;
+
//Advance to first numeric character
- while (!isNumeric(qPos))
+ while (!isNumeric(queueHead))
{
- qPos = incrementIndex(qPos);
- if (qPos == QUEUETAIL) return -1;
+ queueHead = incrementIndex(queueHead);
+ if (queueHead == QUEUETAIL) return -1;
}
//Continue until first non-numeric character
int val = 0;
- while (qPos != QUEUETAIL && isNumeric(qPos))
+ while (queueHead != QUEUETAIL && isNumeric(queueHead))
{
val *= 10;
- val += (int)(qPos - '0');
- qPos = incrementIndex(qPos);
+ val += (int)(*queueHead - '0');
+ queueHead = incrementIndex(queueHead);
}
return val;
}
@@ -117,7 +119,7 @@
//Returns true if the character is numeric
bool isNumeric(char* qPos)
{
- return ('0' < *qPos && *qPos < '9');
+ return ('0' <= *qPos && *qPos <= '9');
}
//Reset the GSM DMA idle bit to 0

