45 lines
916 B
C
45 lines
916 B
C
#include "match_struct.h"
|
|
|
|
static int _LinearFindFunction(RegexCapture* capture, size_t* find)
|
|
{
|
|
if (capture->number == *find) {
|
|
// Equal
|
|
return 0;
|
|
} else if (capture->number < *find) {
|
|
// Look to the right
|
|
return 1;
|
|
} else {
|
|
// Look to the left
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
bool RegexMatch_HaveNumberedCapture(RegexMatch* match, size_t number)
|
|
{
|
|
if (match == NULL) {
|
|
return false;
|
|
}
|
|
|
|
size_t capture_index = DynamicArray_FindFunctionLinear(
|
|
&match->captures,
|
|
(DynamicArrayLinearFindFunction) _LinearFindFunction,
|
|
&number
|
|
);
|
|
|
|
return capture_index != SIZE_MAX;
|
|
}
|
|
|
|
RegexCapture* RegexMatch_GetNumberedCapture(RegexMatch* match, size_t number)
|
|
{
|
|
if (match == NULL) {
|
|
return false;
|
|
}
|
|
|
|
size_t capture_index = DynamicArray_FindFunctionLinear(
|
|
&match->captures,
|
|
(DynamicArrayLinearFindFunction) _LinearFindFunction,
|
|
&number
|
|
);
|
|
|
|
return DynamicArray_GetPointer(&match->captures, capture_index);
|
|
}
|