49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#include "WebServerData.h"
|
|
#include <Ethernet.h>
|
|
#include <Arduino.h>
|
|
|
|
String WebServerData::getValue(const String &data, const String &key)
|
|
{
|
|
return getValue(data, key, '&');
|
|
}
|
|
|
|
/// @brief Separe data PIN1=ON to PIN1 and ON
|
|
/// @param data PIN1=ON
|
|
/// @param key =
|
|
/// @param endchar end of string & or space or any other character
|
|
/// @return
|
|
String WebServerData::getValue(const String &data, const String &key, char endchar)
|
|
{
|
|
int keyIndex = data.indexOf(key);
|
|
if (keyIndex == -1)
|
|
{
|
|
return ""; // return empty string if key is not found
|
|
}
|
|
int separatorIndex = data.indexOf(endchar, keyIndex);
|
|
|
|
String value = data.substring(keyIndex + key.length(), separatorIndex != -1 ? separatorIndex : data.length());
|
|
|
|
return removeAllCharactersAfterEmptySpace(value);
|
|
}
|
|
|
|
String WebServerData::getVariableName(const String &data, const String &key)
|
|
{
|
|
int keyIndex = data.indexOf(key);
|
|
|
|
String value = data.substring(0, keyIndex != -1 ? keyIndex : keyIndex);
|
|
|
|
return removeAllCharactersAfterEmptySpace(value);
|
|
}
|
|
|
|
String WebServerData::removeAllCharactersAfterEmptySpace(String &data)
|
|
{
|
|
int keyIndex = data.indexOf(' ');
|
|
if (keyIndex == -1)
|
|
{
|
|
return data; // return empty string if key is not found
|
|
}
|
|
data.remove(keyIndex);
|
|
data.replace("_", " ");
|
|
return data;
|
|
}
|