51Degrees Device Detection C/C++  4.1

A device detection library that is used natively or by 51Degrees products

String

Detailed Description

String structures containing the string and length.

Introduction

The String structure allows a string and its length to be stored in one structure. This avoids unnecessary calls to strlen. Both the string and its length are allocated in a single operation, so the size of the actual structure (when including the string terminator) is sizeof(fiftyoneDegreesString) + length. This means that the string itself starts at "value" and continues into the rest of the allocated memory.

Get

Getting a const char * from a fiftyoneDegreesString structure can be done by casting a reference to the "value" field:

(const char*)&string->value

However, this can be simplified by using the FIFTYONE_DEGREES_STRING macro which also performs a NULL check on the structure to avoid a segmentation fault.

Compare

This file contains two case insensitive string comparison methods as standards like stricmp vary across compilers.

fiftyoneDegreesStringCompare : compares two strings case insensitively

fiftyoneDegreesStringCompareLength : compares two strings case insensitively up to the length required. Any characters after this point are ignored

Collaboration diagram for String:

Structs

struct  fiftyoneDegreesString
String structure containing its value and size. More...

Macros

#define  FIFTYONE_DEGREES_STRING(s)   (const char*)(s == NULL ? NULL : &((fiftyoneDegreesString*)s)->value)
Macro used to check for NULL before returning the string as a const char *. More...

Functions

void *  fiftyoneDegreesStringRead (const fiftyoneDegreesCollectionFile *file, uint32_t offset, fiftyoneDegreesData *data, fiftyoneDegreesException *exception)
Reads a string from the source file at the offset within the string structure. More...
fiftyoneDegreesString *  fiftyoneDegreesStringGet (fiftyoneDegreesCollection *strings, uint32_t offset, fiftyoneDegreesCollectionItem *item, fiftyoneDegreesException *exception)
Gets the string at the required offset from the collection provided. More...
int  fiftyoneDegreesStringCompareLength (char const *a, char const *b, size_t length)
Case insensitively compare two strings up to the length requested. More...
int  fiftyoneDegreesStringCompare (char *a, char *b)
Case insensitively compare two strings. More...

Macro Definition Documentation

◆ FIFTYONE_DEGREES_STRING

#define FIFTYONE_DEGREES_STRING (   s )    (const char*)(s == NULL ? NULL : &((fiftyoneDegreesString*)s)->value)

Macro used to check for NULL before returning the string as a const char *.

Parameters
s - pointer to the fiftyoneDegreesString
Returns
const char * string or NULL
Examples
Hash/StronglyTyped.c.

Function Documentation

◆ fiftyoneDegreesStringCompare()

int fiftyoneDegreesStringCompare ( char *   a,
char *   b  
)

Case insensitively compare two strings.

Parameters
a - string to compare
b - other string to compare
Returns
0 if same

◆ fiftyoneDegreesStringCompareLength()

int fiftyoneDegreesStringCompareLength ( char const *   a,
char const *   b,
size_t   length  
)

Case insensitively compare two strings up to the length requested.

Parameters
a - string to compare
b - other string to compare
length - of the strings to compare
Returns
0 if same

◆ fiftyoneDegreesStringGet()

fiftyoneDegreesString* fiftyoneDegreesStringGet ( fiftyoneDegreesCollection *   strings,
uint32_t   offset,
fiftyoneDegreesCollectionItem *   item,
fiftyoneDegreesException *   exception  
)

Gets the string at the required offset from the collection provided.

Parameters
strings - collection to get the string from
offset - of the string in the collection
item - to store the string in
exception - pointer to an exception data structure to be used if an exception occurs. See exceptions.h.
Returns
a pointer to string of NULL if the offset is not valid

◆ fiftyoneDegreesStringRead()

void* fiftyoneDegreesStringRead ( const fiftyoneDegreesCollectionFile *   file,
uint32_t   offset,
fiftyoneDegreesData *   data,
fiftyoneDegreesException *   exception  
)

Reads a string from the source file at the offset within the string structure.

Parameters
file - collection to read from
offset - of the string in the collection
data - to store the new string in
exception - pointer to an exception data structure to be used if an exception occurs. See exceptions.h.
Returns
a pointer to the string collection item or NULL if can't be found
On This Page