M src/main.zig => src/main.zig +2 -14
@@ 2,6 2,7 @@ const std = @import("std");
const fs = std.fs;
const mem = std.mem;
const fmt = std.fmt;
+const util = @import("./util.zig");
pub const io_mode = .evented;
var debug_mode = false;
@@ 28,19 29,6 @@ const EscapedString = struct {
error_slice: ?[]const u8,
};
-fn nextLine(reader: anytype, buffer: []u8) !?[]const u8 {
- var line = (try reader.readUntilDelimiterOrEof(
- buffer,
- '\n',
- )) orelse return null;
- // trim annoying windows-only carriage return character
- if (@import("builtin").os.tag == .windows) {
- return mem.trimRight(u8, line, "\r");
- } else {
- return line;
- }
-}
-
// Read a note from disk, filtering out any lines
// inserted by the indexing process.
fn readBody(entry_name: []const u8, contents: *std.ArrayList(u8)) !void {
@@ 53,7 41,7 @@ fn readBody(entry_name: []const u8, contents: *std.ArrayList(u8)) !void {
while (true) {
var buf: [max_line_length]u8 = undefined;
- var maybe_line = try nextLine(reader, &buf);
+ var maybe_line = try util.nextLine(reader, &buf);
if (maybe_line) |line| {
if (line.len > ref_prefix.len and mem.eql(
u8,
A src/util.zig => src/util.zig +12 -0
@@ 0,0 1,12 @@
+pub fn nextLine(reader: anytype, buffer: []u8) !?[]const u8 {
+ var line = (try reader.readUntilDelimiterOrEof(
+ buffer,
+ '\n',
+ )) orelse return null;
+ // trim annoying windows-only carriage return character
+ if (@import("builtin").os.tag == .windows) {
+ return mem.trimRight(u8, line, "\r");
+ } else {
+ return line;
+ }
+}