Skip to content

Commit 7f25f94

Browse files
committed
Use splitScalar for splitting
Zig master has officially deprecated `std.mem.split`, so this will keep the library compatible going forward.
1 parent 4d4bf43 commit 7f25f94

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Let me show you its features!
1515
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:
1616

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

2121
Then add it to your test artifact like so:
@@ -152,7 +152,7 @@ Simply replace the timestamp like so:
152152
\\ohsnap.StampedStruct
153153
\\ .message: []const u8
154154
\\ "frobnicate the turbo-encabulator"
155-
\\ .tag: u64 = 17337
155+
\\ .tag: u64 = 37337
156156
\\ .timestamp: isize = <^\d+$>
157157
,
158158
).expectEqual(with_stamp);
@@ -167,7 +167,7 @@ Let's say you make a change:
167167
```zig
168168
const with_stamp = StampedStruct.init(
169169
"thoroughly frobnicate the encabulator",
170-
17337,
170+
37337,
171171
);
172172
```
173173

@@ -182,7 +182,7 @@ Since this was an intentional change, we need to update the snap:
182182
\\ohsnap.StampedStruct
183183
\\ .message: []const u8
184184
\\ "frobnicate the turbo-encabulator"
185-
\\ .tag: u64 = 17337
185+
\\ .tag: u64 = 37337
186186
\\ .timestamp: isize = <^\d+$>
187187
,
188188
).expectEqual(with_stamp);
@@ -196,7 +196,7 @@ Once again, through the magic of diffing, `ohsnap` will locate the regexen in th
196196
\\ohsnap.StampedStruct
197197
\\ .message: []const u8
198198
\\ "thoroughly frobnicate the encabulator"
199-
\\ .tag: u64 = 17337
199+
\\ .tag: u64 = 37337
200200
\\ .timestamp: isize = <^\d+$>
201201
,
202202
).expectEqual(with_stamp);

src/ohsnap.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub const Snap = struct {
180180

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

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

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

0 commit comments

Comments
 (0)