mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/macos: support CFCharacterSet
This commit is contained in:
@ -2,6 +2,7 @@ pub const c = @import("foundation/c.zig");
|
|||||||
pub usingnamespace @import("foundation/array.zig");
|
pub usingnamespace @import("foundation/array.zig");
|
||||||
pub usingnamespace @import("foundation/attributed_string.zig");
|
pub usingnamespace @import("foundation/attributed_string.zig");
|
||||||
pub usingnamespace @import("foundation/base.zig");
|
pub usingnamespace @import("foundation/base.zig");
|
||||||
|
pub usingnamespace @import("foundation/character_set.zig");
|
||||||
pub usingnamespace @import("foundation/data.zig");
|
pub usingnamespace @import("foundation/data.zig");
|
||||||
pub usingnamespace @import("foundation/dictionary.zig");
|
pub usingnamespace @import("foundation/dictionary.zig");
|
||||||
pub usingnamespace @import("foundation/number.zig");
|
pub usingnamespace @import("foundation/number.zig");
|
||||||
|
30
pkg/macos/foundation/character_set.zig
Normal file
30
pkg/macos/foundation/character_set.zig
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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 @intToPtr(?*CharacterSet, @ptrToInt(c.CFCharacterSetCreateWithCharactersInString(
|
||||||
|
null,
|
||||||
|
@ptrCast(c.CFStringRef, str),
|
||||||
|
))) 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();
|
||||||
|
}
|
Reference in New Issue
Block a user