diff options
author | Dave Beckett <dave@dajobe.org> | 2011-01-26 21:12:03 -0800 |
---|---|---|
committer | Dave Beckett <dave@dajobe.org> | 2011-01-26 21:12:03 -0800 |
commit | c0e086718280eabd0b956f81ccc84c2951133fa2 (patch) | |
tree | 2d662751bc32338657dab4a86247d0d0fffd22bd /librdfa/rdfa_utils.c | |
parent | 08c38190e04c36c77bb9f6405c81d9725ebeefe5 (diff) | |
download | raptor-c0e086718280eabd0b956f81ccc84c2951133fa2.tar.gz |
Update to librdfa GIT commit aeebd00d68ab7292cae35ebfbcb638f3a2625f39
Diffstat (limited to 'librdfa/rdfa_utils.c')
-rw-r--r-- | librdfa/rdfa_utils.c | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/librdfa/rdfa_utils.c b/librdfa/rdfa_utils.c index 2afd58c1..8f7752e4 100644 --- a/librdfa/rdfa_utils.c +++ b/librdfa/rdfa_utils.c @@ -1,19 +1,19 @@ /* - * Copyright 2008 Digital Bazaar, Inc. + * Copyright 2008-2011 Digital Bazaar, Inc. * * This file is part of librdfa. - * + * * librdfa is Free Software, and can be licensed under any of the * following three licenses: - * - * 1. GNU Lesser General Public License (LGPL) V2.1 or any + * + * 1. GNU Lesser General Public License (LGPL) V2.1 or any * newer version * 2. GNU General Public License (GPL) V2 or any newer version * 3. Apache License, V2.0 or any newer version - * + * * You may not use this file except in compliance with at least one of * the above three licenses. - * + * * See LICENSE-* at the top of this software distribution for more * information regarding the details of each license. * @@ -34,10 +34,10 @@ char* rdfa_join_string(const char* prefix, const char* suffix) size_t prefix_size = strlen(prefix); size_t suffix_size = strlen(suffix); rval = (char*)malloc(prefix_size + suffix_size + 1); - + memcpy(rval, prefix, prefix_size); memcpy(rval+prefix_size, suffix, suffix_size + 1); - + return rval; } @@ -56,19 +56,16 @@ char* rdfa_n_append_string( char* rdfa_replace_string(char* old_string, const char* new_string) { char* rval = NULL; - + if(new_string != NULL) { - // free the memory associated with the old string if it exists. - if(old_string != NULL) - { - free(old_string); - } + // free the memory associated with the old string + free(old_string); // copy the new string rval = strdup(new_string); } - + return rval; } @@ -79,7 +76,7 @@ char* rdfa_canonicalize_string(const char* str) char* token = NULL; char* wptr = NULL; char* offset = rval; - + working_string = rdfa_replace_string(working_string, str); // split on any whitespace character that we may find @@ -91,12 +88,12 @@ char* rdfa_canonicalize_string(const char* str) offset += token_length; *offset++ = ' '; *offset = '\0'; - + token = strtok_r(NULL, RDFA_WHITESPACE_CHARACTERS, &wptr); } if(offset != rval) - { + { offset--; *offset = '\0'; } @@ -125,25 +122,29 @@ rdfalist* rdfa_copy_list(rdfalist* list) // copy the base list variables over rval->max_items = list->max_items; rval->num_items = list->num_items; - rval->items = NULL; - rval->items = (rdfalistitem**)realloc(rval->items, sizeof(void*) * rval->max_items); + rval->items = (rdfalistitem**)malloc(sizeof(void*) * rval->max_items); // copy the data of every list member along with all of the flags // for each list member. - // - // TODO: Implement the copy for context, if it is needed. for(i = 0; i < list->max_items; i++) { - if(i < rval->num_items) + if(i < list->num_items) { + rval->items[i] = (rdfalistitem*)malloc(sizeof(rdfalistitem)); + rval->items[i]->data = NULL; + rval->items[i]->flags = list->items[i]->flags; + + // copy specific data type if(list->items[i]->flags & RDFALIST_FLAG_TEXT) { - rval->items[i] = (rdfalistitem*)malloc(sizeof(rdfalistitem)); - rval->items[i]->data = NULL; - rval->items[i]->data = (char*) - rdfa_replace_string((char*)rval->items[i]->data, (const char*)list->items[i]->data); - rval->items[i]->flags = list->items[i]->flags; + rval->items[i]->data = (char*)rdfa_replace_string( + NULL, (const char*)list->items[i]->data); } + /* + else if(flags & RDFALIST_FLAG_CONTEXT) + { + // TODO: Implement the copy for context, if it is needed. + }*/ } else { @@ -166,7 +167,7 @@ void rdfa_print_list(rdfalist* list) { printf(", "); } - + puts((const char*)list->items[i]->data); } @@ -183,7 +184,7 @@ void rdfa_free_list(rdfalist* list) free(list->items[i]->data); free(list->items[i]); } - + free(list->items); free(list); } @@ -200,10 +201,10 @@ void* rdfa_pop_item(rdfalist* stack) if(stack->num_items > 0) { - rval = stack->items[stack->num_items - 1]->data; - free(stack->items[stack->num_items - 1]); - stack->items[stack->num_items - 1] = NULL; - stack->num_items--; + --stack->num_items; + rval = stack->items[stack->num_items]->data; + free(stack->items[stack->num_items]); + stack->items[stack->num_items] = NULL; } return rval; @@ -221,20 +222,21 @@ void rdfa_add_item(rdfalist* list, void* data, liflag_t flags) } else { - item->data = (char*)rdfa_replace_string((char*)item->data, (const char*)data); - } - + item->data = (char*)rdfa_replace_string( + (char*)item->data, (const char*)data); + } + item->flags = flags; if(list->num_items == list->max_items) { list->max_items = 1 + (list->max_items * 2); - list->items = (rdfalistitem**) - realloc(list->items, sizeof(rdfalistitem) * list->max_items); + list->items = (rdfalistitem**)realloc( + list->items, sizeof(rdfalistitem) * list->max_items); } list->items[list->num_items] = item; - list->num_items++; + ++list->num_items; } #ifndef LIBRDFA_IN_RAPTOR @@ -248,7 +250,7 @@ char** rdfa_create_mapping(size_t elements) { memset(mapping, 0, mapping_size); } - + return mapping; } @@ -261,7 +263,7 @@ char** rdfa_copy_mapping(char** mapping) // initialize the mapping memset(rval, 0, mapping_size); - + // copy each element of the old mapping to the new mapping. while(*mptr != NULL) { @@ -269,7 +271,7 @@ char** rdfa_copy_mapping(char** mapping) rptr++; mptr++; } - + return rval; } @@ -277,7 +279,7 @@ void rdfa_update_mapping(char** mapping, const char* key, const char* value) { int found = 0; char** mptr = mapping; - + // search the current mapping to see if the namespace // prefix exists in the mapping while(*mptr != NULL) @@ -309,7 +311,7 @@ const char* rdfa_get_mapping(char** mapping, const char* key) { const char* rval = NULL; char** mptr = mapping; - + // search the current mapping to see if the key exists in the mapping. while(*mptr != NULL) { @@ -324,7 +326,7 @@ const char* rdfa_get_mapping(char** mapping, const char* key) } mptr++; } - + return rval; } @@ -332,7 +334,7 @@ void rdfa_next_mapping(char** mapping, char** key, char** value) { *key = NULL; *value = NULL; - + if(*mapping != NULL) { *key = *mapping++; |