RTI Connext Cert C API
Version 2.4.15
|
String creation, cloning, assignment, and deletion. More...
Functions | |
char * | DDS_String_alloc (DDS_UnsignedLong length) |
Create a new empty string that can hold up to length characters. | |
char * | DDS_String_dup (const char *str) |
Clone a string. Creates a new string that duplicates the value of string . | |
int | DDS_String_cmp (const char *s1, const char *s2) |
Compare two strings. | |
int | DDS_String_ncmp (const char *s1, const char *s2, DDS_UnsignedLong num) |
Compare two strings. | |
int | DDS_String_length (const char *string) |
Return the length of a string. | |
int | DDS_Wstring_cmp (const CDR_Wstring *s1, const CDR_Wstring *s2) |
Return the length of a string. |
String creation, cloning, assignment, and deletion.
The functions in this class ensure consistent cross-platform implementations for string creation (DDS_String_alloc()), deletion (DDS_String_free()), and cloning (DDS_String_dup()) that preserve the mutable value type semantics. These are to be viewed as functions that define a string
class whose data is represented by a 'char*'
.
The following conventions govern the memory management of strings in RTI Connext Micro:
string
class functions. The representation of a string in C/C++ unfortunately does not allow programs to detect how much memory has been allocated for a string. RTI Connext Micro must therefore make some assumptions when a user requests that a string be copied into. The following rules apply when RTI Connext Micro is copying into a string or string sequence:
This requirement can generally be assured by adhering to the following idiom for manipulating strings:
char* DDS_String_alloc | ( | DDS_UnsignedLong | length | ) |
Create a new empty string that can hold up to length
characters.
This function will allocate enough memory to hold a string of length
characters, plus one additional byte to hold the NULL terminating character.
length | <<in>> Capacity of the string. |
char* DDS_String_dup | ( | const char * | str | ) |
Clone a string. Creates a new string that duplicates the value of string
.
str | <<in>> The string to duplicate. |
string
== NULL, this function always returns NULL. Otherwise, upon success it returns a newly created string whose value is string
; upon failure it returns NULL. int DDS_String_cmp | ( | const char * | s1, |
const char * | s2 | ||
) |
int DDS_String_ncmp | ( | const char * | s1, |
const char * | s2, | ||
DDS_UnsignedLong | num | ||
) |
Compare two strings.
This function compares two strings for lexicographic equivalence, but only up to num
bytes.
[in] | s1 | <<in>> Left side of comparison |
[in] | s2 | <<in>> Right side of comparison |
[in] | num | Maximum number of bytes to compare |
int DDS_String_length | ( | const char * | string | ) |
Return the length of a string.
string
must be non-NULL string | <<in>> String to return length of |
int DDS_Wstring_cmp | ( | const CDR_Wstring * | s1, |
const CDR_Wstring * | s2 | ||
) |
Return the length of a string.
s1
and s2 can be NULL or non-NULL.