macos/text: more APIs

This commit is contained in:
Mitchell Hashimoto
2022-10-01 11:25:21 -07:00
parent 88ae3be9ef
commit 57c1d8d329
2 changed files with 38 additions and 1 deletions

View File

@ -11,6 +11,17 @@ pub const URL = opaque {
) orelse error.OutOfMemory; ) 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 { pub fn release(self: *URL) void {
foundation.CFRelease(self); foundation.CFRelease(self);
} }
@ -25,6 +36,11 @@ pub const URL = opaque {
base_url: ?*const anyopaque, base_url: ?*const anyopaque,
) ?*URL; ) ?*URL;
pub extern "c" fn CFURLCopyPath(*URL) ?*foundation.String; pub extern "c" fn CFURLCopyPath(*URL) ?*foundation.String;
pub extern "c" fn CFURLCreateStringByReplacingPercentEscapes(
allocator: ?*anyopaque,
original: *const anyopaque,
escape: *const anyopaque,
) ?*foundation.String;
}; };
test { test {

View File

@ -43,7 +43,28 @@ test "collection" {
// const name = desc.copyAttribute(.name); // const name = desc.copyAttribute(.name);
// defer name.release(); // defer name.release();
// const cstr = name.cstring(&buf, .utf8).?; // 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 "<no path>";
// defer path.release();
//
// const decoded = try foundation.URL.createStringByReplacingPercentEscapes(
// path,
// blank,
// );
// defer decoded.release();
//
// break :path decoded.cstring(&buf2, .utf8) orelse
// "<path cannot be converted to string>";
// };
//
// std.log.warn("i={d} name={s} path={s}", .{ i, cstr, path });
// } // }
// } // }
} }