From 2b62f6f36ae32a1446dacd20b42af8c63f3afa11 Mon Sep 17 00:00:00 2001 From: Mohammed Noureldin Date: Mon, 11 Apr 2022 12:33:30 +0200 Subject: [PATCH] Add new method to look for a flag in all parameters (#16) * Add new method to look for a flag in all parameters A NULL check is added to avoid crash if parameter is out of range. * Renamce the iteration method to cmdParamExists I find this makes more sense. * Change cmdParamExists description grammar Co-authored-by: Pascal Vizeli --- src/CmdParser.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/CmdParser.hpp b/src/CmdParser.hpp index b2afbd2..5f94543 100644 --- a/src/CmdParser.hpp +++ b/src/CmdParser.hpp @@ -157,6 +157,24 @@ class CmdParser return false; } + /** + * Checks if a parameter/flag exists among all + * other passed command parameters. + * + * @param value String to look for among the parameters + * @return TRUE if found + */ + bool cmdParamExists(CmdParserString value) + { + for (uint16_t i = 1; i < m_paramCount; i++) { + if (equalCmdParam(i, value)) { + return true; + } + } + + return false; + } + #if defined(__AVR__) || defined(ESP8266) /**