Merge branch 'trunk' into str_trim_left

This commit is contained in:
Michael Downey 2021-11-09 19:43:26 -05:00 committed by GitHub
commit 07cd3850d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
62 changed files with 3288 additions and 7733 deletions

View file

@ -888,6 +888,34 @@ pub fn listTakeFirst(
}
}
pub fn listTakeLast(
list: RocList,
alignment: u32,
element_width: usize,
take_count: usize,
dec: Dec,
) callconv(.C) RocList {
if (take_count == 0) {
return RocList.empty();
}
if (list.bytes) |source_ptr| {
const size = list.len();
if (size <= take_count) {
return list;
}
const drop_count = size - take_count;
return listDrop(
list,
alignment,
element_width,
drop_count,
dec,
);
} else {
return RocList.empty();
}
}
pub fn listDrop(
list: RocList,
alignment: u32,
@ -1333,3 +1361,39 @@ inline fn listSetImmutable(
//return list;
return new_bytes;
}
pub fn listFindUnsafe(
list: RocList,
caller: Caller1,
data: Opaque,
inc_n_data: IncN,
data_is_owned: bool,
alignment: u32,
element_width: usize,
inc: Inc,
dec: Dec,
) callconv(.C) extern struct { value: Opaque, found: bool } {
if (list.bytes) |source_ptr| {
const size = list.len();
if (data_is_owned) {
inc_n_data(data, size);
}
var i: usize = 0;
while (i < size) : (i += 1) {
var theOne = false;
const element = source_ptr + (i * element_width);
inc(element);
caller(data, element, @ptrCast(?[*]u8, &theOne));
if (theOne) {
return .{ .value = element, .found = true };
} else {
dec(element);
}
}
return .{ .value = null, .found = false };
} else {
return .{ .value = null, .found = false };
}
}

View file

@ -46,12 +46,14 @@ comptime {
exportListFn(list.listSortWith, "sort_with");
exportListFn(list.listConcat, "concat");
exportListFn(list.listTakeFirst, "take_first");
exportListFn(list.listTakeLast, "take_last");
exportListFn(list.listDrop, "drop");
exportListFn(list.listDropAt, "drop_at");
exportListFn(list.listSet, "set");
exportListFn(list.listSetInPlace, "set_in_place");
exportListFn(list.listSwap, "swap");
exportListFn(list.listAny, "any");
exportListFn(list.listFindUnsafe, "find_unsafe");
}
// Dict Module