diff --git a/pkg/macos/foundation/url.zig b/pkg/macos/foundation/url.zig index 3917beff3..f0d71e26a 100644 --- a/pkg/macos/foundation/url.zig +++ b/pkg/macos/foundation/url.zig @@ -11,6 +11,17 @@ pub const URL = opaque { ) orelse error.OutOfMemory; } + pub fn createStringByReplacingPercentEscapes( + str: *foundation.String, + escape: *foundation.String, + ) Allocator.Error!*foundation.String { + return CFURLCreateStringByReplacingPercentEscapes( + null, + str, + escape, + ) orelse return error.OutOfMemory; + } + pub fn release(self: *URL) void { foundation.CFRelease(self); } @@ -25,6 +36,11 @@ pub const URL = opaque { base_url: ?*const anyopaque, ) ?*URL; pub extern "c" fn CFURLCopyPath(*URL) ?*foundation.String; + pub extern "c" fn CFURLCreateStringByReplacingPercentEscapes( + allocator: ?*anyopaque, + original: *const anyopaque, + escape: *const anyopaque, + ) ?*foundation.String; }; test { diff --git a/pkg/macos/text/font_collection.zig b/pkg/macos/text/font_collection.zig index 1b6168719..11ff499af 100644 --- a/pkg/macos/text/font_collection.zig +++ b/pkg/macos/text/font_collection.zig @@ -43,7 +43,28 @@ test "collection" { // const name = desc.copyAttribute(.name); // defer name.release(); // const cstr = name.cstring(&buf, .utf8).?; - // std.log.warn("i={d} v={s}", .{ i, cstr }); + // + // var buf2: [128]u8 = undefined; + // const url = desc.copyAttribute(.url); + // defer url.release(); + // const path = path: { + // const blank = try foundation.String.createWithBytes("", .utf8, false); + // defer blank.release(); + // + // const path = url.copyPath() orelse break :path ""; + // defer path.release(); + // + // const decoded = try foundation.URL.createStringByReplacingPercentEscapes( + // path, + // blank, + // ); + // defer decoded.release(); + // + // break :path decoded.cstring(&buf2, .utf8) orelse + // ""; + // }; + // + // std.log.warn("i={d} name={s} path={s}", .{ i, cstr, path }); // } // } }