mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
wasm: Implement Str.split
This commit is contained in:
parent
d2dbb0001a
commit
02ec30425c
7 changed files with 267 additions and 259 deletions
|
@ -143,6 +143,7 @@ const str = @import("str.zig");
|
|||
comptime {
|
||||
exportStrFn(str.init, "init");
|
||||
exportStrFn(str.strToScalarsC, "to_scalars");
|
||||
exportStrFn(str.strSplit, "str_split");
|
||||
exportStrFn(str.strSplitInPlaceC, "str_split_in_place");
|
||||
exportStrFn(str.countSegments, "count_segments");
|
||||
exportStrFn(str.countGraphemeClusters, "count_grapheme_clusters");
|
||||
|
|
|
@ -744,6 +744,21 @@ fn strFromFloatHelp(comptime T: type, float: T) RocStr {
|
|||
}
|
||||
|
||||
// Str.split
|
||||
|
||||
// For dev backends
|
||||
pub fn strSplit(string: RocStr, delimiter: RocStr) callconv(.C) RocList {
|
||||
const segment_count = countSegments(string, delimiter);
|
||||
const list = RocList.allocate(@alignOf(RocStr), segment_count, @sizeOf(RocStr));
|
||||
|
||||
if (list.bytes) |bytes| {
|
||||
const strings = @ptrCast([*]RocStr, @alignCast(@alignOf(RocStr), bytes));
|
||||
strSplitInPlace(strings, string, delimiter);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
// For LLVM backend
|
||||
pub fn strSplitInPlaceC(opt_array: ?[*]RocStr, string: RocStr, delimiter: RocStr) callconv(.C) void {
|
||||
if (opt_array) |array| {
|
||||
return @call(.{ .modifier = always_inline }, strSplitInPlace, .{ array, string, delimiter });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue