// Copyright 2011-2020 David Robillard // SPDX-License-Identifier: ISC #include "string_utils.h" #include "serd/syntax.h" #include #include typedef struct { const char* name; const char* extension; SerdSyntax syntax; } Syntax; static const Syntax syntaxes[] = { {"turtle", ".ttl", SERD_TURTLE}, {"ntriples", ".nt", SERD_NTRIPLES}, {"nquads", ".nq", SERD_NQUADS}, {"trig", ".trig", SERD_TRIG}, {NULL, NULL, (SerdSyntax)0}, }; SerdSyntax serd_syntax_by_name(const char* const name) { const size_t len = strlen(name); if (len) { for (const Syntax* s = syntaxes; s->name; ++s) { if (!serd_strncasecmp(s->name, name, strlen(name))) { return s->syntax; } } } return (SerdSyntax)0; } SerdSyntax serd_guess_syntax(const char* const filename) { const char* ext = strrchr(filename, '.'); if (ext && ext[1]) { const size_t ext_len = strlen(ext); for (const Syntax* s = syntaxes; s->name; ++s) { if (!serd_strncasecmp(s->extension, ext, ext_len)) { return s->syntax; } } } return (SerdSyntax)0; } bool serd_syntax_has_graphs(const SerdSyntax syntax) { return syntax == SERD_NQUADS || syntax == SERD_TRIG; }