@@ -344,11 +344,7 @@ const TestingSystem = struct {
344344 if (std .mem .eql (u8 , key , kv .key )) return kv .value ;
345345 }
346346 system .deinit ();
347- if (@hasDecl (std .zig , "fmtString" )) {
348- std .debug .panic ("the result of `getenv(\" {f}\" )` must explicitly specified in the TestingSystem" , .{std .zig .fmtString (key )});
349- } else {
350- std .debug .panic ("the result of `getenv(\" {}\" )` must explicitly specified in the TestingSystem" , .{std .zig .fmtEscapes (key )});
351- }
347+ std .debug .panic ("the result of `getenv(\" {f}\" )` must explicitly specified in the TestingSystem" , .{std .zig .fmtString (key )});
352348 }
353349
354350 /// Asserts that the file is specified in `TestingSystem.files`.
@@ -360,11 +356,7 @@ const TestingSystem = struct {
360356 if (std .mem .eql (u8 , file_path , kv .path )) break kv ;
361357 } else {
362358 system .deinit ();
363- if (@hasDecl (std .zig , "fmtString" )) {
364- std .debug .panic ("`openFile(\" {0f}\" , \" {1f}\" )` has been called on an unexpected file" , .{ std .zig .fmtString (dir_path ), std .zig .fmtString (sub_path ) });
365- } else {
366- std .debug .panic ("`openFile(\" {0}\" , \" {1}\" )` has been called on an unexpected file" , .{ std .zig .fmtEscapes (dir_path ), std .zig .fmtEscapes (sub_path ) });
367- }
359+ std .debug .panic ("`openFile(\" {0f}\" , \" {1f}\" )` has been called on an unexpected file" , .{ std .zig .fmtString (dir_path ), std .zig .fmtString (sub_path ) });
368360 };
369361
370362 const data = kv .data orelse return error .FileNotFound ;
@@ -451,7 +443,7 @@ fn xdgUserDirLookup(
451443 defer file .close ();
452444
453445 var buffer : [xdg_user_dir_lookup_line_buffer_size + 1 ]u8 = undefined ;
454- var line_it : if ( @hasDecl ( std.fs.File , "stdin" )) LineIterator else OldLineIterator = .init (file );
446+ var line_it : LineIterator = .init (file );
455447
456448 var user_dir : ? []u8 = null ;
457449 while (try line_it .next (& buffer )) | line_capture | {
@@ -536,48 +528,6 @@ fn xdgUserDirLookup(
536528 return user_dir ;
537529}
538530
539- const OldLineIterator = struct {
540- fbr : std .io .BufferedReader (4096 , std .fs .File .Reader ),
541-
542- fn init (file : std.fs.File ) OldLineIterator {
543- return .{
544- .fbr = std .io .bufferedReader (file .reader ()),
545- };
546- }
547-
548- fn next (it : * OldLineIterator , buffer : []u8 ) std.posix.ReadError ! ? [:0 ]const u8 {
549- const reader = it .fbr .reader ();
550-
551- // Similar to `readUntilDelimiterOrEof` but also writes a null-terminator
552- for (buffer , 0.. ) | * out , index | {
553- const byte = reader .readByte () catch | err | switch (err ) {
554- error .EndOfStream = > if (index == 0 ) return null else '\n ' ,
555- else = > | e | return e ,
556- };
557- if (byte == '\n ' ) {
558- out .* = 0 ;
559- return buffer [0.. index :0 ];
560- }
561- out .* = byte ;
562- } else {
563- // This happens when the line is longer than 511 characters
564- // There are four possible ways to handle this:
565- // - use dynamic allocation to acquire enough storage
566- // - return an error
567- // - skip the line
568- // - truncate the line
569- //
570- // The xdg-user-dir implementation chooses to trunacte the line.
571- // See "getPath - user-dirs.dirs - very long line" test
572-
573- try reader .skipUntilDelimiterOrEof ('\n ' );
574-
575- buffer [buffer .len - 1 ] = 0 ;
576- return buffer [0 .. buffer .len - 1 :0 ];
577- }
578- }
579- };
580-
581531const LineIterator = struct {
582532 file_reader : std.fs.File.Reader ,
583533 keep_reading : bool ,
0 commit comments