Skip to content

Commit

Permalink
upps
Browse files Browse the repository at this point in the history
  • Loading branch information
pvizeli committed Jun 13, 2016
1 parent de64826 commit 8d387f5
Showing 1 changed file with 30 additions and 39 deletions.
69 changes: 30 additions & 39 deletions src/CmdParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* https://github.com/pvizeli/CmdParser
*/

#ifndef CMDPARSER_H
#define CMDPARSER_H
#ifndef _CMDPARSER_H_
#define _CMDPARSER_H_

#if defined(__AVR__)
#include <avr/pgmspace.h>
Expand All @@ -22,7 +22,9 @@ const uint8_t CMDPARSER_CHAR_DQ = 0x22;
const uint8_t CMDPARSER_CHAR_EQ = 0x3D;
const uint16_t CMDPARSER_ERROR = 0xFFFF;

typedef PGM_P CmdParserString_P;
#if defined(__AVR__) || defined(ESP8266)
typedef PGM_P CmdParserString_P;
#endif
typedef const char *CmdParserString;

/**
Expand Down Expand Up @@ -110,22 +112,6 @@ class CmdParser
return false;
}

/**
* Check if param equal with value case sensitive.
*
* @param idx Number of param to get
* @param value String to compare in PROGMEM
* @return TRUE is equal
*/
bool equalCmdParam_P(uint16_t idx, CmdParserString_P value)
{
if (strcasecmp_P(this->getCmdParam(idx), value) == 0) {
return true;
}

return false;
}

/**
* Check if command equal with value case sensitive.
*
Expand All @@ -138,60 +124,65 @@ class CmdParser
}

/**
* Check if command equal with value case sensitive.
* Check if value equal from key case sensitive.
*
* @param key Key store in SRAM for search in cmd
* @param value String to compare in PROGMEM
* @return TRUE is equal
*/
bool equalValueFromKey(CmdParserString key, CmdParserString value)
{
if (strcasecmp(this->getValueFromKey(key, false), value) == 0) {
return true;
}

return false;
}

#if defined(__AVR__) || defined(ESP8266)

/**
* @see equalCommand
*/
bool equalCommand_P(CmdParserString_P value)
{
return this->equalCmdParam_P(0, value);
}

/**
* Check if value equal from key case sensitive.
*
* @param key Key store in SRAM for search in cmd
* @param value String to compare in PROGMEM
* @return TRUE is equal
* @see equalValueFromKey
*/
bool equalValueFromKey(CmdParserString key, CmdParserString value)
bool equalValueFromKey_P(CmdParserString key, CmdParserString value)
{
if (strcasecmp(this->getValueFromKey(key, false), value) == 0) {
if (strcasecmp_P(this->getValueFromKey(key, true), value) == 0) {
return true;
}

return false;
}

/**
* Check if value equal from key case sensitive.
*
* @param key Key store in PROGMEM for search in cmd
* @param value String to compare in PROGMEM
* @return TRUE is equal
* @see equalCmdParam
*/
bool equalValueFromKey_P(CmdParserString key, CmdParserString value)
bool equalCmdParam_P(uint16_t idx, CmdParserString_P value)
{
if (strcasecmp_P(this->getValueFromKey(key, true), value) == 0) {
if (strcasecmp_P(this->getCmdParam(idx), value) == 0) {
return true;
}

return false;
}

/**
* If KeyValue option is set, search the value from a key pair.
* KEY=Value i.e. KEY is upper case @see setOptCmdUpper.
*
* @param key Key store in PROGMEM for search in cmd
* @return String with value or NULL if not exists
* @see getValueFromKey
*/
char *getValueFromKey_P(CmdParserString_P key)
{
return this->getValueFromKey(key, true);
}

#endif

/**
* Set parser option to ignore " quote for string.
* Default is off
Expand Down

0 comments on commit 8d387f5

Please sign in to comment.