Files
ghostty/pkg/macos/foundation/character_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

50 lines
1.4 KiB
Zig

const std = @import("std");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const foundation = @import("../foundation.zig");
const c = @import("c");
pub const CharacterSet = opaque {
pub fn createWithCharactersInString(
str: *foundation.String,
) Allocator.Error!*CharacterSet {
return @as(?*CharacterSet, @ptrFromInt(@intFromPtr(c.CFCharacterSetCreateWithCharactersInString(
null,
@ptrCast(str),
)))) orelse Allocator.Error.OutOfMemory;
}
pub fn createWithCharactersInRange(
range: foundation.Range,
) Allocator.Error!*CharacterSet {
return @as(?*CharacterSet, @ptrFromInt(@intFromPtr(c.CFCharacterSetCreateWithCharactersInRange(
null,
@bitCast(range),
)))) orelse Allocator.Error.OutOfMemory;
}
pub fn release(self: *CharacterSet) void {
c.CFRelease(self);
}
};
test "character set" {
//const testing = std.testing;
const str = try foundation.String.createWithBytes("hello world", .ascii, false);
defer str.release();
const cs = try CharacterSet.createWithCharactersInString(str);
defer cs.release();
}
test "character set range" {
//const testing = std.testing;
const cs = try CharacterSet.createWithCharactersInRange(.{
.location = 'A',
.length = 1,
});
defer cs.release();
}