AceCommon  1.6.0
Arduino library for low-level common functions and features with no external dependencies
Functions
backslash_x_encoding.h File Reference

Provides 2 functions to perform backslash-x encoding and decoding. More...

#include <stddef.h>
#include <stdint.h>
Include dependency graph for backslash_x_encoding.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

uint8_t ace_common::backslashXEncode (char *t, size_t tcap, const char *s, size_t *written)
 Encode the source 's' to target string 't' with capacity 'tcap'. More...
 
uint8_t ace_common::backslashXDecode (char *t, size_t tcap, const char *s, size_t *written)
 Decode the source 's' to target string 't' with capacity 'tcap'. More...
 
bool ace_common::isHexChar (char c)
 Return true if 'c' is a hex character [0-9a-fA-F].
 

Detailed Description

Provides 2 functions to perform backslash-x encoding and decoding.

Non-printable characters are converted into \xHH form, where HH are hexadecimal digits. A \ is converted into \x5A.

Definition in file backslash_x_encoding.h.

Function Documentation

◆ backslashXDecode()

uint8_t ace_common::backslashXDecode ( char *  t,
size_t  tcap,
const char *  s,
size_t *  written 
)

Decode the source 's' to target string 't' with capacity 'tcap'.

The target 't' is always NUL-terminated. The written parameter will be filled in with the number of actual bytes written. This can be useful for chaining multiple calls into a single buffer.

Parameters
ttarget c-string
tcapcapacity of t
ssource c-string
written(nullable) the number of bytes written to 't'
Returns
return 0 status upon success; 1 if 't' ran out of capacity; 2 if 's' was ill-formed (e.g. the \x was not followed by 2 hex characters

Definition at line 79 of file backslash_x_encoding.cpp.

◆ backslashXEncode()

uint8_t ace_common::backslashXEncode ( char *  t,
size_t  tcap,
const char *  s,
size_t *  written 
)

Encode the source 's' to target string 't' with capacity 'tcap'.

The target 't' is always NUL-terminated. The written parameter will be filled in with the number of actual bytes written. This can be useful for chaining multiple calls into a single buffer.

Parameters
ttarget c-string
tcapcapacity of t
ssource c-string
written(nullable) the number of bytes written to 't'
Returns
0 status if successful, non-zero if error

Definition at line 30 of file backslash_x_encoding.cpp.