| author | |
| committer | |
| log | e72472d953f5e91d37bc5f1bf1ec7b6fb5b1afe2 |
| tree | 330c924a9e1fcd46275ca9500bd60e9054251a98 |
| parent | 1595ce273edb32493231a43216a15cfbeb9ffc12 |
See #49175 files changed, 55 insertions(+), 51 deletions(-)
CMakeLists.txt+1-1| ... | ... | @@ -377,7 +377,7 @@ set(ZIG_STAGE2_SOURCES |
| 377 | 377 | "${CMAKE_SOURCE_DIR}/lib/std/io/change_detection_stream.zig" |
| 378 | 378 | "${CMAKE_SOURCE_DIR}/lib/std/io/counting_writer.zig" |
| 379 | 379 | "${CMAKE_SOURCE_DIR}/lib/std/io/counting_reader.zig" |
| 380 | "${CMAKE_SOURCE_DIR}/lib/std/io/find_byte_out_stream.zig" | |
| 380 | "${CMAKE_SOURCE_DIR}/lib/std/io/find_byte_writer.zig" | |
| 381 | 381 | "${CMAKE_SOURCE_DIR}/lib/std/io/fixed_buffer_stream.zig" |
| 382 | 382 | "${CMAKE_SOURCE_DIR}/lib/std/io/reader.zig" |
| 383 | 383 | "${CMAKE_SOURCE_DIR}/lib/std/io/seekable_stream.zig" |
lib/std/io.zig+6-2| ... | ... | @@ -145,8 +145,12 @@ pub const autoIndentingStream = @import("io/auto_indenting_stream.zig").autoInde |
| 145 | 145 | pub const ChangeDetectionStream = @import("io/change_detection_stream.zig").ChangeDetectionStream; |
| 146 | 146 | pub const changeDetectionStream = @import("io/change_detection_stream.zig").changeDetectionStream; |
| 147 | 147 | |
| 148 | pub const FindByteOutStream = @import("io/find_byte_out_stream.zig").FindByteOutStream; | |
| 149 | pub const findByteOutStream = @import("io/find_byte_out_stream.zig").findByteOutStream; | |
| 148 | pub const FindByteWriter = @import("io/find_byte_writer.zig").FindByteWriter; | |
| 149 | pub const findByteWriter = @import("io/find_byte_writer.zig").findByteWriter; | |
| 150 | /// Deprecated: use `FindByteWriter`. | |
| 151 | pub const FindByteOutStream = FindByteWriter; | |
| 152 | /// Deprecated: use `findByteWriter`. | |
| 153 | pub const findByteOutStream = findByteWriter; | |
| 150 | 154 | |
| 151 | 155 | pub const BufferedAtomicFile = @import("io/buffered_atomic_file.zig").BufferedAtomicFile; |
| 152 | 156 |
lib/std/io/find_byte_out_stream.zig deleted-46| ... | ... | @@ -1,46 +0,0 @@ |
| 1 | // SPDX-License-Identifier: MIT | |
| 2 | // Copyright (c) 2015-2021 Zig Contributors | |
| 3 | // This file is part of [zig](https://ziglang.org/), which is MIT licensed. | |
| 4 | // The MIT license requires this copyright notice to be included in all copies | |
| 5 | // and substantial portions of the software. | |
| 6 | ||
| 7 | const std = @import("../std.zig"); | |
| 8 | const io = std.io; | |
| 9 | const assert = std.debug.assert; | |
| 10 | ||
| 11 | /// An OutStream that returns whether the given character has been written to it. | |
| 12 | /// The contents are not written to anything. | |
| 13 | pub fn FindByteOutStream(comptime UnderlyingWriter: type) type { | |
| 14 | return struct { | |
| 15 | const Self = @This(); | |
| 16 | pub const Error = UnderlyingWriter.Error; | |
| 17 | pub const Writer = io.Writer(*Self, Error, write); | |
| 18 | ||
| 19 | underlying_writer: UnderlyingWriter, | |
| 20 | byte_found: bool, | |
| 21 | byte: u8, | |
| 22 | ||
| 23 | pub fn writer(self: *Self) Writer { | |
| 24 | return .{ .context = self }; | |
| 25 | } | |
| 26 | ||
| 27 | fn write(self: *Self, bytes: []const u8) Error!usize { | |
| 28 | if (!self.byte_found) { | |
| 29 | self.byte_found = blk: { | |
| 30 | for (bytes) |b| | |
| 31 | if (b == self.byte) break :blk true; | |
| 32 | break :blk false; | |
| 33 | }; | |
| 34 | } | |
| 35 | return self.underlying_writer.write(bytes); | |
| 36 | } | |
| 37 | }; | |
| 38 | } | |
| 39 | ||
| 40 | pub fn findByteOutStream(byte: u8, underlying_writer: anytype) FindByteOutStream(@TypeOf(underlying_writer)) { | |
| 41 | return FindByteOutStream(@TypeOf(underlying_writer)){ | |
| 42 | .underlying_writer = underlying_writer, | |
| 43 | .byte = byte, | |
| 44 | .byte_found = false, | |
| 45 | }; | |
| 46 | } |
lib/std/io/find_byte_writer.zig created+46| ... | ... | @@ -0,0 +1,46 @@ |
| 1 | // SPDX-License-Identifier: MIT | |
| 2 | // Copyright (c) 2015-2021 Zig Contributors | |
| 3 | // This file is part of [zig](https://ziglang.org/), which is MIT licensed. | |
| 4 | // The MIT license requires this copyright notice to be included in all copies | |
| 5 | // and substantial portions of the software. | |
| 6 | ||
| 7 | const std = @import("../std.zig"); | |
| 8 | const io = std.io; | |
| 9 | const assert = std.debug.assert; | |
| 10 | ||
| 11 | /// A Writer that returns whether the given character has been written to it. | |
| 12 | /// The contents are not written to anything. | |
| 13 | pub fn FindByteWriter(comptime UnderlyingWriter: type) type { | |
| 14 | return struct { | |
| 15 | const Self = @This(); | |
| 16 | pub const Error = UnderlyingWriter.Error; | |
| 17 | pub const Writer = io.Writer(*Self, Error, write); | |
| 18 | ||
| 19 | underlying_writer: UnderlyingWriter, | |
| 20 | byte_found: bool, | |
| 21 | byte: u8, | |
| 22 | ||
| 23 | pub fn writer(self: *Self) Writer { | |
| 24 | return .{ .context = self }; | |
| 25 | } | |
| 26 | ||
| 27 | fn write(self: *Self, bytes: []const u8) Error!usize { | |
| 28 | if (!self.byte_found) { | |
| 29 | self.byte_found = blk: { | |
| 30 | for (bytes) |b| | |
| 31 | if (b == self.byte) break :blk true; | |
| 32 | break :blk false; | |
| 33 | }; | |
| 34 | } | |
| 35 | return self.underlying_writer.write(bytes); | |
| 36 | } | |
| 37 | }; | |
| 38 | } | |
| 39 | ||
| 40 | pub fn findByteWriter(byte: u8, underlying_writer: anytype) FindByteWriter(@TypeOf(underlying_writer)) { | |
| 41 | return FindByteWriter(@TypeOf(underlying_writer)){ | |
| 42 | .underlying_writer = underlying_writer, | |
| 43 | .byte = byte, | |
| 44 | .byte_found = false, | |
| 45 | }; | |
| 46 | } |
lib/std/zig/render.zig+2-2| ... | ... | @@ -790,7 +790,7 @@ fn renderExpression( |
| 790 | 790 | const section_exprs = row_exprs[0..section_end]; |
| 791 | 791 | |
| 792 | 792 | // Null stream for counting the printed length of each expression |
| 793 | var line_find_stream = std.io.findByteOutStream('\n', std.io.null_writer); | |
| 793 | var line_find_stream = std.io.findByteWriter('\n', std.io.null_writer); | |
| 794 | 794 | var counting_stream = std.io.countingWriter(line_find_stream.writer()); |
| 795 | 795 | var auto_indenting_stream = std.io.autoIndentingStream(indent_delta, counting_stream.writer()); |
| 796 | 796 | |
| ... | ... | @@ -954,7 +954,7 @@ fn renderExpression( |
| 954 | 954 | const expr_outputs_one_line = blk: { |
| 955 | 955 | // render field expressions until a LF is found |
| 956 | 956 | for (field_inits) |field_init| { |
| 957 | var find_stream = std.io.findByteOutStream('\n', std.io.null_writer); | |
| 957 | var find_stream = std.io.findByteWriter('\n', std.io.null_writer); | |
| 958 | 958 | var auto_indenting_stream = std.io.autoIndentingStream(indent_delta, find_stream.writer()); |
| 959 | 959 | |
| 960 | 960 | try renderExpression(allocator, &auto_indenting_stream, tree, field_init, Space.None); |