\r\n

51Degrees Device Detection C/C++  4.4

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...
#define  FIFTYONE_DEGREES_IP_ADDRESS(s)
Macro used to check for NULL before returning the IP address byte array as a const char *. More...

Enumerations

enum  fiftyoneDegreesStringFormat { FIFTYONE_DEGREES_STRING_COORDINATE = 1, FIFTYONE_DEGREES_STRING_IP_ADDRESS }
Enumeration to indicate what format is held in a string item These are the values that can be held at the first byte of the #fiftyoneDegreeString value. 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 (const char *a, const char *b)
Case insensitively compare two strings. More...
char *  fiftyoneDegreesStringSubString (const char *a, const char *b)
Case insensitively searching a first occurrence of a substring. More...

Macro Definition Documentation

◆ FIFTYONE_DEGREES_IP_ADDRESS

#define FIFTYONE_DEGREES_IP_ADDRESS (   s )
Value:
(const char*)(s == NULL \
|| ((fiftyoneDegreesString*)s)->value \
NULL : \
&((fiftyoneDegreesString*)s)->trail.secondValue)
String structure containing its value and size.
Definition: string.h:109
Format is a byte array representation of an IP address.
Definition: string.h:81

Macro used to check for NULL before returning the IP address byte array as a const char *.

Parameters
s - pointer to the fiftyoneDegreesString
Returns
const char * string or NULL. NULL if the pointer is NULL or the type stored at the pointer is not an IP address

◆ 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.

Enumeration Type Documentation

◆ fiftyoneDegreesStringFormat

Enumeration to indicate what format is held in a string item These are the values that can be held at the first byte of the #fiftyoneDegreeString value.

Enumerator

FIFTYONE_DEGREES_STRING_COORDINATE 

Format is a pair of floats for latitude and longitude values.

FIFTYONE_DEGREES_STRING_IP_ADDRESS 

Format is a byte array representation of an IP address.

Function Documentation

◆ fiftyoneDegreesStringCompare()

int fiftyoneDegreesStringCompare ( const char *   a,
const 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

◆ fiftyoneDegreesStringSubString()

char* fiftyoneDegreesStringSubString ( const char *   a,
const char *   b  
)

Case insensitively searching a first occurrence of a substring.

Parameters
a - string to search
b - substring to be searched for
Returns
pointer to the first occurrence or NULL if not found