Consolidate function RemoveSpace

This commit is contained in:
Theo Arends 2020-10-10 17:00:37 +02:00
parent 89c690c05d
commit 5ec972376c
3 changed files with 14 additions and 13 deletions

View File

@ -359,8 +359,8 @@ char* Unescape(char* buffer, uint32_t* size)
return buffer;
}
char* RemoveSpace(char* p)
{
char* RemoveSpace(char* p) {
// Remove white-space character (' ','\t','\n','\v','\f','\r')
char* write = p;
char* read = p;
char ch = '.';
@ -371,12 +371,11 @@ char* RemoveSpace(char* p)
*write++ = ch;
}
}
// *write = '\0'; // Removed 20190223 as it buffer overflows on no isspace found - no need either
return p;
}
char* RemoveControlCharacter(char* p)
{
char* RemoveControlCharacter(char* p) {
// Remove control character (0x00 .. 0x1F and 0x7F)
char* write = p;
char* read = p;
char ch = '.';
@ -391,8 +390,8 @@ char* RemoveControlCharacter(char* p)
return p;
}
char* ReplaceCommaWithDot(char* p)
{
char* ReplaceCommaWithDot(char* p) {
// Replace character ',' with '.'
char* write = (char*)p;
char* read = (char*)p;
char ch = '.';
@ -458,6 +457,7 @@ char* Trim(char* p)
return p;
}
/*
char* RemoveAllSpaces(char* p)
{
// remove any white space from the base64
@ -474,6 +474,7 @@ char* RemoveAllSpaces(char* p)
}
return p;
}
*/
char* NoAlNumToUnderscore(char* dest, const char* source)
{

View File

@ -1174,7 +1174,7 @@ void CmndTlsKey(void) {
memcpy_P(spi_buffer, tls_spi_start, tls_spi_len);
// remove any white space from the base64
RemoveAllSpaces(XdrvMailbox.data);
RemoveSpace(XdrvMailbox.data);
// allocate buffer for decoded base64
uint32_t bin_len = decode_base64_length((unsigned char*)XdrvMailbox.data);

View File

@ -413,7 +413,7 @@ void ZbSendSend(class JsonParserToken val_cmd, uint16_t device, uint16_t groupad
x = value.getUInt(); // automatic conversion to 0/1
// if (value.is<bool>()) {
// // x = value.as<bool>() ? 1 : 0;
// } else if
// } else if
// } else if (value.is<unsigned int>()) {
// x = value.as<unsigned int>();
} else {
@ -1263,13 +1263,13 @@ bool parseDeviceInnerData(class Z_Device & device, JsonParserObject root) {
// Import generic attributes first
Z_Data & data = device.data.getByType(data_type, endpoint);
// scan through attributes
for (auto attr : data_values) {
JsonParserToken attr_value = attr.getValue();
uint8_t conv_zigbee_type;
Z_Data_Type conv_data_type;
uint8_t conv_map_offset;
uint8_t conv_map_offset;
if (zigbeeFindAttributeByName(attr.getStr(), nullptr, nullptr, nullptr, &conv_zigbee_type, &conv_data_type, &conv_map_offset) != nullptr) {
// found an attribute matching the name, does is fit the type?
if (conv_data_type == data_type) {
@ -1340,7 +1340,7 @@ bool parseDeviceInnerData(class Z_Device & device, JsonParserObject root) {
//
void CmndZbData(void) {
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
RemoveAllSpaces(XdrvMailbox.data);
RemoveSpace(XdrvMailbox.data);
if (XdrvMailbox.data[0] == '{') {
// JSON input, enter saved data into memory -- essentially for debugging
JsonParser parser(XdrvMailbox.data);
@ -1448,7 +1448,7 @@ void CmndZbConfig(void) {
int8_t zb_txradio_dbm = Settings.zb_txradio_dbm;
// if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
RemoveAllSpaces(XdrvMailbox.data);
RemoveSpace(XdrvMailbox.data);
if (strlen(XdrvMailbox.data) > 0) {
JsonParser parser(XdrvMailbox.data);
JsonParserObject root = parser.getRootObject();