Changeset 7 in libcf++ for trunk/src/bin.cpp


Ignore:
Timestamp:
03/29/15 16:30:07 (9 years ago)
Author:
cheese
Message:

#1 fix and add interfaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bin.cpp

    r4 r7  
    1010
    1111cf::bin::bin(const cf::uint8_t * in,
    12              const cf::size_t size)
     12             const cf::size_t length)
    1313{
    14     set(in, size);
     14    set(in, length);
    1515}
    1616
     
    5555
    5656cf::void_t cf::bin::set(const cf::uint8_t * in,
    57                         const cf::size_t size)
     57                        const cf::size_t length)
    5858{
    5959    if (!in)
    6060        return;
    6161
    62     resize(size);
    63     memcpy(buffer(), in, size);
     62    resize(length);
     63    memcpy(buffer(), in, length);
    6464}
    6565
     
    123123
    124124cf::size_t cf::bin::find(const cf::uint8_t * in,
    125                          const cf::size_t size) const
     125                         const cf::size_t length) const
    126126{
    127     cf::size_t limit = this->size() - size;
     127    cf::size_t limit = size() - length;
    128128
    129129    if (limit < 0 || !in)
    130130        return -1;
    131131
    132     for (cf::size_t iter = 0, iterIn = 0 ; iter <= limit ; iter++)
     132    for (cf::size_t iter = 0 ; iter <= limit ; iter++)
    133133    {
    134         for (iterIn = 0 ; iterIn < size ; iterIn++)
    135         {
    136             if (*((buffer() + iter) + iterIn) != *(in + iterIn))
    137                 break;
    138         }
    139 
    140         if (iterIn == size)
     134        if (!memcmp(buffer() + iter, in, length))
    141135            return iter;
    142136    }
Note: See TracChangeset for help on using the changeset viewer.