Changeset 0d3f8ec in serd


Ignore:
Timestamp:
07/30/17 01:11:47 (4 weeks ago)
Author:
David Robillard <d@…>
Branches:
master, serd1
Children:
c0c776a
Parents:
32f1075
git-author:
David Robillard <d@…> (07/29/17 23:04:58)
git-committer:
David Robillard <d@…> (07/30/17 01:11:47)
Message:

Cleanup: Add push_bytes function to reduce code verbosity

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/reader.c

    r0cd0c73 r0d3f8ec  
    228228 
    229229static inline void 
    230 push_replacement(SerdReader* reader, Ref dest) 
    231 { 
    232     push_byte(reader, dest, 0xEF); 
    233     push_byte(reader, dest, 0xBF); 
    234     push_byte(reader, dest, 0xBD); 
     230push_bytes(SerdReader* reader, Ref ref, const uint8_t* bytes, unsigned len) 
     231{ 
     232    for (unsigned i = 0; i < len; ++i) { 
     233        push_byte(reader, ref, bytes[i]); 
     234    } 
    235235} 
    236236 
     
    324324        r_err(reader, SERD_ERR_BAD_SYNTAX, 
    325325              "unicode character 0x%X out of range\n", code); 
    326         push_replacement(reader, dest); 
     326        push_bytes(reader, dest, replacement_char, 3); 
    327327        *char_code = 0xFFFD; 
    328328        return true; 
     
    349349    } 
    350350 
    351     for (unsigned i = 0; i < size; ++i) { 
    352         push_byte(reader, dest, buf[i]); 
    353     } 
     351    push_bytes(reader, dest, buf, size); 
    354352    *char_code = code; 
    355353    return true; 
     
    396394{ 
    397395    r_err(reader, SERD_ERR_BAD_SYNTAX, fmt, c); 
    398     push_replacement(reader, dest); 
     396    push_bytes(reader, dest, replacement_char, 3); 
    399397 
    400398    // Skip bytes until the next start byte 
     
    415413    } 
    416414 
    417     char bytes[4]; 
     415    uint8_t bytes[4]; 
    418416    bytes[0] = c; 
    419417 
     
    428426 
    429427    // Emit character 
    430     for (unsigned i = 0; i < size; ++i) { 
    431         push_byte(reader, dest, bytes[i]); 
    432     } 
     428    push_bytes(reader, dest, bytes, size); 
    433429    return SERD_SUCCESS; 
    434430} 
  • src/serd_internal.h

    r9c29938 r0d3f8ec  
    3838#    define MIN(a, b) (((a) < (b)) ? (a) : (b)) 
    3939#endif 
     40 
     41static const uint8_t replacement_char[] = { 0xEF, 0xBF, 0xBD }; 
    4042 
    4143/* File and Buffer Utilities */ 
  • src/writer.c

    r6b9074f r0d3f8ec  
    6262    uint8_t     space_after_sep;   ///< Newline after sep if after sep 
    6363} SepRule; 
    64  
    65 static const uint8_t replacement_char[] = { 0xEF, 0xBF, 0xBD }; 
    6664 
    6765static const SepRule rules[] = { 
Note: See TracChangeset for help on using the changeset viewer.