Diffusion C API 6.11.5
Loading...
Searching...
No Matches
utils.h File Reference

Miscellaneous utility functions that don't fit anywhere else. More...

Functions

char * uint32_to_str (uint32_t val)
 Safely convert an unsigned integer to a NULL-terminated string.
 
char * int_to_str (int val)
 Safely convert a signed integer to a NULL-terminated string.
 
char * double_to_str (double val)
 Safely convert a signed double to a NULL-terminated string.
 
uint32_t float_to_uint32 (float f)
 Encode an ieee754 float as a uint32_t (4 bytes).
 
float uint32_to_float (uint32_t i)
 Decode an ieee754 float from a 4-byte unsigned int.
 
char * selector_get_prefix (const char *selector)
 Returns the largest non-regexp part of a topic selector.
 
char * diffusion_escape (const char *string)
 Escapes special characters in a string that is to be used within a topic property or a session filter.
 
SET_Tdiffusion_string_to_roles (const char *string)
 Utility method which converts a string of the format required by the $Roles session property into a mutable set of strings.
 
char * diffusion_roles_to_string (const SET_T *roles)
 Utility method which converts a set of authorisation roles to the string format required by the $Roles session property.
 
bool string_ends_with (const char *string, const char *suffix)
 Determines if str terminates with suffix.
 
bool string_starts_with (const char *string, const char *prefix)
 Determines if str starts with prefix.
 
SET_Thash_to_set (HASH_T *hash, int(*cmp_fn)(const void *, const void *))
 Converts a HASH_T into a SET_T with the same value pointers.
 

Detailed Description

Miscellaneous utility functions that don't fit anywhere else.

Function Documentation

◆ diffusion_escape()

char * diffusion_escape ( const char *  string)

Escapes special characters in a string that is to be used within a topic property or a session filter.

This is a convenience method which inserts an escape character '\' before any of the special characters ' " or .

Parameters
stringthe string to be escaped. If NULL, then NULL will be returned
Returns
the string value with escape characters inserted as appropriate

◆ diffusion_roles_to_string()

char * diffusion_roles_to_string ( const SET_T roles)

Utility method which converts a set of authorisation roles to the string format required by the $Roles session property.

Parameters
rolesA set of roles. If NULL, then NULL will be returned from this function.
Returns
a string representing the supplied roles, formatted as required by the $Roles session property

◆ diffusion_string_to_roles()

SET_T * diffusion_string_to_roles ( const char *  string)

Utility method which converts a string of the format required by the $Roles session property into a mutable set of strings.

Parameters
stringThe string with quoted roles separated by whitespace or commas. If NULL, then NULL will be returned from this function.
Returns
set of roles

◆ double_to_str()

char * double_to_str ( double  val)

Safely convert a signed double to a NULL-terminated string.

The "float" format specifier is used. The caller should free the return value after use.

Parameters
valThe signed double to convert.
Returns
A NULL-terminated string or NULL if the conversion failed.

◆ float_to_uint32()

uint32_t float_to_uint32 ( float  f)

Encode an ieee754 float as a uint32_t (4 bytes).

Parameters
fFloat to encode
Returns
A uint32_t

◆ hash_to_set()

SET_T * hash_to_set ( HASH_T hash,
int(*)(const void *, const void *)  cmp_fn 
)

Converts a HASH_T into a SET_T with the same value pointers.

Parameters
hashthe hash map
cmp_fna function that compares the values of the hash map
Returns
a set containing the values of the hash map

◆ int_to_str()

char * int_to_str ( int  val)

Safely convert a signed integer to a NULL-terminated string.

The caller should free the return value after use.

Parameters
valThe signed integer to convert.
Returns
A NULL-terminated string or NULL if the conversion failed.

◆ selector_get_prefix()

char * selector_get_prefix ( const char *  selector)

Returns the largest non-regexp part of a topic selector.

Parameters
selectorThe topic selector to analyse.
Returns
A pointer to a char array, which should be freed by the caller.

◆ uint32_to_float()

float uint32_to_float ( uint32_t  i)

Decode an ieee754 float from a 4-byte unsigned int.

Parameters
iuint32_t containing IEEE754-encoded data.
Returns
A float

◆ uint32_to_str()

char * uint32_to_str ( uint32_t  val)

Safely convert an unsigned integer to a NULL-terminated string.

The caller should free the return value after use.

Parameters
valThe unsigned integer to convert.
Return values
ANULL-terminated string or NULL if the conversion failed.