/* * UtilCore.cpp * * Created on: 14 April 2019 * Author: wentzelc */ // Standard C/C++ Libraries #include #include #include #include // redA Libraries #include "UtilCore.h" //--------------------------------------------------------------------------- // Variable used to temp values with static char ReturnStr[1000]; //--------------------------------------------------------------------------- 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; // Remove special char for (int i=0; i 126)) || (NoCrLf && ((Bytes[i] == '\r') || (Bytes[i] == '\n')))) { *BufPos = SpecChar; } else { *BufPos = Bytes[i]; } BufPos++; } BufPos = 0; return TempBuf; } //--------------------------------------------------------------------------- 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; // Print Hex values of individual bytes for (int i=0; i