diff options
author | Dave Beckett <dave@dajobe.org> | 2010-12-29 09:53:42 -0800 |
---|---|---|
committer | Dave Beckett <dave@dajobe.org> | 2010-12-29 09:53:42 -0800 |
commit | cf99fd6f3abf18ffdf7789f22aa4fa10171fbec0 (patch) | |
tree | 97ea80a97b81c1693385f6d687865f56da55c9b9 /src/raptor_syntax_description.c | |
parent | acf3ae04fe1f35d7f30e7cffe1ead3077bc94053 (diff) | |
download | raptor-cf99fd6f3abf18ffdf7789f22aa4fa10171fbec0.tar.gz |
Restore array counts to syntax description. Pull out common validation.
raptor_syntax_description gains names_count, mime_types_count and
uri_strings_count all computed at registration.
(raptor_syntax_description_validate): Added to public API to validate
and compute counts.
(raptor_world_register_parser_factory,
raptor_world_register_serializer_factory): Call above for common
validation checks.
Diffstat (limited to 'src/raptor_syntax_description.c')
-rw-r--r-- | src/raptor_syntax_description.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/raptor_syntax_description.c b/src/raptor_syntax_description.c new file mode 100644 index 00000000..a02a8b59 --- /dev/null +++ b/src/raptor_syntax_description.c @@ -0,0 +1,114 @@ +/* -*- Mode: c; c-basic-offset: 2 -*- + * + * raptor_syntax_description.c - Raptor syntax description API + * + * Copyright (C) 2010, David Beckett http://www.dajobe.org/ + * + * This package is Free Software and part of Redland http://librdf.org/ + * + * It is licensed under the following three licenses as alternatives: + * 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.html or LICENSE.txt at the top of this package for the + * complete terms and further detail along with the license texts for + * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively. + * + * + */ + + +#ifdef HAVE_CONFIG_H +#include <raptor_config.h> +#endif + +#ifdef WIN32 +#include <win32_raptor_config.h> +#endif + + +#include <stdio.h> +#include <string.h> + +/* Raptor includes */ +#include "raptor.h" +#include "raptor_internal.h" + + +static unsigned int +count_strings_array(const char* const * array) +{ + unsigned int i; + + if(!array) + return 0; + + for(i = 0; (array[i]); i++) + ; + + return i; +} + + +static unsigned int +count_mime_types_array(const raptor_type_q* array) +{ + unsigned int i; + + if(!array) + return 0; + + for(i = 0; (array[i].mime_type); i++) + ; + + return i; +} + + +/** + * raptor_syntax_description_validate: + * @desc: description + * + * Validate a syntax description has the required fields (name, labels) and update counts + * + * Returns: non-0 on failure + **/ +int +raptor_syntax_description_validate(raptor_syntax_description* desc) +{ + if(!desc || !desc->names || !desc->names[0] || !desc->label) + return 1; + +#ifdef RAPTOR_DEBUG + /* Maintainer only check of static data */ + if(desc->mime_types) { + unsigned int i; + const raptor_type_q* type_q = NULL; + + for(i = 0; + (type_q = &desc->mime_types[i]) && type_q->mime_type; + i++) { + size_t len = strlen(type_q->mime_type); + if(len != type_q->mime_type_len) { + fprintf(stderr, + "Format %s mime type %s actual len %d static len %d\n", + desc->names[0], type_q->mime_type, + (int)len, (int)type_q->mime_type_len); + } + } + } +#endif + + desc->names_count = count_strings_array(desc->names); + if(!desc->names_count) + return 1; + + desc->mime_types_count = count_mime_types_array(desc->mime_types); + desc->uri_strings_count = count_strings_array(desc->uri_strings); + + return 0; +} |