mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-04 17:06:33 +00:00
macos/foundation: more string funcs
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
pub usingnamespace @import("foundation/array.zig");
|
pub usingnamespace @import("foundation/array.zig");
|
||||||
|
pub usingnamespace @import("foundation/base.zig");
|
||||||
pub usingnamespace @import("foundation/dictionary.zig");
|
pub usingnamespace @import("foundation/dictionary.zig");
|
||||||
pub usingnamespace @import("foundation/string.zig");
|
pub usingnamespace @import("foundation/string.zig");
|
||||||
pub usingnamespace @import("foundation/type.zig");
|
pub usingnamespace @import("foundation/type.zig");
|
||||||
|
5
pkg/macos/foundation/base.zig
Normal file
5
pkg/macos/foundation/base.zig
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
pub const ComparisonResult = enum(c_int) {
|
||||||
|
less = -1,
|
||||||
|
equal = 0,
|
||||||
|
greater = 1,
|
||||||
|
};
|
@@ -1,6 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const cftype = @import("type.zig");
|
const foundation = @import("../foundation.zig");
|
||||||
|
|
||||||
pub const String = opaque {
|
pub const String = opaque {
|
||||||
pub fn createWithBytes(
|
pub fn createWithBytes(
|
||||||
@@ -18,13 +18,24 @@ pub const String = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn release(self: *String) void {
|
pub fn release(self: *String) void {
|
||||||
cftype.CFRelease(self);
|
foundation.CFRelease(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hasPrefix(self: *String, prefix: *String) bool {
|
pub fn hasPrefix(self: *String, prefix: *String) bool {
|
||||||
return CFStringHasPrefix(self, prefix) == 1;
|
return CFStringHasPrefix(self, prefix) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn compare(
|
||||||
|
self: *String,
|
||||||
|
other: *String,
|
||||||
|
options: StringComparison,
|
||||||
|
) foundation.ComparisonResult {
|
||||||
|
return @intToEnum(
|
||||||
|
foundation.ComparisonResult,
|
||||||
|
CFStringCompare(self, other, @bitCast(c_int, options)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub extern "c" fn CFStringCreateWithBytes(
|
pub extern "c" fn CFStringCreateWithBytes(
|
||||||
allocator: ?*anyopaque,
|
allocator: ?*anyopaque,
|
||||||
bytes: [*]const u8,
|
bytes: [*]const u8,
|
||||||
@@ -33,6 +44,25 @@ pub const String = opaque {
|
|||||||
is_external: bool,
|
is_external: bool,
|
||||||
) ?*String;
|
) ?*String;
|
||||||
pub extern "c" fn CFStringHasPrefix(*String, *String) u8;
|
pub extern "c" fn CFStringHasPrefix(*String, *String) u8;
|
||||||
|
pub extern "c" fn CFStringCompare(*String, *String, c_int) c_int;
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const StringComparison = packed struct {
|
||||||
|
case_insensitive: bool = false,
|
||||||
|
_unused_2: bool = false,
|
||||||
|
backwards: bool = false,
|
||||||
|
anchored: bool = false,
|
||||||
|
nonliteral: bool = false,
|
||||||
|
localized: bool = false,
|
||||||
|
numerically: bool = false,
|
||||||
|
diacritic_insensitive: bool = false,
|
||||||
|
width_insensitive: bool = false,
|
||||||
|
forced_ordering: bool = false,
|
||||||
|
_padding: u22 = 0,
|
||||||
|
|
||||||
|
test {
|
||||||
|
try std.testing.expectEqual(@bitSizeOf(c_int), @bitSizeOf(StringComparison));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// https://developer.apple.com/documentation/corefoundation/cfstringencoding?language=objc
|
/// https://developer.apple.com/documentation/corefoundation/cfstringencoding?language=objc
|
||||||
@@ -63,4 +93,5 @@ test "string" {
|
|||||||
defer prefix.release();
|
defer prefix.release();
|
||||||
|
|
||||||
try testing.expect(str.hasPrefix(prefix));
|
try testing.expect(str.hasPrefix(prefix));
|
||||||
|
try testing.expectEqual(foundation.ComparisonResult.equal, str.compare(str, .{}));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user