blob: d80ca45dc93a0e0113a27b0b707d7a9f175ff9a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
const std = @import("std");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const foundation = @import("../foundation.zig");
const c = @import("c.zig").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();
}
|