Wapcaplet
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
libwapcaplet.c File Reference
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "libwapcaplet/libwapcaplet.h"

Go to the source code of this file.

Classes

struct  lwc_context_s
 

Macros

#define UNUSED(x)   ((x) = (x))
 
#define STR_OF(str)   ((char *)(str + 1))
 
#define CSTR_OF(str)   ((const char *)(str + 1))
 
#define NR_BUCKETS_DEFAULT   (4091)
 
#define LWC_ALLOC(s)   malloc(s)
 
#define LWC_FREE(p)   free(p)
 

Typedefs

typedef struct lwc_context_s lwc_context
 
typedef lwc_hash(* lwc_hasher) (const char *, size_t)
 
typedef int(* lwc_strncmp) (const char *, const char *, size_t)
 
typedef void *(* lwc_memcpy) (void *restrict, const void *restrict, size_t)
 

Functions

lwc_error lwc_intern_string (const char *s, size_t slen, lwc_string **ret)
 
lwc_error lwc_intern_substring (lwc_string *str, size_t ssoffset, size_t sslen, lwc_string **ret)
 
lwc_error lwc_string_tolower (lwc_string *str, lwc_string **ret)
 
void lwc_string_destroy (lwc_string *str)
 
lwc_error lwc__intern_caseless_string (lwc_string *str)
 
void lwc_iterate_strings (lwc_iteration_callback_fn cb, void *pw)
 

Macro Definition Documentation

◆ CSTR_OF

#define CSTR_OF (   str)    ((const char *)(str + 1))

Definition at line 34 of file libwapcaplet.c.

◆ LWC_ALLOC

#define LWC_ALLOC (   s)    malloc(s)

Definition at line 45 of file libwapcaplet.c.

◆ LWC_FREE

#define LWC_FREE (   p)    free(p)

Definition at line 46 of file libwapcaplet.c.

◆ NR_BUCKETS_DEFAULT

#define NR_BUCKETS_DEFAULT   (4091)

Definition at line 36 of file libwapcaplet.c.

◆ STR_OF

#define STR_OF (   str)    ((char *)(str + 1))

Definition at line 33 of file libwapcaplet.c.

◆ UNUSED

#define UNUSED (   x)    ((x) = (x))

Definition at line 16 of file libwapcaplet.c.

Typedef Documentation

◆ lwc_context

typedef struct lwc_context_s lwc_context

◆ lwc_hasher

typedef lwc_hash(* lwc_hasher) (const char *, size_t)

Definition at line 48 of file libwapcaplet.c.

◆ lwc_memcpy

typedef void *(* lwc_memcpy) (void *restrict, const void *restrict, size_t)

Definition at line 50 of file libwapcaplet.c.

◆ lwc_strncmp

typedef int(* lwc_strncmp) (const char *, const char *, size_t)

Definition at line 49 of file libwapcaplet.c.

Function Documentation

◆ lwc__intern_caseless_string()

lwc_error lwc__intern_caseless_string ( lwc_string str)

Intern a caseless copy of the passed string.

Parameters
strThe string to intern the caseless copy of.
Returns
lwc_error_ok if successful, otherwise the error code describing the issue.,
Note
This is for "internal" use by the caseless comparison macro and not for users.

Definition at line 255 of file libwapcaplet.c.

◆ lwc_intern_string()

lwc_error lwc_intern_string ( const char *  s,
size_t  slen,
lwc_string **  ret 
)

Intern a string.

Take a copy of the string data referred to by s and slen and intern it. The resulting lwc_string can be used for simple and caseless comparisons by lwc_string_isequal and lwc_string_caseless_isequal respectively.

Parameters
sPointer to the start of the string to intern.
slenLength of the string in characters. (Not including any terminators)
retPointer to lwc_string pointer to fill out.
Returns
Result of operation, if not OK then the value pointed to by ret will not be valid.
Note
The memory pointed to by s is not referenced by the result.
If the string was already present, its reference count is incremented rather than allocating more memory.
The returned string is currently NULL-terminated but this will not necessarily be the case in future. Try not to rely on it.

Definition at line 143 of file libwapcaplet.c.

◆ lwc_intern_substring()

lwc_error lwc_intern_substring ( lwc_string str,
size_t  ssoffset,
size_t  sslen,
lwc_string **  ret 
)

Intern a substring.

Intern a subsequence of the provided lwc_string.

Parameters
strString to acquire substring from.
ssoffsetSubstring offset into str.
sslenSubstring length.
retPointer to pointer to lwc_string to fill out.
Returns
Result of operation, if not OK then the value pointed to by ret will not be valid.

Definition at line 152 of file libwapcaplet.c.

◆ lwc_iterate_strings()

void lwc_iterate_strings ( lwc_iteration_callback_fn  cb,
void *  pw 
)

Iterate the context and return every string in it.

If there are no strings found in the context, then this has the side effect of removing the global context which will reduce the chances of false-positives on leak checkers.

Parameters
cbThe callback to give the string to.
pwThe private word for the callback.

Definition at line 270 of file libwapcaplet.c.

◆ lwc_string_destroy()

void lwc_string_destroy ( lwc_string str)

Destroy an unreffed lwc_string.

This destroys an lwc_string whose reference count indicates that it should be.

Parameters
strThe string to unref.

Definition at line 187 of file libwapcaplet.c.

◆ lwc_string_tolower()

lwc_error lwc_string_tolower ( lwc_string str,
lwc_string **  ret 
)

Optain a lowercased lwc_string from given lwc_string.

Parameters
strString to create lowercase string from.
retPointer to lwc_string pointer to fill out.
Returns
Result of operation, if not OK then the value pointed to by ret will not be valid.

Definition at line 168 of file libwapcaplet.c.