mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Add Str.repeat builtin
This commit is contained in:
parent
0b02929a53
commit
b32a42f05a
11 changed files with 109 additions and 14 deletions
|
@ -101,6 +101,7 @@ comptime {
|
|||
exportStrFn(str.strToUtf8C, "to_utf8");
|
||||
exportStrFn(str.fromUtf8C, "from_utf8");
|
||||
exportStrFn(str.fromUtf8RangeC, "from_utf8_range");
|
||||
exportStrFn(str.repeat, "repeat");
|
||||
}
|
||||
|
||||
// Utils
|
||||
|
|
|
@ -866,6 +866,23 @@ pub fn startsWith(string: RocStr, prefix: RocStr) callconv(.C) bool {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Str.repeat
|
||||
pub fn repeat(string: RocStr, count: usize) callconv(.C) RocStr {
|
||||
const bytes_len = string.len();
|
||||
const bytes_ptr = string.asU8ptr();
|
||||
|
||||
var ret_string = RocStr.allocate(.Clone, count * bytes_len);
|
||||
var ret_string_ptr = ret_string.asU8ptr();
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < count) : (i += 1) {
|
||||
@memcpy(ret_string_ptr + (i * bytes_len), bytes_ptr, bytes_len);
|
||||
}
|
||||
|
||||
return ret_string;
|
||||
}
|
||||
|
||||
// Str.startsWithCodePt
|
||||
pub fn startsWithCodePt(string: RocStr, prefix: u32) callconv(.C) bool {
|
||||
const bytes_ptr = string.asU8ptr();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue