mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: add another string API to test it really works
This commit is contained in:
@ -21,6 +21,10 @@ pub const String = opaque {
|
|||||||
cftype.CFRelease(self);
|
cftype.CFRelease(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hasPrefix(self: *String, prefix: *String) bool {
|
||||||
|
return CFStringHasPrefix(self, prefix) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
pub extern "c" fn CFStringCreateWithBytes(
|
pub extern "c" fn CFStringCreateWithBytes(
|
||||||
allocator: ?*anyopaque,
|
allocator: ?*anyopaque,
|
||||||
bytes: [*]const u8,
|
bytes: [*]const u8,
|
||||||
@ -28,6 +32,7 @@ pub const String = opaque {
|
|||||||
encooding: u32,
|
encooding: u32,
|
||||||
is_external: bool,
|
is_external: bool,
|
||||||
) ?*String;
|
) ?*String;
|
||||||
|
pub extern "c" fn CFStringHasPrefix(*String, *String) u8;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// https://developer.apple.com/documentation/corefoundation/cfstringencoding?language=objc
|
/// https://developer.apple.com/documentation/corefoundation/cfstringencoding?language=objc
|
||||||
@ -49,6 +54,13 @@ pub const StringEncoding = enum(u32) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
test "string" {
|
test "string" {
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
const str = try String.createWithBytes("hello world", .ascii, false);
|
const str = try String.createWithBytes("hello world", .ascii, false);
|
||||||
defer str.release();
|
defer str.release();
|
||||||
|
|
||||||
|
const prefix = try String.createWithBytes("hello", .ascii, false);
|
||||||
|
defer prefix.release();
|
||||||
|
|
||||||
|
try testing.expect(str.hasPrefix(prefix));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user