Volksdata 1.0b7
RDF library
Loading...
Searching...
No Matches
Namespace module
Collaboration diagram for Namespace module:

Data Structures

struct  NSEntry
 Prefix / Namespace pair. More...

Macros

#define PFX_LEN   8
 Namespace prefix length, including terminator.

Typedefs

typedef char VOLK_ns_pfx[PFX_LEN]
 Namespace prefix type.

Functions

VOLK_rc VOLK_nsmap_add (const char *pfx, const char *nsstr)
 Add a prefix -> namespace pair to the map or update it.
VOLK_rc VOLK_nsmap_remove (const char *pfx)
 Remove a prefix -> namespace pair from a map.
const char * VOLK_nsmap_get_ns (const char *pfx)
 Get the namespace for a prefix.
const char * VOLK_nsmap_get_pfx (const char *ns)
 Get the prefix for a namespace.
VOLK_rc VOLK_nsmap_normalize_uri (const char *pfx_uri, char **fq_uri)
 Convert a namespace-prefixed string to a FQ URI sring if mapped.
VOLK_rc VOLK_nsmap_denormalize_uri (const char *fq_uri, char **pfx_uri)
 Convert a FQ URI string to a prefixed string if the prefix is found.
const char *** VOLK_nsmap_dump (void)
 Dump all entries of the namespace map.

Variables

struct hashmap * VOLK_default_nsm
 Default namespace prefix map.

Detailed Description

Macro Definition Documentation

◆ PFX_LEN

#define PFX_LEN   8

Namespace prefix length, including terminator.

Definition at line 16 of file namespace.h.

Typedef Documentation

◆ VOLK_ns_pfx

typedef char VOLK_ns_pfx[PFX_LEN]

Namespace prefix type.

Definition at line 21 of file namespace.h.

Function Documentation

◆ VOLK_nsmap_add()

VOLK_rc VOLK_nsmap_add ( const char * pfx,
const char * nsstr )

Add a prefix -> namespace pair to the map or update it.

If the prefix already exists, it is quietly updated with the new value.

Parameters
[in]pfxThe namespace prefix.
[in]nsstrFully qualified namespace.
Returns
VOLK_OK if the record was added or replaced; VOLK_MEM_ERR if an allocation error occurred.

Definition at line 42 of file namespace.c.

◆ VOLK_nsmap_remove()

VOLK_rc VOLK_nsmap_remove ( const char * pfx)

Remove a prefix -> namespace pair from a map.

Parameters
[in]pfxThe namespace prefix to remove.
Returns
VOLK_OK on successful delete; VOLK_NOACTION if no record was found.

Definition at line 70 of file namespace.c.

◆ VOLK_nsmap_get_ns()

const char * VOLK_nsmap_get_ns ( const char * pfx)

Get the namespace for a prefix.

Parameters
[in]pfxThe prefix to look up.
Returns
A pointer to the namespace string. Note that this is not a copy and should not be modified directly.

Definition at line 85 of file namespace.c.

◆ VOLK_nsmap_get_pfx()

const char * VOLK_nsmap_get_pfx ( const char * ns)

Get the prefix for a namespace.

Parameters
[in]nsThe namespace to look up.
Returns
Found prefix, or NULL if the namespace is not mapped.

Definition at line 96 of file namespace.c.

◆ VOLK_nsmap_normalize_uri()

VOLK_rc VOLK_nsmap_normalize_uri ( const char * pfx_uri,
char ** fq_uri )

Convert a namespace-prefixed string to a FQ URI sring if mapped.

Parameters
[in]pfx_uriURI string to denormalize.
[out]fq_uriString pointer to be filled with the FQ URI. The caller is in charge of freeing the memory. If the namespace is not in the map or an error occurred, this will be NULL. This is to inform the caller that the result is not normalized and a TERM_NS_IRIREF should not be construed with it.
Returns
VOLK_OK on success, VOLK_NORESULT if no entry was found in the map, VOLK_MEM_ERR if a memory allocation error ocurred.

Definition at line 110 of file namespace.c.

◆ VOLK_nsmap_denormalize_uri()

VOLK_rc VOLK_nsmap_denormalize_uri ( const char * fq_uri,
char ** pfx_uri )

Convert a FQ URI string to a prefixed string if the prefix is found.

Todo
Note that this function does not attempt to find the longest or shortest namespace prefix in case of conflicts (e.g. when both http://example.edu/ and http://example.edu/data/ are mapped and http://example.edu/data/51937642 is being denormalized). In such case, the first prefix that is found is assigned.
Parameters
[in]fq_uriURI string to normalize.
[out]pfx_uriString pointer to be filled with the prefixed URI. The caller is in charge of freeing the memory. If the namespace is not in the map or an error occurred, this will be NULL. This is to inform the caller that the result is not denormalized and a TERM_IRIREF should not be construed with it.
Returns
VOLK_OK on success, VOLK_NORESULT if no entry was found in the map, VOLK_MEM_ERR if a memory allocation error ocurred.

Definition at line 153 of file namespace.c.

◆ VOLK_nsmap_dump()

const char *** VOLK_nsmap_dump ( void )

Dump all entries of the namespace map.

Returns
2-dimensional array of strings, with as many rows as namespace entries, and two columns: the first for the namespace prefix, the second for the namespace. The last entry is NULL. Prefix and namespace strings pointed to by the array are owned by the namespace map, but the individual pointers must be freed along with the parent array. E.g.:
const char ***nsm_data = VOLK_nsmap_dump (nsm);
// [...]
for (size_t i = 0; nsm_data[i] != NULL; i++)
    free (nsm_data[i]);
free (nsm_data);

Definition at line 191 of file namespace.c.

Variable Documentation

◆ VOLK_default_nsm

struct hashmap* VOLK_default_nsm
extern

Default namespace prefix map.

This is a singleton. It gets created with VOLK_init() and freed with VOLK_done().

API.

Definition at line 38 of file namespace.c.