Changeset f15d475 in serd


Ignore:
Timestamp:
07/30/17 01:19:06 (4 weeks ago)
Author:
David Robillard <d@…>
Branches:
master, serd1
Children:
1cd3218
Parents:
c0c776a
Message:

Move parse_utf8_char to shared internal header

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/serd_internal.h

    r0d3f8ec rf15d475  
    357357} 
    358358 
     359/// Return the code point of a UTF-8 character with known length 
     360static inline uint32_t 
     361parse_counted_utf8_char(const uint8_t* utf8, size_t size) 
     362{ 
     363    uint32_t c = utf8[0] & ((1 << (8 - size)) - 1); 
     364    for (size_t i = 1; i < size; ++i) { 
     365        const uint8_t in = utf8[i] & 0x3F; 
     366        c = (c << 6) | in; 
     367    } 
     368    return c; 
     369} 
     370 
     371/// Parse a UTF-8 character, set *size to the length, and return the code point 
     372static inline uint32_t 
     373parse_utf8_char(const uint8_t* utf8, size_t* size) 
     374{ 
     375    switch (*size = utf8_num_bytes(utf8[0])) { 
     376    case 1: case 2: case 3: case 4: 
     377        return parse_counted_utf8_char(utf8, *size); 
     378    default: 
     379        return *size = 0; 
     380    } 
     381} 
     382 
    359383/* URI utilities */ 
    360384 
  • src/writer.c

    r0d3f8ec rf15d475  
    175175} 
    176176 
    177 // Parse a UTF-8 character, set *size to the length, and return the code point 
    178 static inline uint32_t 
    179 parse_utf8_char(SerdWriter* writer, const uint8_t* utf8, size_t* size) 
    180 { 
    181     switch (*size = utf8_num_bytes(utf8[0])) { 
    182     case 1: case 2: case 3: case 4: 
    183         break; 
    184     default: 
    185         return *size = 0; 
    186     } 
    187  
    188     uint32_t c = utf8[0] & ((1 << (8 - *size)) - 1); 
    189     for (size_t i = 1; i < *size; ++i) { 
    190         const uint8_t in = utf8[i] & 0x3F; 
    191         c = (c << 6) | in; 
    192     } 
    193     return c; 
    194 } 
    195  
    196177// Write a single character, as an escape for single byte characters 
    197178// (Caller prints any single byte characters that don't need escaping) 
     
    200181{ 
    201182    char           escape[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 
    202     const uint32_t c          = parse_utf8_char(writer, utf8, size); 
     183    const uint32_t c          = parse_utf8_char(utf8, size); 
    203184    switch (*size) { 
    204185    case 0: 
Note: See TracChangeset for help on using the changeset viewer.