| ... | @@ -269,6 +269,18 @@ pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void { | ... | @@ -269,6 +269,18 @@ pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void { |
| 269 | } | 269 | } |
| 270 | } | 270 | } |
| 271 | | 271 | |
| | 272 | /// Copy `source` into `dest`. Asserts no overlap. Asserts `dest.len` greater |
| | 273 | /// or equal to source len. Returns number of elements copied. |
| | 274 | pub fn copySentinel(comptime T: type, comptime s: T, dest: []T, source: [*:s]const T) usize { |
| | 275 | const i = findSentinel(T, s, source); |
| | 276 | @memcpy(dest[0..i], source[0..i]); |
| | 277 | return i; |
| | 278 | } |
| | 279 | |
| | 280 | test copySentinel { |
| | 281 | @panic("TODO"); |
| | 282 | } |
| | 283 | |
| 272 | /// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function. | 284 | /// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function. |
| 273 | /// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when | 285 | /// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when |
| 274 | /// interfacing with a C API where this practice is more common and relied upon. If you are performing code review and see this | 286 | /// interfacing with a C API where this practice is more common and relied upon. If you are performing code review and see this |
| ... | @@ -733,6 +745,20 @@ test lessThan { | ... | @@ -733,6 +745,20 @@ test lessThan { |
| 733 | try testing.expect(lessThan(u8, "", "a")); | 745 | try testing.expect(lessThan(u8, "", "a")); |
| 734 | } | 746 | } |
| 735 | | 747 | |
| | 748 | /// Returns `true` if `lhs < rhs`; `false` otherwise, operating on |
| | 749 | /// null-terminated arrays. |
| | 750 | pub fn lessThanZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T) bool { |
| | 751 | return orderZ(T, lhs, rhs) == .lt; |
| | 752 | } |
| | 753 | |
| | 754 | test lessThanZ { |
| | 755 | try testing.expect(lessThanZ(u8, "abcd", "bee")); |
| | 756 | try testing.expect(!lessThanZ(u8, "abc", "abc")); |
| | 757 | try testing.expect(lessThanZ(u8, "abc", "abc0")); |
| | 758 | try testing.expect(!lessThanZ(u8, "", "")); |
| | 759 | try testing.expect(lessThanZ(u8, "", "a")); |
| | 760 | } |
| | 761 | |
| 736 | const use_vectors = switch (builtin.zig_backend) { | 762 | const use_vectors = switch (builtin.zig_backend) { |
| 737 | // These backends don't support vectors yet. | 763 | // These backends don't support vectors yet. |
| 738 | .stage2_aarch64, | 764 | .stage2_aarch64, |