config file quoted strings are accepted now

This commit is contained in:
Mitchell Hashimoto
2023-06-23 13:45:48 -07:00
parent ce47bdb874
commit 6e79e84acf
2 changed files with 24 additions and 3 deletions

View File

@ -375,7 +375,22 @@ pub fn LineIterator(comptime ReaderType: type) type {
// Trim spaces around '=' // Trim spaces around '='
if (mem.indexOf(u8, entry, "=")) |idx| { if (mem.indexOf(u8, entry, "=")) |idx| {
const key = std.mem.trim(u8, entry[0..idx], whitespace); const key = std.mem.trim(u8, entry[0..idx], whitespace);
const value = std.mem.trim(u8, entry[idx + 1 ..], whitespace); const value = value: {
var value = std.mem.trim(u8, entry[idx + 1 ..], whitespace);
// Detect a quoted string.
if (value.len >= 2 and
value[0] == '"' and
value[value.len - 1] == '"')
{
// Trim quotes since our CLI args processor expects
// quotes to already be gone.
value = value[1 .. value.len - 1];
}
break :value value;
};
const len = key.len + value.len + 1; const len = key.len + value.len + 1;
if (entry.len != len) { if (entry.len != len) {
std.mem.copy(u8, entry, key); std.mem.copy(u8, entry, key);
@ -414,6 +429,9 @@ test "LineIterator" {
\\ \\
\\ # An indented comment \\ # An indented comment
\\ E \\ E
\\
\\# A quoted string with whitespace
\\F= "value "
); );
var iter = lineIterator(fbs.reader()); var iter = lineIterator(fbs.reader());
@ -422,6 +440,7 @@ test "LineIterator" {
try testing.expectEqualStrings("--C", iter.next().?); try testing.expectEqualStrings("--C", iter.next().?);
try testing.expectEqualStrings("--D", iter.next().?); try testing.expectEqualStrings("--D", iter.next().?);
try testing.expectEqualStrings("--E", iter.next().?); try testing.expectEqualStrings("--E", iter.next().?);
try testing.expectEqualStrings("--F=value ", iter.next().?);
try testing.expectEqual(@as(?[]const u8, null), iter.next()); try testing.expectEqual(@as(?[]const u8, null), iter.next());
try testing.expectEqual(@as(?[]const u8, null), iter.next()); try testing.expectEqual(@as(?[]const u8, null), iter.next());
} }

View File

@ -346,7 +346,8 @@ test "fontconfig codepoint" {
} }
test "coretext" { test "coretext" {
if (options.backend != .coretext) return error.SkipZigTest; if (options.backend != .coretext and options.backend != .coretext_freetype)
return error.SkipZigTest;
const testing = std.testing; const testing = std.testing;
@ -363,7 +364,8 @@ test "coretext" {
} }
test "coretext codepoint" { test "coretext codepoint" {
if (options.backend != .coretext) return error.SkipZigTest; if (options.backend != .coretext and options.backend != .coretext_freetype)
return error.SkipZigTest;
const testing = std.testing; const testing = std.testing;