Compare commits
2 commits
1f6cb4eb0c
...
1c90621708
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c90621708 | |||
| e01e8857e1 |
4 changed files with 22 additions and 15 deletions
|
|
@ -12,7 +12,7 @@ jobs:
|
|||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Zig
|
||||
uses: https://github.com/mlugg/setup-zig@v2.0.5
|
||||
uses: https://codeberg.org/mlugg/setup-zig@v2.2.1
|
||||
- name: Build project
|
||||
run: zig build --summary all
|
||||
- name: Run tests
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
[tools]
|
||||
zig = "0.15.1"
|
||||
zls = "0.15.0"
|
||||
pre-commit = "latest"
|
||||
"ubi:DonIsaac/zlint" = "latest"
|
||||
zig = "0.15.2"
|
||||
zls = "0.15.1"
|
||||
prek = "0.3.1"
|
||||
"ubi:DonIsaac/zlint" = "0.7.9"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v3.2.0
|
||||
rev: v6.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub fn main() !u8 {
|
|||
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
|
||||
var stderr_writer = std.fs.File.stdout().writer(&.{});
|
||||
const stdout = &stdout_writer.interface;
|
||||
defer stdout.flush() catch {};
|
||||
defer stdout.flush() catch @panic("flush failed!");
|
||||
const stderr = &stderr_writer.interface;
|
||||
const args = try std.process.argsAlloc(allocator);
|
||||
defer std.process.argsFree(allocator, args);
|
||||
|
|
@ -89,7 +89,17 @@ const Substitution = struct {
|
|||
|
||||
fn substituteLines(reader: *std.Io.Reader, writer: *std.Io.Writer, substitutions: []const Substitution) !usize {
|
||||
var subs: usize = 0;
|
||||
while (reader.takeDelimiterExclusive('\n')) |line| {
|
||||
var first_line = true;
|
||||
while (reader.takeDelimiter('\n')) |line_opt| {
|
||||
// takeDelimiter returns null at EOF
|
||||
const line = line_opt orelse break;
|
||||
|
||||
// Write newline before each line except the first
|
||||
if (!first_line) {
|
||||
try writer.writeByte('\n');
|
||||
}
|
||||
first_line = false;
|
||||
|
||||
var substituted = false;
|
||||
for (substitutions) |sub| {
|
||||
if (std.mem.eql(u8, line, sub.original)) {
|
||||
|
|
@ -101,9 +111,6 @@ fn substituteLines(reader: *std.Io.Reader, writer: *std.Io.Writer, substitutions
|
|||
}
|
||||
if (!substituted)
|
||||
try writer.writeAll(line);
|
||||
|
||||
if (reader.peekByte() != error.EndOfStream)
|
||||
try writer.writeByte('\n');
|
||||
} else |err| if (err != error.EndOfStream) return err;
|
||||
return subs;
|
||||
}
|
||||
|
|
@ -120,7 +127,7 @@ test "substitute lines exact match" {
|
|||
.{ .original = "replace_me", .replacement = "new_line" },
|
||||
};
|
||||
|
||||
try substituteLines(
|
||||
_ = try substituteLines(
|
||||
&input_stream,
|
||||
&output_stream,
|
||||
&substitutions,
|
||||
|
|
@ -141,7 +148,7 @@ test "no match found" {
|
|||
.{ .original = "nonexistent", .replacement = "replacement" },
|
||||
};
|
||||
|
||||
try substituteLines(
|
||||
_ = try substituteLines(
|
||||
&input_stream,
|
||||
&output_stream,
|
||||
&substitutions,
|
||||
|
|
@ -163,7 +170,7 @@ test "partial match not replaced" {
|
|||
.{ .original = "match", .replacement = "replaced" },
|
||||
};
|
||||
|
||||
try substituteLines(
|
||||
_ = try substituteLines(
|
||||
&input_stream,
|
||||
&output_stream,
|
||||
&substitutions,
|
||||
|
|
@ -186,7 +193,7 @@ test "multiple substitutions" {
|
|||
.{ .original = "replace_also", .replacement = "also_new" },
|
||||
};
|
||||
|
||||
try substituteLines(
|
||||
_ = try substituteLines(
|
||||
&input_stream,
|
||||
&output_stream,
|
||||
&substitutions,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue