also looking at this
fix(android): text going to the JVM is modified UTF-8, and was not being
#168
12 files
+326
-136
| @@ -78,7 +78,7 @@ fn apply(j: Jni, edit: jobject) !void { | ||
| 78 | 78 | try j.callVoidMethodA(edit, try j.methodId(edit_cls, "apply", "()V"), &.{}); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | pub fn set(j: Jni, prefs: jobject, key: [*:0]const u8, value: [*:0]const u8) !void { | |
| 81 | pub fn set(j: Jni, allocator: std.mem.Allocator, prefs: jobject, key: []const u8, value: []const u8) !void { | |
| 82 | 82 | try j.pushLocalFrame(16); |
| 83 | 83 | defer _ = j.popLocalFrame(null); |
| 84 | 84 | |
| @@ -92,12 +92,12 @@ pub fn set(j: Jni, prefs: jobject, key: [*:0]const u8, value: [*:0]const u8) !vo | ||
| 92 | 92 | "putString", |
| 93 | 93 | "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;", |
| 94 | 94 | ), |
| 95 | &.{ .{ .l = try j.newStringUtf(key) }, .{ .l = try j.newStringUtf(value) } }, | |
| 95 | &.{ .{ .l = try j.newStringUtf8(allocator, key) }, .{ .l = try j.newStringUtf8(allocator, value) } }, | |
| 96 | 96 | ); |
| 97 | 97 | try apply(j, edit); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | pub fn remove(j: Jni, prefs: jobject, key: [*:0]const u8) !void { | |
| 100 | pub fn remove(j: Jni, allocator: std.mem.Allocator, prefs: jobject, key: []const u8) !void { | |
| 101 | 101 | try j.pushLocalFrame(16); |
| 102 | 102 | defer _ = j.popLocalFrame(null); |
| 103 | 103 | |
| @@ -107,7 +107,7 @@ pub fn remove(j: Jni, prefs: jobject, key: [*:0]const u8) !void { | ||
| 107 | 107 | _ = try j.callObjectMethodA( |
| 108 | 108 | edit, |
| 109 | 109 | try j.methodId(edit_cls, "remove", "(Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;"), |
| 110 | &.{.{ .l = try j.newStringUtf(key) }}, | |
| 110 | &.{.{ .l = try j.newStringUtf8(allocator, key) }}, | |
| 111 | 111 | ); |
| 112 | 112 | try apply(j, edit); |
| 113 | 113 | } |
| @@ -147,7 +147,7 @@ pub fn renderRead(allocator: std.mem.Allocator, value: ?[]const u8) ![]u8 { | ||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /// `prefs.getString(key, null)`, as an owned optional. Caller frees. |
| 150 | pub fn get(allocator: std.mem.Allocator, j: Jni, prefs: jobject, key: [*:0]const u8) !?[]u8 { | |
| 150 | pub fn get(allocator: std.mem.Allocator, j: Jni, prefs: jobject, key: []const u8) !?[]u8 { | |
| 151 | 151 | try j.pushLocalFrame(16); |
| 152 | 152 | defer _ = j.popLocalFrame(null); |
| 153 | 153 | |
| @@ -161,7 +161,7 @@ pub fn get(allocator: std.mem.Allocator, j: Jni, prefs: jobject, key: [*:0]const | ||
| 161 | 161 | ), |
| 162 | 162 | // The default is null, which is what makes "absent" distinguishable |
| 163 | 163 | // from a stored empty string. |
| 164 | &.{ .{ .l = try j.newStringUtf(key) }, .{ .l = null } }, | |
| 164 | &.{ .{ .l = try j.newStringUtf8(allocator, key) }, .{ .l = null } }, | |
| 165 | 165 | ); |
| 166 | 166 | if (value == null) return null; |
| 167 | 167 | return try j.stringToUtf8(allocator, value); |