mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-17 19:41:36 +08:00
条件判断还存在问题
This commit is contained in:
parent
e86657d807
commit
ce9acda014
92
src/list.c
92
src/list.c
@ -368,6 +368,9 @@ done:
|
||||
{
|
||||
empty = true;
|
||||
}
|
||||
|
||||
if (empty != true)
|
||||
{
|
||||
if (start < 0)
|
||||
{
|
||||
if (start < -self->size(self))
|
||||
@ -420,7 +423,96 @@ done:
|
||||
}
|
||||
else
|
||||
{
|
||||
list = list_new2(self->_obj_size, capacity);
|
||||
if (list == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
list->compare = self->compare;
|
||||
list->print_obj = self->print_obj;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// special case
|
||||
if (start == LIST_UNLIMITED)
|
||||
{
|
||||
start = self->size(self) - 1;
|
||||
}
|
||||
if (end == LIST_UNLIMITED)
|
||||
{
|
||||
end = 0;
|
||||
contain_last_obj = true;
|
||||
}
|
||||
|
||||
// [start_min, end_max] start > end and limit start_min and end_max
|
||||
if (start <= end || end >= self->size(self) || start < -self->size(self))
|
||||
{
|
||||
empty = true;
|
||||
}
|
||||
|
||||
if (empty != true)
|
||||
{
|
||||
if (start < 0)
|
||||
{
|
||||
if (start < -self->size(self))
|
||||
{
|
||||
start = -self->size(self);
|
||||
}
|
||||
start += self->size(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (start > self->size(self))
|
||||
{
|
||||
start = self->size(self) - 1;
|
||||
contain_last_obj = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (end < 0)
|
||||
{
|
||||
end += self->size(self);
|
||||
}
|
||||
|
||||
if (empty != true)
|
||||
{
|
||||
// calc capacity
|
||||
capacity = end - start;
|
||||
}
|
||||
list = list_new2(self->_obj_size, capacity);
|
||||
if (list == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
list->compare = self->compare;
|
||||
list->print_obj = self->print_obj;
|
||||
|
||||
if (contain_last_obj != true)
|
||||
{
|
||||
for (i = start; i > end; i += step)
|
||||
{
|
||||
list->append(list, (char*)self->obj + i * self->_obj_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = start; i >= end; i += step)
|
||||
{
|
||||
list->append(list, (char*)self->obj + i * self->_obj_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list = list_new2(self->_obj_size, capacity);
|
||||
if (list == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
list->compare = self->compare;
|
||||
list->print_obj = self->print_obj;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
|
Loading…
Reference in New Issue
Block a user