| ... | ... | @@ -2948,18 +2948,18 @@ pub fn SplitBackwardsIterator(comptime T: type, comptime delimiter_type: Delimit |
| 2948 | 2948 | |
| 2949 | 2949 | /// Naively combines a series of slices with a separator. |
| 2950 | 2950 | /// Allocates memory for the result, which must be freed by the caller. |
| 2951 | | pub fn join(allocator: Allocator, separator: []const u8, slices: []const []const u8) ![]u8 { |
| 2951 | pub fn join(allocator: Allocator, separator: []const u8, slices: []const []const u8) Allocator.Error![]u8 { |
| 2952 | 2952 | return joinMaybeZ(allocator, separator, slices, false); |
| 2953 | 2953 | } |
| 2954 | 2954 | |
| 2955 | 2955 | /// Naively combines a series of slices with a separator and null terminator. |
| 2956 | 2956 | /// Allocates memory for the result, which must be freed by the caller. |
| 2957 | | pub fn joinZ(allocator: Allocator, separator: []const u8, slices: []const []const u8) ![:0]u8 { |
| 2957 | pub fn joinZ(allocator: Allocator, separator: []const u8, slices: []const []const u8) Allocator.Error![:0]u8 { |
| 2958 | 2958 | const out = try joinMaybeZ(allocator, separator, slices, true); |
| 2959 | 2959 | return out[0 .. out.len - 1 :0]; |
| 2960 | 2960 | } |
| 2961 | 2961 | |
| 2962 | | fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []const u8, zero: bool) ![]u8 { |
| 2962 | fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []const u8, zero: bool) Allocator.Error![]u8 { |
| 2963 | 2963 | if (slices.len == 0) return if (zero) try allocator.dupe(u8, &[1]u8{0}) else &[0]u8{}; |
| 2964 | 2964 | |
| 2965 | 2965 | const total_len = blk: { |
| ... | ... | @@ -3038,18 +3038,18 @@ test "joinZ" { |
| 3038 | 3038 | } |
| 3039 | 3039 | |
| 3040 | 3040 | /// Copies each T from slices into a new slice that exactly holds all the elements. |
| 3041 | | pub fn concat(allocator: Allocator, comptime T: type, slices: []const []const T) ![]T { |
| 3041 | pub fn concat(allocator: Allocator, comptime T: type, slices: []const []const T) Allocator.Error![]T { |
| 3042 | 3042 | return concatMaybeSentinel(allocator, T, slices, null); |
| 3043 | 3043 | } |
| 3044 | 3044 | |
| 3045 | 3045 | /// Copies each T from slices into a new slice that exactly holds all the elements. |
| 3046 | | pub fn concatWithSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: T) ![:s]T { |
| 3046 | pub fn concatWithSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: T) Allocator.Error![:s]T { |
| 3047 | 3047 | const ret = try concatMaybeSentinel(allocator, T, slices, s); |
| 3048 | 3048 | return ret[0 .. ret.len - 1 :s]; |
| 3049 | 3049 | } |
| 3050 | 3050 | |
| 3051 | 3051 | /// Copies each T from slices into a new slice that exactly holds all the elements as well as the sentinel. |
| 3052 | | pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: ?T) ![]T { |
| 3052 | pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: ?T) Allocator.Error![]T { |
| 3053 | 3053 | if (slices.len == 0) return if (s) |sentinel| try allocator.dupe(T, &[1]T{sentinel}) else &[0]T{}; |
| 3054 | 3054 | |
| 3055 | 3055 | const total_len = blk: { |