diff --git a/CMakeLists.txt b/CMakeLists.txt index d0445759f1356f850de510e4bea623dd780cb1a9..49dde70f5e292b5e81ff64ad8b4a830a531beac6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -377,7 +377,7 @@ set(ZIG_STAGE2_SOURCES "${CMAKE_SOURCE_DIR}/lib/std/io/change_detection_stream.zig" "${CMAKE_SOURCE_DIR}/lib/std/io/counting_writer.zig" "${CMAKE_SOURCE_DIR}/lib/std/io/counting_reader.zig" - "${CMAKE_SOURCE_DIR}/lib/std/io/find_byte_out_stream.zig" + "${CMAKE_SOURCE_DIR}/lib/std/io/find_byte_writer.zig" "${CMAKE_SOURCE_DIR}/lib/std/io/fixed_buffer_stream.zig" "${CMAKE_SOURCE_DIR}/lib/std/io/reader.zig" "${CMAKE_SOURCE_DIR}/lib/std/io/seekable_stream.zig" diff --git a/lib/std/io.zig b/lib/std/io.zig index 3d8744d74d3b1cf49a7a9a672f8316fcb7e6f28c..fb5f00805c473b81763c138c606f3c682319a3e7 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -145,8 +145,12 @@ pub const autoIndentingStream = @import("io/auto_indenting_stream.zig").autoInde pub const ChangeDetectionStream = @import("io/change_detection_stream.zig").ChangeDetectionStream; pub const changeDetectionStream = @import("io/change_detection_stream.zig").changeDetectionStream; -pub const FindByteOutStream = @import("io/find_byte_out_stream.zig").FindByteOutStream; -pub const findByteOutStream = @import("io/find_byte_out_stream.zig").findByteOutStream; +pub const FindByteWriter = @import("io/find_byte_writer.zig").FindByteWriter; +pub const findByteWriter = @import("io/find_byte_writer.zig").findByteWriter; +/// Deprecated: use `FindByteWriter`. +pub const FindByteOutStream = FindByteWriter; +/// Deprecated: use `findByteWriter`. +pub const findByteOutStream = findByteWriter; pub const BufferedAtomicFile = @import("io/buffered_atomic_file.zig").BufferedAtomicFile; diff --git a/lib/std/io/find_byte_out_stream.zig b/lib/std/io/find_byte_out_stream.zig deleted file mode 100644 index e0e8fa871cc49df227fdec59336d0a2047ff3fa9..0000000000000000000000000000000000000000 --- a/lib/std/io/find_byte_out_stream.zig +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2015-2021 Zig Contributors -// This file is part of [zig](https://ziglang.org/), which is MIT licensed. -// The MIT license requires this copyright notice to be included in all copies -// and substantial portions of the software. - -const std = @import("../std.zig"); -const io = std.io; -const assert = std.debug.assert; - -/// An OutStream that returns whether the given character has been written to it. -/// The contents are not written to anything. -pub fn FindByteOutStream(comptime UnderlyingWriter: type) type { - return struct { - const Self = @This(); - pub const Error = UnderlyingWriter.Error; - pub const Writer = io.Writer(*Self, Error, write); - - underlying_writer: UnderlyingWriter, - byte_found: bool, - byte: u8, - - pub fn writer(self: *Self) Writer { - return .{ .context = self }; - } - - fn write(self: *Self, bytes: []const u8) Error!usize { - if (!self.byte_found) { - self.byte_found = blk: { - for (bytes) |b| - if (b == self.byte) break :blk true; - break :blk false; - }; - } - return self.underlying_writer.write(bytes); - } - }; -} - -pub fn findByteOutStream(byte: u8, underlying_writer: anytype) FindByteOutStream(@TypeOf(underlying_writer)) { - return FindByteOutStream(@TypeOf(underlying_writer)){ - .underlying_writer = underlying_writer, - .byte = byte, - .byte_found = false, - }; -} diff --git a/lib/std/io/find_byte_writer.zig b/lib/std/io/find_byte_writer.zig new file mode 100644 index 0000000000000000000000000000000000000000..db45114d3e4eb11731c431f33e08e414bafc1610 --- /dev/null +++ b/lib/std/io/find_byte_writer.zig @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.org/), which is MIT licensed. +// The MIT license requires this copyright notice to be included in all copies +// and substantial portions of the software. + +const std = @import("../std.zig"); +const io = std.io; +const assert = std.debug.assert; + +/// A Writer that returns whether the given character has been written to it. +/// The contents are not written to anything. +pub fn FindByteWriter(comptime UnderlyingWriter: type) type { + return struct { + const Self = @This(); + pub const Error = UnderlyingWriter.Error; + pub const Writer = io.Writer(*Self, Error, write); + + underlying_writer: UnderlyingWriter, + byte_found: bool, + byte: u8, + + pub fn writer(self: *Self) Writer { + return .{ .context = self }; + } + + fn write(self: *Self, bytes: []const u8) Error!usize { + if (!self.byte_found) { + self.byte_found = blk: { + for (bytes) |b| + if (b == self.byte) break :blk true; + break :blk false; + }; + } + return self.underlying_writer.write(bytes); + } + }; +} + +pub fn findByteWriter(byte: u8, underlying_writer: anytype) FindByteWriter(@TypeOf(underlying_writer)) { + return FindByteWriter(@TypeOf(underlying_writer)){ + .underlying_writer = underlying_writer, + .byte = byte, + .byte_found = false, + }; +} diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 8d2d37b76ae22934cef92ca4fc2e231d977a4521..3cced0dd6ba6c6157aee72421cad07220ac5c49a 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -790,7 +790,7 @@ fn renderExpression( const section_exprs = row_exprs[0..section_end]; // Null stream for counting the printed length of each expression - var line_find_stream = std.io.findByteOutStream('\n', std.io.null_writer); + var line_find_stream = std.io.findByteWriter('\n', std.io.null_writer); var counting_stream = std.io.countingWriter(line_find_stream.writer()); var auto_indenting_stream = std.io.autoIndentingStream(indent_delta, counting_stream.writer()); @@ -954,7 +954,7 @@ fn renderExpression( const expr_outputs_one_line = blk: { // render field expressions until a LF is found for (field_inits) |field_init| { - var find_stream = std.io.findByteOutStream('\n', std.io.null_writer); + var find_stream = std.io.findByteWriter('\n', std.io.null_writer); var auto_indenting_stream = std.io.autoIndentingStream(indent_delta, find_stream.writer()); try renderExpression(allocator, &auto_indenting_stream, tree, field_init, Space.None);