S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
sopc_helper_string.h File Reference
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include "sopc_enums.h"

Go to the source code of this file.

Functions

int SOPC_strncmp_ignore_case (const char *s1, const char *s2, size_t size)
 Compare 2 string in a case-insensitive manner. Comparison returns 0 if size characters were considered identical or s1 and s2 were identical and terminated by a '\0' character.
 
int SOPC_strcmp_ignore_case (const char *s1, const char *s2)
 Compare 2 string in a case-insensitive manner. Comparison returns 0 if all characters are identical.
 
int SOPC_strcmp_ignore_case_alt_end (const char *s1, const char *s2, char endCharacter)
 Compare 2 string in a case-insensitive manner until endCharacter or '\0' character found. Comparison returns 0 if all characters are identical and s1 and s2 end is reached with endCharacter or '\0' character.
 
SOPC_ReturnStatus SOPC_strtouint8_t (const char *sz, uint8_t *n, int base, char cEnd)
 Read a uint8_t from the string with strtoul.
 
SOPC_ReturnStatus SOPC_strtouint16_t (const char *sz, uint16_t *n, int base, char cEnd)
 Read a uint16_t from the string with strtoul.
 
SOPC_ReturnStatus SOPC_strtouint32_t (const char *sz, uint32_t *n, int base, char cEnd)
 Read a uint32_t from the string with strtoul.
 
bool SOPC_strtoint (const char *data, size_t len, uint8_t width, void *dest)
 Read a signed integer from the string with strtoll.
 
bool SOPC_strtouint (const char *data, size_t len, uint8_t width, void *dest)
 Read an unsigned integer from the string with strtoull.
 
bool SOPC_strtodouble (const char *data, size_t len, uint8_t width, void *dest)
 Read a double from the string with strtod.
 
char * SOPC_strdup (const char *s)
 Duplicate the given C string and return copy.
 
SOPC_ReturnStatus SOPC_StrConcat (const char *left, const char *right, char **str)
 Concatenates the two given C strings.
 

Function Documentation

◆ SOPC_strncmp_ignore_case()

int SOPC_strncmp_ignore_case ( const char * s1,
const char * s2,
size_t size )

Compare 2 string in a case-insensitive manner. Comparison returns 0 if size characters were considered identical or s1 and s2 were identical and terminated by a '\0' character.

Parameters
s1A non null string terminated by '\0' character
s2A non null string terminated by '\0' character
sizeMaximum number of characters compared for computing result.
Returns
0 if string are identical in a case-insensitive way, -1 if s1 < s2 and +1 if s1 > s2 (based on first lower case character value comparison). -1000 in case of invalid parameter.

◆ SOPC_strcmp_ignore_case()

int SOPC_strcmp_ignore_case ( const char * s1,
const char * s2 )

Compare 2 string in a case-insensitive manner. Comparison returns 0 if all characters are identical.

Parameters
s1A non null string terminated by '\0' character
s2A non null string terminated by '\0' character
Returns
0 if string are identical in a case-insensitive way, -1 if s1 < s2 and +1 if s1 > s2 (based on first lower case character value comparison). -1000 in case of invalid parameter.

◆ SOPC_strcmp_ignore_case_alt_end()

int SOPC_strcmp_ignore_case_alt_end ( const char * s1,
const char * s2,
char endCharacter )

Compare 2 string in a case-insensitive manner until endCharacter or '\0' character found. Comparison returns 0 if all characters are identical and s1 and s2 end is reached with endCharacter or '\0' character.

Parameters
s1A non null string terminated by '\0' character (and which might contain endCharacter)
s2A non null string terminated by '\0' character (and which might contain endCharacter)
endCharacterAn alternative endCharacter to consider for stopping comparison.
Returns
0 if string are identical in a case-insensitive way, -1 if s1 < s2 and +1 if s1 > s2 (based on first lower case character value comparison). -1000 in case of invalid parameter.

◆ SOPC_strtouint8_t()

SOPC_ReturnStatus SOPC_strtouint8_t ( const char * sz,
uint8_t * n,
int base,
char cEnd )

Read a uint8_t from the string with strtoul.

Parameters
szA pointer to the CString containing the number.
nA pointer to the uint8_t.
baseThe base in which the number is written. See strtoul for more about /p base.
cEndTermination char. The first char of the unconsumed part of sz shall be this. May be '\0'.
Returns
SOPC_STATUS_OK if read was done successfully, in which case *n is modified.

◆ SOPC_strtouint16_t()

SOPC_ReturnStatus SOPC_strtouint16_t ( const char * sz,
uint16_t * n,
int base,
char cEnd )

Read a uint16_t from the string with strtoul.

Parameters
szA pointer to the CString containing the number.
nA pointer to the uint16_t.
baseThe base in which the number is written. See strtoul for more about /p base.
cEndTermination char. The first char of the unconsumed part of sz shall be this. May be '\0'.
Returns
SOPC_STATUS_OK if read was done successfully, in which case *n is modified.

◆ SOPC_strtouint32_t()

SOPC_ReturnStatus SOPC_strtouint32_t ( const char * sz,
uint32_t * n,
int base,
char cEnd )

Read a uint32_t from the string with strtoul.

Parameters
szA pointer to the CString containing the number.
nA pointer to the uint32_t.
baseThe base in which the number is written. See strtoul for more about /p base.
cEndTermination char. The first char of the unconsumed part of sz shall be this. May be '\0'.
Returns
SOPC_STATUS_OK if read was done successfully, in which case *n is modified.

◆ SOPC_strtoint()

bool SOPC_strtoint ( const char * data,
size_t len,
uint8_t width,
void * dest )

Read a signed integer from the string with strtoll.

Parameters
dataA pointer to the CString containing the number in base 10
lenThe length of the CString to use for parsing, it shall be <= 20
widthThe number of bits of the signed integer
destThe destination pointer containing the integer value parsed, it shall be of integer type int<width>_t
Returns
true in case of success false otherwise

◆ SOPC_strtouint()

bool SOPC_strtouint ( const char * data,
size_t len,
uint8_t width,
void * dest )

Read an unsigned integer from the string with strtoull.

Parameters
dataA pointer to the CString containing the number in base 10
lenThe length of the CString to use for parsing, it shall be <= 20
widthThe number of bits of the unsigned integer
destThe destination pointer containing the integer value parsed, it shall be of integer type uint<width>_t
Returns
true in case of success false otherwise

◆ SOPC_strtodouble()

bool SOPC_strtodouble ( const char * data,
size_t len,
uint8_t width,
void * dest )

Read a double from the string with strtod.

Parameters
dataA pointer to the CString containing the double value
lenThe length of the CString to use for parsing, it shall be <= 339
widthThe number of bits of the double
destThe destination pointer containing the integer value parsed, it shall be of type float if width == 32 and double if width == 64
Returns
true in case of success false otherwise

◆ SOPC_strdup()

char * SOPC_strdup ( const char * s)

Duplicate the given C string and return copy.

Parameters
sThe C string to duplicate
Returns
The duplicated C string or NULL in case of copy failure

◆ SOPC_StrConcat()

SOPC_ReturnStatus SOPC_StrConcat ( const char * left,
const char * right,
char ** str )

Concatenates the two given C strings.

Parameters
leftThe C string at the left side.
rightThe C string at the right side.
strThe newly C string = left + right . You should free it with SOPC_Free.
Returns
SOPC_STATUS_OK when successful.