mirror of
https://github.com/ziglang/zig.git
synced 2026-01-28 02:05:31 +00:00
translate-c: convert tabs to \t in object-like macro string literals
Closes #12549
This commit is contained in:
parent
e2bb92b2e2
commit
e283a40d17
@ -5799,7 +5799,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {
|
||||
}
|
||||
}
|
||||
for (source) |c| {
|
||||
if (c == '\\') {
|
||||
if (c == '\\' or c == '\t') {
|
||||
break;
|
||||
}
|
||||
} else return source;
|
||||
@ -5876,6 +5876,13 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {
|
||||
state = .Start;
|
||||
},
|
||||
.Start => {
|
||||
if (c == '\t') {
|
||||
bytes[i] = '\\';
|
||||
i += 1;
|
||||
bytes[i] = 't';
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (c == '\\') {
|
||||
state = .Escape;
|
||||
}
|
||||
|
||||
@ -50,3 +50,5 @@ typedef _Bool uintptr_t;
|
||||
#define CAST_TO_UINTPTR(X) (uintptr_t)(X)
|
||||
|
||||
#define LARGE_INT 18446744073709550592
|
||||
|
||||
#define EMBEDDED_TAB "hello "
|
||||
|
||||
@ -2,6 +2,7 @@ const builtin = @import("builtin");
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const expectEqualStrings = std.testing.expectEqualStrings;
|
||||
|
||||
const h = @cImport(@cInclude("behavior/translate_c_macros.h"));
|
||||
|
||||
@ -123,3 +124,13 @@ test "large integer macro" {
|
||||
|
||||
try expectEqual(@as(c_ulonglong, 18446744073709550592), h.LARGE_INT);
|
||||
}
|
||||
|
||||
test "string literal macro with embedded tab character" {
|
||||
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
|
||||
try expectEqualStrings("hello\t", h.EMBEDDED_TAB);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user