Files
ghostty/pkg/fontconfig/lang_set.zig
Mitchell Hashimoto eccd07f009 pkg: replace @cImport with addTranslateC in pkg/
@cImport is going to disappear in Zig 0.17. Its deprecated in Zig 0.16.
Let's remove it now.

Replace @cImport with addTranslateC across pkg/ packages. Each
package now has a c_import.h header that is translated at build
time via addTranslateC and exposed as a "cimport" module import.

Converted packages:
- dcimgui
- fontconfig
- freetype
- glslang
- harfbuzz
- macos
- oniguruma
- opengl
- sentry
- spirv-cross
- wuffs

Omitted:
- gtk4-layer-shell - This has a bit more complexity with how it
  interacts with GTK headers, so I need to consider this a bit more.
- src/ - It'll be cleaner to do this separately.
2026-04-16 21:35:51 -07:00

62 lines
1.8 KiB
Zig

const std = @import("std");
const assert = std.debug.assert;
const c = @import("c");
pub const LangSet = opaque {
pub fn create() *LangSet {
return @ptrCast(c.FcLangSetCreate());
}
pub fn destroy(self: *LangSet) void {
c.FcLangSetDestroy(self.cval());
}
pub fn addLang(self: *LangSet, lang: [:0]const u8) bool {
return c.FcLangSetAdd(self.cval(), lang.ptr) == c.FcTrue;
}
pub fn hasLang(self: *const LangSet, lang: [:0]const u8) bool {
return c.FcLangSetHasLang(self.cvalConst(), lang.ptr) == c.FcLangEqual;
}
pub inline fn cval(self: *LangSet) *c.struct__FcLangSet {
return @ptrCast(self);
}
pub inline fn cvalConst(self: *const LangSet) *const c.struct__FcLangSet {
return @ptrCast(self);
}
};
test "create" {
const testing = std.testing;
var fs = LangSet.create();
defer fs.destroy();
try testing.expect(!fs.hasLang("und-zsye"));
}
test "hasLang exact match" {
const testing = std.testing;
// Test exact match: langset with "en-US" should return true for "en-US"
var fs = LangSet.create();
defer fs.destroy();
try testing.expect(fs.addLang("en-US"));
try testing.expect(fs.hasLang("en-US"));
// Test exact match: langset with "und-zsye" should return true for "und-zsye"
var fs_emoji = LangSet.create();
defer fs_emoji.destroy();
try testing.expect(fs_emoji.addLang("und-zsye"));
try testing.expect(fs_emoji.hasLang("und-zsye"));
// Test mismatch: langset with "en-US" should return false for "fr"
try testing.expect(!fs.hasLang("fr"));
// Test partial match: langset with "en-US" should return false for "en-GB"
// (different territory, but we only want exact matches)
try testing.expect(!fs.hasLang("en-GB"));
}