| author | |
| committer | |
| log | 6fb9f29c318b731eb213f56d7b14898be8b668cf |
| tree | 0640e38e15f308106d3f56348d649c82da391429 |
| parent | aebddddaa1dd96e7a86f3ee10cb6c5e89b56d58b |
| signature | Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw |
2 files changed, 22 insertions(+), 0 deletions(-)
src/lib.zig+2| ... | ... | @@ -87,6 +87,7 @@ pub const from_hex = @import("./from_hex.zig").from_hex; |
| 87 | 87 | pub const Pointee = @import("./Pointee.zig").Pointee; |
| 88 | 88 | pub const compareFnSlice = @import("./compareFnSlice.zig").compareFnSlice; |
| 89 | 89 | pub const sumLen = @import("./sumLen.zig").sumLen; |
| 90 | pub const splitScalarN = @import("./splitScalarN.zig").splitScalarN; | |
| 90 | 91 | |
| 91 | 92 | test { |
| 92 | 93 | _ = @import("reduceNumber.zig"); |
| ... | ... | @@ -163,4 +164,5 @@ test { |
| 163 | 164 | _ = @import("Pointee.zig"); |
| 164 | 165 | _ = @import("compareFnSlice.zig"); |
| 165 | 166 | _ = @import("sumLen.zig"); |
| 167 | _ = @import("splitScalarN.zig"); | |
| 166 | 168 | } |
src/splitScalarN.zig created+20| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | const std = @import("std"); | |
| 2 | const extras = @import("./lib.zig"); | |
| 3 | ||
| 4 | pub fn splitScalarN(comptime T: type, buffer: []const T, delimiter: T, comptime N: usize) ?[N][]const T { | |
| 5 | var result: [N][]const T = undefined; | |
| 6 | var iter = std.mem.splitScalar(T, buffer, delimiter); | |
| 7 | for (&result) |*x| x.* = iter.next() orelse return null; | |
| 8 | if (iter.next() != null) return null; | |
| 9 | return result; | |
| 10 | } | |
| 11 | ||
| 12 | test { | |
| 13 | try std.testing.expectEqualDeep(&[_][]const u8{ "abc", "def" }, &splitScalarN(u8, "abc.def", '.', 2).?); | |
| 14 | } | |
| 15 | test { | |
| 16 | try std.testing.expectEqual(null, splitScalarN(u8, "abcdef", '.', 2)); | |
| 17 | } | |
| 18 | test { | |
| 19 | try std.testing.expectEqual(null, splitScalarN(u8, "ab.cd.ef", '.', 2)); | |
| 20 | } |