Changeset f341716 in serd


Ignore:
Timestamp:
Sep 24, 2017, 10:02:59 AM (8 weeks ago)
Author:
David Robillard <d@…>
Branches:
master, serd1
Children:
82b207f
Parents:
f1d036c
git-author:
David Robillard <d@…> (09/24/17 07:36:56)
git-committer:
David Robillard <d@…> (09/24/17 10:02:59)
Message:

Make serdi guess input syntax from extension if unspecified

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • NEWS

    rf1d036c rf341716  
    11serd (0.29.3) unstable;
    22
     3  * Make serdi guess input syntax from extension if unspecified
    34  * Make serdi syntax options case-insensitive
    45  * Add basic error tolerant parsing for line-based formats
     
    910  * Fix building with MSVC
    1011
    11  -- David Robillard <d@drobilla.net>  Sun, 24 Sep 2017 16:34:20 +0200
     12 -- David Robillard <d@drobilla.net>  Sun, 24 Sep 2017 16:36:37 +0200
    1213
    1314serd (0.28.0) stable;
  • src/serdi.c

    rf1d036c rf341716  
    4848    }
    4949    SERDI_ERRORF("unknown syntax `%s'\n", name);
     50    return (SerdSyntax)0;
     51}
     52
     53static SerdSyntax
     54guess_syntax(const char* filename)
     55{
     56    const char* ext = strrchr(filename, '.');
     57    if (ext) {
     58        for (const Syntax* s = syntaxes; s->name; ++s) {
     59            if (!serd_strncasecmp(s->extension, ext, strlen(ext))) {
     60                return s->syntax;
     61            }
     62        }
     63    }
    5064    return (SerdSyntax)0;
    5165}
     
    107121
    108122    FILE*          in_fd         = NULL;
    109     SerdSyntax     input_syntax  = SERD_TURTLE;
    110     SerdSyntax     output_syntax = SERD_NTRIPLES;
     123    SerdSyntax     input_syntax  = (SerdSyntax)0;
     124    SerdSyntax     output_syntax = (SerdSyntax)0;
    111125    bool           from_file     = true;
    112126    bool           bulk_read     = true;
     
    193207    }
    194208
     209    if (!input_syntax && !(input_syntax = guess_syntax((const char*)in_name))) {
     210        input_syntax = SERD_TRIG;
     211    }
     212
     213    if (!output_syntax) {
     214        output_syntax = (
     215            (input_syntax == SERD_TURTLE || input_syntax == SERD_NTRIPLES)
     216            ? SERD_NTRIPLES
     217            : SERD_NQUADS);
     218    }
     219
    195220    SerdURI  base_uri = SERD_URI_NULL;
    196221    SerdNode base     = SERD_NODE_NULL;
Note: See TracChangeset for help on using the changeset viewer.