IoAbstraction
Functions
TextUtilities.h File Reference

A series of text and numeric utilities useful for many purposes. More...

Go to the source code of this file.

Functions

void appendChar (char *str, char val, int len)
 
void ltoaClrBuff (char *str, long val, uint8_t dp, char padChar, int len)
 
void fastltoa_mv (char *str, long val, long divisor, char padChar, int len)
 
void fastltoa (char *str, long val, uint8_t dp, char padChar, int len)
 
void fastftoa (char *sz, float fl, int dp, int strSize)
 
long dpToDivisor (int dp)
 
long valueToSignificantPlaces (unsigned long value, bool negative)
 
char hexChar (uint8_t val)
 
uint8_t hexValueOf (char val)
 
void intToHexString (char *buffer, size_t bufferSize, unsigned int input, int digits, bool with0x)
 
float tcFltAbs (float f1)
 

Detailed Description

A series of text and numeric utilities useful for many purposes.

Function Documentation

◆ appendChar()

void appendChar ( char *  str,
char  val,
int  len 
)

appends a character at the end of the string, if there is space according to len

◆ ltoaClrBuff()

void ltoaClrBuff ( char *  str,
long  val,
uint8_t  dp,
char  padChar,
int  len 
)

A fast long to ascii function that more feature complete than the standard library. Supports zero padding and maximum number of decimal places. This version always starts at position 0 in the provided buffer and goes up to position len always leaving space for a terminator. The other two versions below support appending instead.

Parameters
strthe buffer to be output to
valthe value to be converted
divisorthe power of 10 largest value (eg 10000, 1000000L etc)
padCharthe character to pad with (or NOT_PADDED which is 0)
lenthe length of the buffer passed in, it will not be exceeded.

◆ fastltoa_mv()

void fastltoa_mv ( char *  str,
long  val,
long  divisor,
char  padChar,
int  len 
)

A fast long to ascii function that more feature complete than the standard library. Supports zero padding and the largest actual value to use normally a power of 10. Absolute largest value displayable is 1000000000 - 1. NOTE that this function will append at the end of the current string. Use ltoaClrBuff to start at position 0. This call will not exceed the length provided and will properly terminate the string.

Parameters
strthe buffer to be appended to
valthe value to be converted
divisorthe power of 10 largest value (eg 10000, 1000000L etc)
padCharthe character to pad with (or NOT_PADDED which is 0)
lenthe length of the buffer passed in, it will not be exceeded.

◆ fastltoa()

void fastltoa ( char *  str,
long  val,
uint8_t  dp,
char  padChar,
int  len 
)

A fast long to ascii function that more feature complete than the standard library. Supports zero padding and the number of decimal places to use. Maximum number of decimal places is 9. NOTE that this function will append at the end of the current string and will not exceed the length provided, it will also properly terminate the string. Use ltoaClrBuff to start at position 0 in the buffer.

Parameters
strthe buffer to be appended to
valthe value to be converted
dpthe number of decimal places allowed
padCharthe character to pad with (or NOT_PADDED which is 0)
lenthe length of the buffer passed in, it will not be exceeded.

◆ fastftoa()

void fastftoa ( char *  sz,
float  fl,
int  dp,
int  strSize 
)

A very simple floating point string function based on the fastltoa above. It can print floating point values up to 9 whole digits and 9 decimal places. Note this function appends the floating point value at the end of the string, to put the value at the beginning, ensure the string is zero length.

Parameters
szthe string to append to,
flthe float to convert
dpthe numer of decimal places (max 9)
strSizethe string maximum length (usually from sizeof)

◆ dpToDivisor()

long dpToDivisor ( int  dp)

converts decimal places into a suitable divisor, eg: 2 -> 100, 4 -> 10000

◆ valueToSignificantPlaces()

long valueToSignificantPlaces ( unsigned long  value,
bool  negative 
)

Indicates how many integers are needed to represent the value and negative flag if provided

Parameters
valuethe value to represent as unsigned.
negativeif the value is negative
Returns
the number of characters including the sign needed

◆ hexChar()

char hexChar ( uint8_t  val)

Get the hex equivalent of a single digit, input must be between 0 and 15

Parameters
valthe input unsigned integer between 0 and 15
Returns
a hex character from 0..F

◆ hexValueOf()

uint8_t hexValueOf ( char  val)

Get the integer representation of a hex digit, between 0..F

Parameters
valthe input character
Returns
the numeric representation.

◆ intToHexString()

void intToHexString ( char *  buffer,
size_t  bufferSize,
unsigned int  input,
int  digits,
bool  with0x 
)

Get the hex string for a number to a given number of fixed places, EG 4 digits. You can optionally include the '0x' at the beginning.

Parameters
bufferthe buffer to copy into
bufferSizethe size of the buffer
inputthe input number
digitsthe number of FIXED digits
with0xif 0x should be included at the beginning

◆ tcFltAbs()

float tcFltAbs ( float  f1)
inline

Ensure that a float is always positive.

Parameters
f1the float that could be positive or negative
Returns
the positive version of the float.