This commit is contained in:
@@ -588,7 +588,7 @@ __evstring_findFirst_impl(
|
||||
.offset = ~0ull
|
||||
};
|
||||
|
||||
if(query.len == 0)
|
||||
if(query.len == 0 || query.len > text.len)
|
||||
return result;
|
||||
|
||||
for(u64 l = text.offset; l <= text.offset + text.len - query.len; l++)
|
||||
@@ -731,18 +731,25 @@ evstring_findAll(
|
||||
if(text_len == 0 || query_len == 0 || query_len > text_len) {
|
||||
return 0;
|
||||
}
|
||||
bool check_run = (results == NULL);
|
||||
|
||||
evstring_view query_view = evstring_slice(query, 0, -1);
|
||||
|
||||
u64 count = 0;
|
||||
for(evstring_view v = evstring_findFirst(text, query);
|
||||
v.len != 0;
|
||||
v = __evstring_findFirst_impl(
|
||||
evstring_slice(text, v.offset + v.len, -1),
|
||||
evstring_slice(query, 0, -1))) {
|
||||
if(!check_run) {
|
||||
results[count] = v;
|
||||
|
||||
for(u64 l = 0; l <= text_len - query_len; l++)
|
||||
{
|
||||
evstring_view curr_view = {
|
||||
.data = text,
|
||||
.len = query_len,
|
||||
.offset = l
|
||||
};
|
||||
if(EV_EQUAL(evstring_view)(&curr_view, &query_view))
|
||||
{
|
||||
if(results) results[count] = curr_view;
|
||||
count++;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring text = evstr("Hello, this is me saying `Hello` like someone who says 'Hello'");
|
||||
|
||||
assert(evstring_findAll(text, evstr("Hello"), NULL) == 3);
|
||||
assert(evstring_findAll(evstr("abc"), evstr("abc"), NULL) == 1);
|
||||
assert(evstring_findAll(evstr("abcx"), evstr("abc"), NULL) == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring_view search_results[1];
|
||||
evstring text = evstr("abc");
|
||||
evstring query = evstr("abc");
|
||||
|
||||
assert(evstring_findAll(text, query, search_results) == 1);
|
||||
assert(search_results[0].data == text);
|
||||
assert(search_results[0].len == 3);
|
||||
assert(search_results[0].offset == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring_view search_results[1];
|
||||
evstring text = evstr("Hello, this is me saying `Hello` like someone who says 'Hello'");
|
||||
|
||||
assert(evstring_findAll(text, evstr(""), search_results) == 0);
|
||||
assert(evstring_findAll(text, evstr("Goodbye"), search_results) == 0);
|
||||
assert(evstring_findAll(evstr("ab"), evstr("abc"), search_results) == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring_view search_results[2];
|
||||
evstring text = evstr("aaa");
|
||||
evstring query = evstr("aa");
|
||||
|
||||
assert(evstring_findAll(text, query, search_results) == 2);
|
||||
|
||||
assert(search_results[0].data == text);
|
||||
assert(search_results[0].len == 2);
|
||||
assert(search_results[0].offset == 0);
|
||||
|
||||
assert(search_results[1].data == text);
|
||||
assert(search_results[1].len == 2);
|
||||
assert(search_results[1].offset == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring_view search_results[1];
|
||||
evstring text = evstr("abcx");
|
||||
evstring query = evstr("abc");
|
||||
|
||||
assert(evstring_findAll(text, query, search_results) == 1);
|
||||
assert(search_results[0].data == text);
|
||||
assert(search_results[0].len == 3);
|
||||
assert(search_results[0].offset == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring text = evstr("");
|
||||
evstring query = evstr("a");
|
||||
|
||||
evstring_view match = evstring_findFirst(text, query);
|
||||
|
||||
assert(match.len == 0);
|
||||
assert(match.offset == ~0ull);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring text = evstr("ab");
|
||||
evstring query = evstr("abc");
|
||||
|
||||
evstring_view match = evstring_findFirst(text, query);
|
||||
|
||||
assert(match.len == 0);
|
||||
assert(match.offset == ~0ull);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -5,12 +5,20 @@ tests = [
|
||||
'new_format',
|
||||
'replace_first',
|
||||
'find_all',
|
||||
'find_all_exact_match',
|
||||
'find_all_short_suffix',
|
||||
'find_all_count_only',
|
||||
'find_all_no_matches',
|
||||
'find_all_overlapping',
|
||||
'push_fmt_float',
|
||||
'find_first_mismatch',
|
||||
'find_first_overlapping_prefix',
|
||||
'stack_get_space',
|
||||
'overlapping_push',
|
||||
'find_first_empty_query',
|
||||
'find_first_query_too_long',
|
||||
'find_first_empty_text',
|
||||
'replace_first_query_too_long',
|
||||
]
|
||||
|
||||
foreach t : tests
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring text = evstr("ab");
|
||||
evstring replacement = evstr("x");
|
||||
evstring query = evstr("abc");
|
||||
|
||||
evstring result = evstring_replaceFirst(text, query, replacement);
|
||||
|
||||
assert(EV_EQUAL(evstring)(&result, &text));
|
||||
|
||||
evstring_free(result);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user