diff --git a/sonoff/support.ino b/sonoff/support.ino index 035a1d31d..b9fec8651 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -124,6 +124,18 @@ size_t strcspn(const char *str1, const char *str2) return ret; } +// https://clc-wiki.net/wiki/C_standard_library:string.h:strpbrk +// Locate the first occurrence in the string pointed to by s1 of any character from the string pointed to by s2 +char* strpbrk(const char *s1, const char *s2) +{ + while(*s1) { + if (strchr(s2, *s1++)) { + return (char*)--s1; + } + } + return 0; +} + // https://opensource.apple.com/source/Libc/Libc-583/stdlib/FreeBSD/strtoull.c // Convert a string to an unsigned long long integer #ifndef __LONG_LONG_MAX__ diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index d46900e5a..26bdbcb86 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -887,7 +887,7 @@ char * findClosureBracket(char * pStart) if (bFindClosures) { return pointer; } else { - return NULL; + return nullptr; } } @@ -1015,7 +1015,7 @@ bool findNextObjectValue(char * &pointer, float &value) break; } else if (*pointer == '(') { //It is a sub expression bracketed with () char * closureBracket = findClosureBracket(pointer); //Get the position of closure bracket ")" - if (closureBracket != NULL) { + if (closureBracket != nullptr) { value = evaluateExpression(pointer+1, closureBracket - pointer - 2); pointer = closureBracket + 1; bSucceed = true; @@ -1310,7 +1310,7 @@ bool findNextLogicObjectValue(char * &pointer, bool &value) break; } else if (*pointer == '(') { //It is a sub expression bracketed with () char * closureBracket = findClosureBracket(pointer); //Get the position of closure bracket ")" - if (closureBracket != NULL) { + if (closureBracket != nullptr) { value = evaluateLogicalExpression(pointer+1, closureBracket - pointer - 2); pointer = closureBracket + 1; bSucceed = true; @@ -1555,7 +1555,7 @@ void ProcessIfStatement(const char* statements) while (*pos && *pos != '(') { pos++; } - if (NULL == *pos) break; + if (0 == *pos) { break; } char * posEnd = findClosureBracket(pos); if (true == evaluateLogicalExpression(pos + 1, posEnd - (pos + 1))) {