Changes in boot/generic/src/str.c [002fd5f:a35b458] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • boot/generic/src/str.c

    r002fd5f ra35b458  
    141141        if (*offset + 1 > size)
    142142                return 0;
    143        
     143
    144144        /* First byte read from string */
    145145        uint8_t b0 = (uint8_t) str[(*offset)++];
    146        
     146
    147147        /* Determine code length */
    148        
     148
    149149        unsigned int b0_bits;  /* Data bits in first byte */
    150150        unsigned int cbytes;   /* Number of continuation bytes */
    151        
     151
    152152        if ((b0 & 0x80) == 0) {
    153153                /* 0xxxxxxx (Plain ASCII) */
     
    170170                return U_SPECIAL;
    171171        }
    172        
     172
    173173        if (*offset + cbytes > size)
    174174                return U_SPECIAL;
    175        
     175
    176176        wchar_t ch = b0 & LO_MASK_8(b0_bits);
    177        
     177
    178178        /* Decode continuation bytes */
    179179        while (cbytes > 0) {
    180180                uint8_t b = (uint8_t) str[(*offset)++];
    181                
     181
    182182                /* Must be 10xxxxxx */
    183183                if ((b & 0xc0) != 0x80)
    184184                        return U_SPECIAL;
    185                
     185
    186186                /* Shift data bits to ch */
    187187                ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS));
    188188                cbytes--;
    189189        }
    190        
     190
    191191        return ch;
    192192}
     
    211211        if (*offset >= size)
    212212                return EOVERFLOW;
    213        
     213
    214214        if (!chr_check(ch))
    215215                return EINVAL;
    216        
     216
    217217        /* Unsigned version of ch (bit operations should only be done
    218218           on unsigned types). */
    219219        uint32_t cc = (uint32_t) ch;
    220        
     220
    221221        /* Determine how many continuation bytes are needed */
    222        
     222
    223223        unsigned int b0_bits;  /* Data bits in first byte */
    224224        unsigned int cbytes;   /* Number of continuation bytes */
    225        
     225
    226226        if ((cc & ~LO_MASK_32(7)) == 0) {
    227227                b0_bits = 7;
     
    240240                return EINVAL;
    241241        }
    242        
     242
    243243        /* Check for available space in buffer */
    244244        if (*offset + cbytes >= size)
    245245                return EOVERFLOW;
    246        
     246
    247247        /* Encode continuation bytes */
    248248        unsigned int i;
     
    251251                cc = cc >> CONT_BITS;
    252252        }
    253        
     253
    254254        /* Encode first byte */
    255255        str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1);
    256        
     256
    257257        /* Advance offset */
    258258        *offset += cbytes + 1;
    259        
     259
    260260        return EOK;
    261261}
     
    274274{
    275275        size_t size = 0;
    276        
     276
    277277        while (*str++ != 0)
    278278                size++;
    279        
     279
    280280        return size;
    281281}
     
    298298        size_t len = 0;
    299299        size_t offset = 0;
    300        
     300
    301301        while (len < max_len) {
    302302                if (str_decode(str, &offset, STR_NO_LIMIT) == 0)
    303303                        break;
    304                
     304
    305305                len++;
    306306        }
    307        
     307
    308308        return offset;
    309309}
     
    320320        size_t len = 0;
    321321        size_t offset = 0;
    322        
     322
    323323        while (str_decode(str, &offset, STR_NO_LIMIT) != 0)
    324324                len++;
    325        
     325
    326326        return len;
    327327}
     
    336336        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
    337337                return true;
    338        
     338
    339339        return false;
    340340}
     
    349349        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
    350350                return true;
    351        
     351
    352352        return false;
    353353}
     
    375375        wchar_t c1 = 0;
    376376        wchar_t c2 = 0;
    377        
     377
    378378        size_t off1 = 0;
    379379        size_t off2 = 0;
    380        
     380
    381381        while (true) {
    382382                c1 = str_decode(s1, &off1, STR_NO_LIMIT);
    383383                c2 = str_decode(s2, &off2, STR_NO_LIMIT);
    384                
     384
    385385                if (c1 < c2)
    386386                        return -1;
    387                
     387
    388388                if (c1 > c2)
    389389                        return 1;
    390                
     390
    391391                if ((c1 == 0) || (c2 == 0))
    392392                        break;
    393393        }
    394        
     394
    395395        return 0;
    396396}
     
    412412        size_t src_off = 0;
    413413        size_t dest_off = 0;
    414        
     414
    415415        wchar_t ch;
    416416        while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
     
    418418                        break;
    419419        }
    420        
     420
    421421        dest[dest_off] = '\0';
    422422}
Note: See TracChangeset for help on using the changeset viewer.