Changeset c0c776a in serd


Ignore:
Timestamp:
07/30/17 01:11:47 (3 months ago)
Author:
David Robillard <d@…>
Branches:
master, serd1
Children:
f15d475
Parents:
0d3f8ec
git-author:
David Robillard <d@…> (07/30/17 01:11:23)
git-committer:
David Robillard <d@…> (07/30/17 01:11:47)
Message:

Make read_PN_CHARS functions return a status code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/reader.c

    r0d3f8ec rc0c776a  
    602602} 
    603603 
    604 static bool 
     604static SerdStatus 
    605605read_PN_CHARS_BASE(SerdReader* reader, Ref dest) 
    606606{ 
    607607    const uint8_t c = peek_byte(reader); 
    608608    if ((c & 0x80)) {  // Multi-byte character 
    609         return !read_utf8_character(reader, dest, eat_byte_safe(reader, c)); 
    610     } 
    611     if (is_alpha(c)) { 
     609        return read_utf8_character(reader, dest, eat_byte_safe(reader, c)); 
     610    } else if (is_alpha(c)) { 
    612611        push_byte(reader, dest, eat_byte_safe(reader, c)); 
    613         return true; 
    614     } 
    615     return false; 
    616 } 
    617  
    618 static bool 
     612        return SERD_SUCCESS; 
     613    } 
     614    return SERD_FAILURE; 
     615} 
     616 
     617static SerdStatus 
    619618read_PN_CHARS(SerdReader* reader, Ref dest) 
    620619{ 
    621620    const uint8_t c = peek_byte(reader); 
    622621    if ((c & 0x80)) {  // Multi-byte character 
    623         return !read_utf8_character(reader, dest, eat_byte_safe(reader, c)); 
    624     } 
    625  
    626     if (is_alpha(c) || is_digit(c) || c == '_' || c == '-') { 
     622        return read_utf8_character(reader, dest, eat_byte_safe(reader, c)); 
     623    } else if (is_alpha(c) || is_digit(c) || c == '_' || c == '-') { 
    627624        push_byte(reader, dest, eat_byte_safe(reader, c)); 
    628         return true; 
    629     } 
    630     return false; 
     625        return SERD_SUCCESS; 
     626    } 
     627    return SERD_FAILURE; 
    631628} 
    632629 
     
    682679        if ((st = read_PLX(reader, dest)) > SERD_FAILURE) { 
    683680            return st; 
    684         } else if (st != SERD_SUCCESS && !read_PN_CHARS_BASE(reader, dest)) { 
     681        } else if (st != SERD_SUCCESS && read_PN_CHARS_BASE(reader, dest)) { 
    685682            return SERD_FAILURE; 
    686683        } 
     
    692689        } else if ((st = read_PLX(reader, dest)) > SERD_FAILURE) { 
    693690            return st; 
    694         } else if (st != SERD_SUCCESS && !read_PN_CHARS(reader, dest)) { 
     691        } else if (st != SERD_SUCCESS && read_PN_CHARS(reader, dest)) { 
    695692            break; 
    696693        } 
     
    716713        if (c == '.') { 
    717714            push_byte(reader, dest, eat_byte_safe(reader, c)); 
    718         } else if (!read_PN_CHARS(reader, dest)) { 
     715        } else if (read_PN_CHARS(reader, dest)) { 
    719716            break; 
    720717        } 
     
    722719 
    723720    const SerdNode* const n = deref(reader, dest); 
    724     if (n->buf[n->n_bytes - 1] == '.' && !read_PN_CHARS(reader, dest)) { 
     721    if (n->buf[n->n_bytes - 1] == '.' && read_PN_CHARS(reader, dest)) { 
    725722        r_err(reader, SERD_ERR_BAD_SYNTAX, "prefix ends with `.'\n"); 
    726723        return SERD_ERR_BAD_SYNTAX; 
     
    733730read_PN_PREFIX(SerdReader* reader, Ref dest) 
    734731{ 
    735     if (read_PN_CHARS_BASE(reader, dest)) { 
     732    if (!read_PN_CHARS_BASE(reader, dest)) { 
    736733        return read_PN_PREFIX_tail(reader, dest); 
    737734    } 
     
    10271024    if (is_digit(c) || c == '_') { 
    10281025        push_byte(reader, ref, eat_byte_safe(reader, c)); 
    1029     } else if (!read_PN_CHARS(reader, ref)) { 
     1026    } else if (read_PN_CHARS(reader, ref)) { 
    10301027        r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid name start character\n"); 
    10311028        return pop_node(reader, ref); 
     
    10351032        if (c == '.') { 
    10361033            push_byte(reader, ref, eat_byte_safe(reader, c)); 
    1037         } else if (!read_PN_CHARS(reader, ref)) { 
     1034        } else if (read_PN_CHARS(reader, ref)) { 
    10381035            break; 
    10391036        } 
     
    10411038 
    10421039    SerdNode* n = deref(reader, ref); 
    1043     if (n->buf[n->n_bytes - 1] == '.' && !read_PN_CHARS(reader, ref)) { 
     1040    if (n->buf[n->n_bytes - 1] == '.' && read_PN_CHARS(reader, ref)) { 
    10441041        // Ate trailing dot, pop it from stack/node and inform caller 
    10451042        --n->n_bytes; 
     
    12061203        */ 
    12071204        node = deref(reader, o = push_node(reader, SERD_CURIE, "", 0)); 
    1208         while (read_PN_CHARS_BASE(reader, o)) {} 
     1205        while (!read_PN_CHARS_BASE(reader, o)) {} 
    12091206        if ((node->n_bytes == 4 && !memcmp(node->buf, "true", 4)) || 
    12101207            (node->n_bytes == 5 && !memcmp(node->buf, "false", 5))) { 
Note: See TracChangeset for help on using the changeset viewer.