httpmessage  0.4.0
HTTP message parsing library
Classes | Macros | Functions
Text utility

Classes

struct  httpmessage_stringview
 Reference to a text buffer. More...
 

Macros

#define HTTPMESSAGE_TEXT_WRITE_FILE(_written, _file, _text, _length)
 Write content to file. More...
 

Functions

httpmessage_stringviewhttpmessage_stringview_new (void)
 Allocate and initialize a new string view. More...
 
HMAPI void httpmessage_stringview_assign (httpmessage_stringview *string, const char *text)
 Assign text to the string view. More...
 
HMAPI void httpmessage_stringview_clear (httpmessage_stringview *string)
 Reset string view. More...
 
HMAPI void httpmessage_stringview_free (httpmessage_stringview **string)
 Free a string view. More...
 
HMAPI int httpmessage_stringview_compare (const httpmessage_stringview *a, const httpmessage_stringview *b)
 Compare two string view. More...
 
HMAPI int httpmessage_stringview_compare_text (const httpmessage_stringview *a, const char *text, size_t length)
 Compare a string view to a text. More...
 
HMAPI int httpmessage_stringview_caseless_compare (const httpmessage_stringview *a, const httpmessage_stringview *b)
 Compare two string view, ignoring case. More...
 
HMAPI int httpmessage_stringview_caseless_compare_text (const httpmessage_stringview *a, const char *text, size_t length)
 Compare a string view to a text, ignoring case. More...
 

Detailed Description

Macro Definition Documentation

◆ HTTPMESSAGE_TEXT_WRITE_FILE

#define HTTPMESSAGE_TEXT_WRITE_FILE (   _written,
  _file,
  _text,
  _length 
)
Value:
{ \
size_t _result = fwrite(_text, (size_t)1, (size_t)_length, _file); \
if ((size_t)_result != (size_t)(_length)) return HTTPMESSAGE_ERROR_WRITE; \
_written += (size_t)_length; \
}
Definition: httpmessage.h:35

Write content to file.

Function Documentation

◆ httpmessage_stringview_assign()

HMAPI void httpmessage_stringview_assign ( httpmessage_stringview string,
const char *  text 
)

Assign text to the string view.

Parameters
stringString view
textText
Examples:
request_write_buffer.c.

◆ httpmessage_stringview_caseless_compare()

HMAPI int httpmessage_stringview_caseless_compare ( const httpmessage_stringview a,
const httpmessage_stringview b 
)

Compare two string view, ignoring case.

Parameters
aFirst string view
bSecond string view
Returns
< 0 if (string < text), 0 if (string == text) and > 0 if (string > text)

◆ httpmessage_stringview_caseless_compare_text()

HMAPI int httpmessage_stringview_caseless_compare_text ( const httpmessage_stringview a,
const char *  text,
size_t  length 
)

Compare a string view to a text, ignoring case.

Parameters
aString view to compare with text
textText
lengthText length
Returns
< 0 if (string < text), 0 if (string == text) and > 0 if (string > text)

◆ httpmessage_stringview_clear()

HMAPI void httpmessage_stringview_clear ( httpmessage_stringview string)

Reset string view.

After this call, the string view will point to a NULL string of length 0.

Parameters
stringString view to reset

◆ httpmessage_stringview_compare()

HMAPI int httpmessage_stringview_compare ( const httpmessage_stringview a,
const httpmessage_stringview b 
)

Compare two string view.

Same behavior as strcmp()

Parameters
aFirst string view
bSecond string view
Returns
< 0 if (a < 0). 0 if (a == b) and > 0 if (a > b)

◆ httpmessage_stringview_compare_text()

HMAPI int httpmessage_stringview_compare_text ( const httpmessage_stringview a,
const char *  text,
size_t  length 
)

Compare a string view to a text.

Parameters
aString view to compare with text
textText
lengthText length
Returns
< 0 if (string < text), 0 if (string == text) and > 0 if (string > text)

◆ httpmessage_stringview_free()

HMAPI void httpmessage_stringview_free ( httpmessage_stringview **  string)

Free a string view.

Release string view memory allocated with httpmessage_stringview_new()` and set the pointer to NULL

Parameters
stringString view to free.

◆ httpmessage_stringview_new()

httpmessage_stringview* httpmessage_stringview_new ( void  )

Allocate and initialize a new string view.

The newly created string view points to a NULL reference of length 0.

Returns
The newly created string view or NULL on error.