CharBuffer search fixed & Log/Util buffer changed:
- Char/ShiftBuffer: Fixed multi-char string search
- UtilCore: Always pass output buffer & remove own buffer for conversions
- UtilCore: Remove optional parameters to force passing of buffer
- LogCore: Add TempBuffer for output conversion (using UtilCore)
- ApplicationCore: Allow setting size of TempBuffer via config
- Optimize use of {}
This commit is contained in:
100
UtilCore.cpp
100
UtilCore.cpp
@@ -16,27 +16,15 @@
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Variable used to temp values with
|
||||
static char ReturnStr[10000];
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
char * BytesToSafeStr( const char * Bytes, const int Len, const bool NoCrLf, const char SpecChar, char * OutBuf )
|
||||
{
|
||||
char * TempBuf;
|
||||
char * BufPos;
|
||||
|
||||
// Select/create output buffer
|
||||
if (!OutBuf) {
|
||||
TempBuf = ReturnStr;
|
||||
}
|
||||
else {
|
||||
// if (!*OutBuf)
|
||||
// *OutBuf = (char*)malloc( Len+1 );
|
||||
// TempBuf = *OutBuf;
|
||||
TempBuf = OutBuf;
|
||||
}
|
||||
BufPos = TempBuf;
|
||||
// Validate output buffer
|
||||
if (!OutBuf)
|
||||
return NULL;
|
||||
else
|
||||
BufPos = OutBuf;
|
||||
|
||||
// Remove special char
|
||||
for (int i=0; i<Len; i++) {
|
||||
@@ -53,28 +41,21 @@ char * BytesToSafeStr( const char * Bytes, const int Len, const bool NoCrLf, con
|
||||
BufPos++;
|
||||
}
|
||||
*BufPos = 0;
|
||||
return TempBuf;
|
||||
return OutBuf;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
char * BytesToHexStr( const char * Bytes, const int Len, const char * Separator, char * OutBuf )
|
||||
{
|
||||
char * TempBuf;
|
||||
char * BufPos;
|
||||
bool First = true;
|
||||
char SepLen = (Separator)? strlen(Separator) : 0;
|
||||
|
||||
// Select/create output buffer
|
||||
if (!OutBuf) {
|
||||
TempBuf = ReturnStr;
|
||||
}
|
||||
else {
|
||||
// if (!*OutBuf)
|
||||
// *OutBuf = (char*)malloc( Len*(2+SepLen)+1 );
|
||||
// TempBuf = *OutBuf;
|
||||
TempBuf = OutBuf;
|
||||
}
|
||||
BufPos = TempBuf;
|
||||
// Validate output buffer
|
||||
if (!OutBuf)
|
||||
return NULL;
|
||||
else
|
||||
BufPos = OutBuf;
|
||||
|
||||
// Print Hex values of individual bytes
|
||||
for (int i=0; i<Len; i++) {
|
||||
@@ -83,28 +64,21 @@ char * BytesToHexStr( const char * Bytes, const int Len, const char * Separator,
|
||||
First = false;
|
||||
}
|
||||
*BufPos = 0;
|
||||
return TempBuf;
|
||||
return OutBuf;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
char * BytesToBinStr( const char * Bytes, const int Len, const char * Separator, char * OutBuf )
|
||||
{
|
||||
char * TempBuf;
|
||||
char * BufPos;
|
||||
bool First = true;
|
||||
char SepLen = (Separator)? strlen(Separator) : 0;
|
||||
|
||||
// Select/create output buffer
|
||||
if (!OutBuf) {
|
||||
TempBuf = ReturnStr;
|
||||
}
|
||||
else {
|
||||
// if (!*OutBuf)
|
||||
// *OutBuf = (char*)malloc( Len*(8+SepLen)+1 );
|
||||
// TempBuf = *OutBuf;
|
||||
TempBuf = OutBuf;
|
||||
}
|
||||
BufPos = TempBuf;
|
||||
// Validate output buffer
|
||||
if (!OutBuf)
|
||||
return NULL;
|
||||
else
|
||||
BufPos = OutBuf;
|
||||
|
||||
// Print each byte as 8-bit binary
|
||||
for (int i=0; i<Len; i++) {
|
||||
@@ -115,29 +89,22 @@ char * BytesToBinStr( const char * Bytes, const int Len, const char * Separator,
|
||||
First = false;
|
||||
}
|
||||
*BufPos = 0;
|
||||
return TempBuf;
|
||||
return OutBuf;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
char * IntToBinStr( const int Bytes, const int Len, const char * Separator, char * OutBuf )
|
||||
{
|
||||
char * TempBuf;
|
||||
char * BufPos;
|
||||
bool First = true;
|
||||
char SepLen = (Separator)? strlen(Separator) : 0;
|
||||
u_int8_t Byte;
|
||||
|
||||
// Select/create output buffer
|
||||
if (!OutBuf) {
|
||||
TempBuf = ReturnStr;
|
||||
}
|
||||
else {
|
||||
// if (!*OutBuf)
|
||||
// *OutBuf = (char*)malloc( Len*(8+SepLen)+1 );
|
||||
// TempBuf = *OutBuf;
|
||||
TempBuf = OutBuf;
|
||||
}
|
||||
BufPos = TempBuf;
|
||||
// Validate output buffer
|
||||
if (!OutBuf)
|
||||
return NULL;
|
||||
else
|
||||
BufPos = OutBuf;
|
||||
|
||||
// Print each byte as 8-bit binary
|
||||
for (int i=Len-1; i>=0; i--) {
|
||||
@@ -149,28 +116,21 @@ char * IntToBinStr( const int Bytes, const int Len, const char * Separator, char
|
||||
First = false;
|
||||
}
|
||||
*BufPos = 0;
|
||||
return TempBuf;
|
||||
return OutBuf;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
char * HexStrToBytes( const char * Str, const int Len, const char * Separator, char * OutBuf )
|
||||
{
|
||||
char * TempBuf;
|
||||
u_int8_t * BufPos;
|
||||
char * StrPos = (char*)Str;
|
||||
char SepLen = (Separator)? strlen(Separator) : 0;
|
||||
|
||||
// Select/create output buffer
|
||||
if (!OutBuf) {
|
||||
TempBuf = ReturnStr;
|
||||
}
|
||||
else {
|
||||
// if (!*OutBuf)
|
||||
// *OutBuf = (char*)malloc( Len/(2+SepLen)+1 );
|
||||
// TempBuf = *OutBuf;
|
||||
TempBuf = OutBuf;
|
||||
}
|
||||
BufPos = (u_int8_t*)TempBuf;
|
||||
// Validate output buffer
|
||||
if (!OutBuf)
|
||||
return NULL;
|
||||
else
|
||||
BufPos = (u_int8_t*)OutBuf;
|
||||
|
||||
// Print Hex values of individual bytes
|
||||
while ((StrPos - Str < Len) && isxdigit(StrPos[0]) && isxdigit(StrPos[1])) {
|
||||
@@ -185,7 +145,7 @@ char * HexStrToBytes( const char * Str, const int Len, const char * Separator, c
|
||||
}
|
||||
}
|
||||
*BufPos = 0;
|
||||
return TempBuf;
|
||||
return OutBuf;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user