Skip to content

Commit

Permalink
Use std::equal instead of a memcmp.
Browse files Browse the repository at this point in the history
This no longer requires the cstring header.
  • Loading branch information
PG1003 committed Dec 26, 2020
1 parent 5608004 commit 30bbeee
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <cstring>
#include <cassert>

#include <string>
Expand Down Expand Up @@ -163,6 +162,8 @@ struct captures
static constexpr int max_local = 2;
capture< CharT > local[ max_local ];
std::unique_ptr< capture< CharT >[] > alloc;

static_assert( MAXCAPTURES > max_local );
};

struct matchdepth_sentinel
Expand Down Expand Up @@ -243,8 +244,8 @@ struct basic_match_result
iterator operator --( int ) noexcept { const auto tmp = iterator( cap - 1 ); move( -1 ); return tmp; }
iterator & operator +=( int i ) noexcept { move( i ); return *this; }
iterator & operator -=( int i ) noexcept { move( -i ); return *this; }
iterator operator +( int i ) const noexcept { assert( cap); return iterator( cap + i ); }
iterator operator -( int i ) const noexcept { assert( cap); return iterator( cap - i ); }
iterator operator +( int i ) const noexcept { assert( cap ); return iterator( cap + i ); }
iterator operator -( int i ) const noexcept { assert( cap ); return iterator( cap - i ); }
bool operator ==( const iterator &other ) const noexcept { return cap == other.cap; }
bool operator !=( const iterator &other ) const noexcept { return cap != other.cap; }

Expand Down Expand Up @@ -636,9 +637,11 @@ const StrCharT * match_capture( MS &ms, const StrCharT * s, PatCharT c )
throw lex_error( capture_invalid_index );
}

const int len = ms.captures[ i ].len();
const int len = ms.captures[ i ].len();
const StrCharT * c_begin = ms.captures[ i ].init();
const StrCharT * c_end = c_begin + len;
if( ( ms.s_end - s ) >= len &&
memcmp( ms.captures[ i ].init(), s, len * sizeof( c ) ) == 0 )
std::equal( c_begin, c_end, s ) )
{
return s + len;
}
Expand Down

0 comments on commit 30bbeee

Please sign in to comment.