Official reference client implementation for Cumulocity SmartREST on u-blox C027.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: util/lex.cpp
- Revision:
- 99:e369fc75c000
- Parent:
- 94:61d44636f020
--- a/util/lex.cpp Mon Apr 27 13:30:21 2015 +0000 +++ b/util/lex.cpp Thu May 07 09:57:55 2015 +0000 @@ -1,6 +1,7 @@ #include <ctype.h> #include <string.h> #include "lex.h" +#include "logging.h" const char* skipHTTPHeader(const char* p) { @@ -100,6 +101,44 @@ return p+j; } +const char* lexConfig(const char* p, Token& tok) +{ + size_t j = 0; + for (; p[j] && !isgraph(p[j]); ++j); + size_t i = j; + tok.p = p+j; + if (p[i] == 0) { + tok.type = Token::NONE; + } else if (p[i] == '=') { + ++i; + tok.type = Token::ASSIGN; + } else if (p[i] == ';') { + ++i; + tok.type = Token::SEMICOLON; + } else if (isalpha(p[i])) { + for (++i; isalnum(p[i]); ++i); + tok.type = Token::STRING; + } else if (isdigit(p[i])) { + for (++i; isdigit(p[i]); ++i); + if (p[i] == '.') { + for (++i; isdigit(p[i]); ++i); + tok.type = Token::FLOAT; + } else if (isalnum(p[i])) { + for (++i; isalnum(p[i]); ++i); + tok.type = Token::STRING; + } else { + tok.type = Token::INT; + } + } else { + aError("lexConfig: %c\n", p[i]); + for (++i; isgraph(p[i]); ++i); + tok.type = Token::ERROR; + } + tok.len = i - j; + for (; p[i] && !isgraph(p[i]); ++i); + return p+i; +} + size_t strncpyEscape(char* dest, const char *source, size_t num) { if (source == NULL) return 0;