Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Enumerations | Functions
ola::strings Namespace Reference

Detailed Description

String helper and formatting functions.

Classes

struct  _ToHex
 

Enumerations

enum  { HEX_BIT_WIDTH = 4 }
 

Functions

string IntToString (int i)
 Convert an int to a string. More...
 
string IntToString (unsigned int i)
 Convert an unsigned int to a string. More...
 
void FormatData (std::ostream *out, const uint8_t *data, unsigned int length, unsigned int indent=0, unsigned int byte_per_line=8)
 Write binary data to an ostream in a human readable form. More...
 
void CopyToFixedLengthBuffer (const std::string &input, char *buffer, unsigned int size)
 Copy a string to a fixed length buffer without NULL terminating. More...
 
template<typename T >
_ToHex< T > ToHex (T v, bool prefix=true)
 Convert a value to a hex string. More...
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const ola::strings::_ToHex< T > &i)
 Output the _ToHex type to an ostream.
 
uint32_t _HexCast (uint8_t v)
 
uint32_t _HexCast (int8_t v)
 
uint16_t _HexCast (uint16_t v)
 
uint16_t _HexCast (int16_t v)
 
uint32_t _HexCast (uint32_t v)
 
uint32_t _HexCast (int32_t v)
 
template<size_t size>
void StrNCopy (char(&output)[size], const char *input)
 A safe version of strncpy that null-terminates the output string. More...
 

Function Documentation

void ola::strings::CopyToFixedLengthBuffer ( const std::string &  input,
char *  buffer,
unsigned int  size 
)

Copy a string to a fixed length buffer without NULL terminating.

Parameters
inputThe string to copy to the buffer.
bufferThe memory location to copy the contents of the string to.
sizeThe size of the memory buffer.
Note
The buffer may not be NULL terminated, it's not safe to use functions like strlen(), printf() etc. on the result. This is typically used in RDM code.
void ola::strings::FormatData ( std::ostream *  out,
const uint8_t *  data,
unsigned int  length,
unsigned int  indent = 0,
unsigned int  byte_per_line = 8 
)

Write binary data to an ostream in a human readable form.

Parameters
outthe ostream to write to
datapointer to the data
lengthlength of the data
indentthe number of spaces to prefix each line with
byte_per_linethe number of bytes to display per line
Note
The data is printed in two columns, hex on the left, ascii on the right. Non ascii values are printed as `.'
std::string ola::strings::IntToString ( int  i)

Convert an int to a string.

Parameters
ithe int to convert
Returns
the string representation of the int
std::string ola::strings::IntToString ( unsigned int  i)

Convert an unsigned int to a string.

Parameters
ithe unsigned int to convert
Returns
The string representation of the unsigned int
template<size_t size>
void ola::strings::StrNCopy ( char(&)  output[size],
const char *  input 
)
inline

A safe version of strncpy that null-terminates the output string.

Parameters
[out]outputThe output array
[in]inputThe input string.
template<typename T >
_ToHex<T> ola::strings::ToHex ( v,
bool  prefix = true 
)

Convert a value to a hex string.

Automatic constructor for _ToHex that deals with widths

Template Parameters
Tthe type of value to convert
Parameters
vthe value to convert
prefixshow the 0x prefix
Returns
A _ToHex struct representing the value, output it to an ostream to use it.
Note
We only currently support unsigned ints due to a lack of requirement for anything else