diff options
| author | Veikka Tuominen <git@vexu.eu> | 2024-06-02 17:03:56 +0300 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-06-02 13:03:29 -0400 |
| commit | 5e1ccd96e5dcd2ed2d38d3260edcdd68b4b8da9d (patch) | |
| tree | f90fe2f0fa4e3fc1dca1039942d32d17a80d91f4 /lib/std | |
| parent | 64ef45eb059328ac8579c22506fa7574e8cf45f2 (diff) | |
| download | zig-5e1ccd96e5dcd2ed2d38d3260edcdd68b4b8da9d.tar.gz zig-5e1ccd96e5dcd2ed2d38d3260edcdd68b4b8da9d.zip | |
remove std.Ini
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/Ini.zig | 66 | ||||
| -rw-r--r-- | lib/std/std.zig | 1 |
2 files changed, 0 insertions, 67 deletions
diff --git a/lib/std/Ini.zig b/lib/std/Ini.zig deleted file mode 100644 index 1965339186..0000000000 --- a/lib/std/Ini.zig +++ /dev/null @@ -1,66 +0,0 @@ -bytes: []const u8, - -pub const SectionIterator = struct { - ini: Ini, - next_index: ?usize, - header: []const u8, - - pub fn next(it: *SectionIterator) ?[]const u8 { - const bytes = it.ini.bytes; - const start = it.next_index orelse return null; - const end = mem.indexOfPos(u8, bytes, start, "\n[") orelse bytes.len; - const result = bytes[start..end]; - if (mem.indexOfPos(u8, bytes, start, it.header)) |next_index| { - it.next_index = next_index + it.header.len; - } else { - it.next_index = null; - } - return result; - } -}; - -/// Asserts that `header` includes "\n[" at the beginning and "]\n" at the end. -/// `header` must remain valid for the lifetime of the iterator. -pub fn iterateSection(ini: Ini, header: []const u8) SectionIterator { - assert(mem.startsWith(u8, header, "\n[")); - assert(mem.endsWith(u8, header, "]\n")); - const first_header = header[1..]; - const next_index = if (mem.indexOf(u8, ini.bytes, first_header)) |i| - i + first_header.len - else - null; - return .{ - .ini = ini, - .next_index = next_index, - .header = header, - }; -} - -const std = @import("std.zig"); -const mem = std.mem; -const assert = std.debug.assert; -const Ini = @This(); -const testing = std.testing; - -test iterateSection { - const example = - \\[package] - \\name=libffmpeg - \\version=5.1.2 - \\ - \\[dependency] - \\id=libz - \\url=url1 - \\ - \\[dependency] - \\id=libmp3lame - \\url=url2 - ; - var ini: Ini = .{ .bytes = example }; - var it = ini.iterateSection("\n[dependency]\n"); - const section1 = it.next() orelse return error.TestFailed; - try testing.expectEqualStrings("id=libz\nurl=url1\n", section1); - const section2 = it.next() orelse return error.TestFailed; - try testing.expectEqualStrings("id=libmp3lame\nurl=url2", section2); - try testing.expect(it.next() == null); -} diff --git a/lib/std/std.zig b/lib/std/std.zig index e33feddbf5..1f62630d0d 100644 --- a/lib/std/std.zig +++ b/lib/std/std.zig @@ -25,7 +25,6 @@ pub const EnumMap = enums.EnumMap; pub const EnumSet = enums.EnumSet; pub const HashMap = hash_map.HashMap; pub const HashMapUnmanaged = hash_map.HashMapUnmanaged; -pub const Ini = @import("Ini.zig"); pub const MultiArrayList = @import("multi_array_list.zig").MultiArrayList; pub const PackedIntArray = @import("packed_int_array.zig").PackedIntArray; pub const PackedIntArrayEndian = @import("packed_int_array.zig").PackedIntArrayEndian; |
