Skip to content

Commit

Permalink
Use splitScalar for splitting
Browse files Browse the repository at this point in the history
Zig master has officially deprecated `std.mem.split`, so this will keep
the library compatible going forward.
  • Loading branch information
mnemnion committed Aug 4, 2024
1 parent 4d4bf43 commit 7f25f94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Let me show you its features!
The best way to use `ohsnap` is to install it using the [Zig Build System](https://ziglang.org/learn/build-system/). From your project repo root, use `zig fetch` like this:

```sh
zig fetch --save "https://github.com/mnemnion/ohsnap/archive/refs/tags/v0.1.1.tar.gz"
zig fetch --save "https://github.com/mnemnion/ohsnap/archive/refs/tags/v0.1.2.tar.gz"
```

Then add it to your test artifact like so:
Expand Down Expand Up @@ -152,7 +152,7 @@ Simply replace the timestamp like so:
\\ohsnap.StampedStruct
\\ .message: []const u8
\\ "frobnicate the turbo-encabulator"
\\ .tag: u64 = 17337
\\ .tag: u64 = 37337
\\ .timestamp: isize = <^\d+$>
,
).expectEqual(with_stamp);
Expand All @@ -167,7 +167,7 @@ Let's say you make a change:
```zig
const with_stamp = StampedStruct.init(
"thoroughly frobnicate the encabulator",
17337,
37337,
);
```

Expand All @@ -182,7 +182,7 @@ Since this was an intentional change, we need to update the snap:
\\ohsnap.StampedStruct
\\ .message: []const u8
\\ "frobnicate the turbo-encabulator"
\\ .tag: u64 = 17337
\\ .tag: u64 = 37337
\\ .timestamp: isize = <^\d+$>
,
).expectEqual(with_stamp);
Expand All @@ -196,7 +196,7 @@ Once again, through the magic of diffing, `ohsnap` will locate the regexen in th
\\ohsnap.StampedStruct
\\ .message: []const u8
\\ "thoroughly frobnicate the encabulator"
\\ .tag: u64 = 17337
\\ .tag: u64 = 37337
\\ .timestamp: isize = <^\d+$>
,
).expectEqual(with_stamp);
Expand Down
6 changes: 3 additions & 3 deletions src/ohsnap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub const Snap = struct {

try file_text_updated.appendSlice(snapshot_prefix);
{
var lines = std.mem.split(u8, got, "\n");
var lines = std.mem.splitScalar(u8, got, '\n');
while (lines.next()) |line| {
try file_text_updated.writer().print("{s}\\\\{s}\n", .{ indent, line });
}
Expand Down Expand Up @@ -377,7 +377,7 @@ fn snapRange(text: []const u8, src_line: u32) !Range {
var offset: usize = 0;
var line_number: u32 = 0;

var lines = std.mem.split(u8, text, "\n");
var lines = std.mem.splitScalar(u8, text, '\n');
const snap_start = while (lines.next()) |line| : (line_number += 1) {
if (line_number == src_line) {
if (std.mem.indexOf(u8, line, "@src()") == null) {
Expand All @@ -401,7 +401,7 @@ fn snapRange(text: []const u8, src_line: u32) !Range {
offset += line.len + 1; // 1 for \n
} else unreachable;

lines = std.mem.split(u8, text[snap_start..], "\n");
lines = std.mem.splitScalar(u8, text[snap_start..], '\n');
const snap_end = while (lines.next()) |line| {
if (!isMultilineString(line)) {
break offset;
Expand Down

0 comments on commit 7f25f94

Please sign in to comment.