| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <pj/array.h> |
| 20 |
#include <pj/string.h> |
| 21 |
#include <pj/assert.h> |
| 22 |
#include <pj/errno.h> |
| 23 |
|
| 24 |
PJ_DEF(void) pj_array_insert( void *array, |
| 25 |
unsigned elem_size, |
| 26 |
unsigned count, |
| 27 |
unsigned pos, |
| 28 |
const void *value) |
| 29 |
{ |
| 30 |
if (count && pos < count) { |
| 31 |
pj_memmove( (char*)array + (pos+1)*elem_size, |
| 32 |
(char*)array + pos*elem_size, |
| 33 |
(count-pos)*(pj_size_t)elem_size); |
| 34 |
} |
| 35 |
pj_memmove((char*)array + pos*elem_size, value, elem_size); |
| 36 |
} |
| 37 |
|
| 38 |
PJ_DEF(void) pj_array_erase( void *array, |
| 39 |
unsigned elem_size, |
| 40 |
unsigned count, |
| 41 |
unsigned pos) |
| 42 |
{ |
| 43 |
pj_assert(count != 0); |
| 44 |
if (pos < count-1) { |
| 45 |
pj_memmove( (char*)array + pos*elem_size, |
| 46 |
(char*)array + (pos+1)*elem_size, |
| 47 |
(count-pos-1)*(pj_size_t)elem_size); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
PJ_DEF(pj_status_t) pj_array_find( const void *array, |
| 52 |
unsigned elem_size, |
| 53 |
unsigned count, |
| 54 |
pj_status_t (*matching)(const void *value), |
| 55 |
void **result) |
| 56 |
{ |
| 57 |
unsigned i; |
| 58 |
const char *char_array = (const char*)array; |
| 59 |
for (i=0; i<count; ++i) { |
| 60 |
if ( (*matching)(char_array) == PJ_SUCCESS) { |
| 61 |
if (result) { |
| 62 |
*result = (void*)char_array; |
| 63 |
} |
| 64 |
return PJ_SUCCESS; |
| 65 |
} |
| 66 |
char_array += elem_size; |
| 67 |
} |
| 68 |
return PJ_ENOTFOUND; |
| 69 |
} |
| 70 |
|