zig icon indicating copy to clipboard operation
zig copied to clipboard

std.mem.trim*: Allow mutable slices

Open ominitay opened this issue 3 years ago • 1 comments

This PR changes std.mem.trimLeft, ...trimRight, and ...trim to allow the use of both mutable and non-mutable slices. Previously, either a dangerous intToPtr was needed, or the slice's data had to be manually copied into a mutable slice. This change means that mutable slices now "just work", and doesn't break existing use.

ominitay avatar Sep 06 '22 16:09 ominitay

There are a few changes left to be made here. Pointer alignment must be considered -- the function should return an naturally-aligned slice. Additionally, sentinel-terminated slices should be disallowed, at least for trim and trimRight, or the sentinel should be removed from the return type.

ominitay avatar Sep 06 '22 16:09 ominitay

Closing old draft

andrewrk avatar Dec 12 '22 03:12 andrewrk