Compare commits
7 Commits
ea9d45625d
...
c38e5784e9
| Author | SHA1 | Date | |
|---|---|---|---|
| c38e5784e9 | |||
| 7663c76329 | |||
| 76a5bf0afa | |||
| 701a3807b6 | |||
| b5b2df24aa | |||
| b845e72902 | |||
| dcd1beae8a |
@@ -67,18 +67,18 @@
|
||||
# if defined(_MSC_VER)
|
||||
# undef EV_CC_MSVC
|
||||
# define EV_CC_MSVC 1
|
||||
# elif defined(__GNUC__)
|
||||
# undef EV_CC_GCC
|
||||
# define EV_CC_GCC 1
|
||||
# elif defined(__clang)
|
||||
# undef EV_CC_CLANG
|
||||
# define EV_CC_CLANG 1
|
||||
# elif defined(__GNUC__)
|
||||
# undef EV_CC_GCC
|
||||
# define EV_CC_GCC 1
|
||||
# else
|
||||
# error EV_CC_UNKNOWN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(EV_BUILDTYPE_DEBUG) && !defined(EV_BUILDTYPE_DEBUG_OPT) && !defined(EV_BUILDTYPE_RELEASE)
|
||||
#if !defined(EV_BUILDTYPE_DEBUG) && !defined(EV_BUILDTYPE_DEBUGOPT) && !defined(EV_BUILDTYPE_RELEASE)
|
||||
#define EV_BUILDTYPE_RELEASE 1
|
||||
#endif
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ evstring_readFile(
|
||||
if(fopen_s(&f,filePath,"rb")) return EV_INVALID(evstring);
|
||||
#else
|
||||
f = fopen(filePath, "rb");
|
||||
if(f == NULL) return EV_INVALID(evstring);
|
||||
#endif
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
||||
@@ -152,7 +152,7 @@ i32 ev_log_add_callback(ev_log_log_fn fn, void* udata, ev_log_level level)
|
||||
}
|
||||
|
||||
|
||||
i32 log_add_fp(FILE *fp, ev_log_level level)
|
||||
i32 ev_log_add_fp(FILE *fp, ev_log_level level)
|
||||
{
|
||||
return ev_log_add_callback(ev_log_file_callback, fp, level);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ evstring_slice(
|
||||
i64 begin,
|
||||
i64 end);
|
||||
|
||||
EV_STR_API i32
|
||||
EV_STR_API evstring_error_t
|
||||
evstring_pushView(
|
||||
evstring *s,
|
||||
evstring_view ref);
|
||||
@@ -330,7 +330,7 @@ evstring_free(
|
||||
{
|
||||
evstr_asserttype(s);
|
||||
if(META(s)->allocationType == EV_STR_ALLOCATION_TYPE_HEAP) {
|
||||
free(META(s));
|
||||
ev_str_free(META(s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,6 +402,7 @@ evstring_setLength(
|
||||
meta = META(*s);
|
||||
}
|
||||
meta->length = newlen;
|
||||
(*s)[newlen] = 0;
|
||||
|
||||
return EV_STR_ERR_NONE;
|
||||
}
|
||||
@@ -498,10 +499,13 @@ evstring_slice(
|
||||
u64 wrapped_begin = begin < 0 ? string_len + 1 + begin : begin;
|
||||
u64 wrapped_end = end < 0 ? string_len + 1 + end : end;
|
||||
|
||||
// In this case, the assertions don't matter
|
||||
if(wrapped_begin != wrapped_end)
|
||||
{
|
||||
assert(wrapped_begin >= 0 && wrapped_begin < string_len);
|
||||
assert(wrapped_end > 0 && wrapped_end <= string_len);
|
||||
|
||||
assert(wrapped_begin < wrapped_end);
|
||||
}
|
||||
|
||||
return (evstring_view) {
|
||||
.data = s,
|
||||
@@ -542,9 +546,10 @@ __evstring_findFirst_impl(
|
||||
};
|
||||
|
||||
for(u64 i = text.offset; i < text.offset + text.len; i++) {
|
||||
if(text.data[i] == query.data[query.offset + found_progress]) {
|
||||
if(text.data[i] == query.data[query.offset + found_progress])
|
||||
found_progress++;
|
||||
}
|
||||
else
|
||||
found_progress = 0;
|
||||
if(found_progress == query.len) {
|
||||
result.offset = (i+1) - query.len;
|
||||
result.len = query.len;
|
||||
@@ -688,8 +693,9 @@ evstring_findAll(
|
||||
evstring_slice(text, v.offset + v.len, -1),
|
||||
evstring_slice(query, 0, -1))) {
|
||||
if(!check_run) {
|
||||
results[count++] = v;
|
||||
results[count] = v;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ typedef void *ev_svec_t;
|
||||
|
||||
typedef enum {
|
||||
EV_VEC_ERR_NONE = 0,
|
||||
EV_VEC_ERR_OOM = 1
|
||||
EV_VEC_ERR_OOM = -1,
|
||||
EV_VEC_ERR_INVALID_OP = -2
|
||||
} ev_vec_error_t;
|
||||
TYPEDATA_GEN(ev_vec_error_t, DEFAULT(EV_VEC_ERR_NONE));
|
||||
|
||||
@@ -252,7 +253,7 @@ ev_vec_fini(
|
||||
* vector
|
||||
*
|
||||
* \returns The index of the element that was just pushed. If the operation
|
||||
* failed, a non-zero (vec_error_t) value is returned.
|
||||
* failed, a less-than-zero (vec_error_t) value is returned.
|
||||
*/
|
||||
EV_VEC_API int
|
||||
ev_vec_push_impl(
|
||||
@@ -640,6 +641,8 @@ ev_vec_pop(
|
||||
ev_vec_t* v = (ev_vec_t*)vec_p;
|
||||
__ev_vec_getmeta(*v)
|
||||
|
||||
if(metadata->length == 0) return EV_VEC_ERR_INVALID_OP;
|
||||
|
||||
if(out != NULL) {
|
||||
void *src = ((char *)*v) + ((metadata->length-1) * metadata->typeData.size);
|
||||
if (metadata->typeData.copy_fn) {
|
||||
|
||||
@@ -43,6 +43,8 @@ headers_dep = declare_dependency(
|
||||
# Tests
|
||||
str_test = executable('str_test', 'str_test.c', dependencies: [str_dep], c_args: evh_c_args)
|
||||
test('evstr', str_test)
|
||||
vec_test = executable('vec_test', 'vec_test.c', dependencies: [vec_dep], c_args: evh_c_args)
|
||||
test('evvec', vec_test)
|
||||
log_test = executable('log_test', 'log_test.c', dependencies: [log_dep], c_args: evh_c_args)
|
||||
test('evlog', log_test)
|
||||
|
||||
|
||||
+25
@@ -77,5 +77,30 @@ int main()
|
||||
evstring_free(heap_str);
|
||||
}
|
||||
|
||||
{ // Incorrectly handled mismatches
|
||||
evstring text = evstr("aab");
|
||||
evstring query = evstr("ab");
|
||||
evstring_view match = evstring_findFirst(text, query);
|
||||
assert(match.len == 2);
|
||||
assert(match.offset == 1);
|
||||
}
|
||||
|
||||
{ // Underflowing getSpace for stack strings
|
||||
evstring stack_str = evstr("abc");
|
||||
assert(evstring_getSpace(stack_str) == 0);
|
||||
}
|
||||
|
||||
{ // Overlapping push
|
||||
evstring s = evstring_newFromStr("abc");
|
||||
assert(s != NULL);
|
||||
|
||||
evstring_error_t err = evstring_pushStr(&s, s);
|
||||
assert(err == EV_STR_ERR_NONE);
|
||||
assert(strcmp(s, "abcabc") == 0);
|
||||
|
||||
evstring_free(s);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#define EV_VEC_IMPLEMENTATION
|
||||
#include "ev_vec.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
{
|
||||
ev_vec(i32) v = ev_vec_init(i32);
|
||||
assert(v != NULL);
|
||||
|
||||
for(i32 i = 0; i < 5; i++) {
|
||||
assert(ev_vec_push_impl(&v, &i) >= 0);
|
||||
}
|
||||
|
||||
ev_vec_error_t err = ev_vec_setcapacity(&v, 2);
|
||||
assert(err != EV_VEC_ERR_NONE || ev_vec_len(&v) <= ev_vec_capacity(&v));
|
||||
|
||||
ev_vec_fini(&v);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user