ghostty/pkg/macos/foundation/character_set.zig
Mitchell Hashimoto 314f9287b1 Update Zig (#164)
* update zig

* pkg/fontconfig: clean up @as

* pkg/freetype,harfbuzz: clean up @as

* pkg/imgui: clean up @as

* pkg/macos: clean up @as

* pkg/pixman,utf8proc: clean up @as

* clean up @as

* lots more @as cleanup

* undo flatpak changes

* clean up @as
2023-06-30 12:15:31 -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.zig");
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,
range.cval(),
)))) 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();
}