File tree 3 files changed +21
-5
lines changed
3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 1
1
const std = @import ("std.zig" );
2
2
const tokenizer = @import ("zig/tokenizer.zig" );
3
- const fmt = @import ("zig/fmt.zig" );
3
+ pub const fmt = @import ("zig/fmt.zig" );
4
4
const assert = std .debug .assert ;
5
5
6
6
pub const ErrorBundle = @import ("zig/ErrorBundle.zig" );
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ fn formatId(
13
13
return writer .writeAll (bytes );
14
14
}
15
15
try writer .writeAll ("@\" " );
16
- try formatEscapes (bytes , "" , options , writer );
16
+ try stringEscape (bytes , "" , options , writer );
17
17
try writer .writeByte ('"' );
18
18
}
19
19
@@ -47,7 +47,7 @@ test "isValidId" {
47
47
/// Print the string as escaped contents of a double quoted or single-quoted string.
48
48
/// Format `{}` treats contents as a double-quoted string.
49
49
/// Format `{'}` treats contents as a single-quoted string.
50
- fn formatEscapes (
50
+ pub fn stringEscape (
51
51
bytes : []const u8 ,
52
52
comptime fmt : []const u8 ,
53
53
options : std.fmt.FormatOptions ,
@@ -90,7 +90,7 @@ fn formatEscapes(
90
90
/// The format specifier must be one of:
91
91
/// * `{}` treats contents as a double-quoted string.
92
92
/// * `{'}` treats contents as a single-quoted string.
93
- pub fn fmtEscapes (bytes : []const u8 ) std.fmt.Formatter (formatEscapes ) {
93
+ pub fn fmtEscapes (bytes : []const u8 ) std.fmt.Formatter (stringEscape ) {
94
94
return .{ .data = bytes };
95
95
}
96
96
Original file line number Diff line number Diff line change @@ -89,7 +89,23 @@ pub const Path = struct {
89
89
options : std.fmt.FormatOptions ,
90
90
writer : anytype ,
91
91
) ! void {
92
- _ = options ;
92
+ if (fmt_string .len == 1 ) {
93
+ // Quote-escape the string.
94
+ const stringEscape = std .zig .fmt .stringEscape ;
95
+ const f = switch (fmt_string [0 ]) {
96
+ 'q' = > "" ,
97
+ '\' ' = > '\' ' ,
98
+ else = > @compileError ("unsupported format string: " ++ fmt_string ),
99
+ };
100
+ if (self .root_dir .path ) | p | {
101
+ try stringEscape (p , f , options , writer );
102
+ if (self .sub_path .len > 0 ) try writer .writeAll (fs .path .sep_str );
103
+ }
104
+ if (self .sub_path .len > 0 ) {
105
+ try stringEscape (self .sub_path , f , options , writer );
106
+ }
107
+ return ;
108
+ }
93
109
if (fmt_string .len > 0 )
94
110
std .fmt .invalidFmtError (fmt_string , self );
95
111
if (self .root_dir .path ) | p | {
You can’t perform that action at this time.
0 commit comments