also looking at this
fix(android): text going to the JVM is modified UTF-8, and was not being
#168
12 files
+326
-136
| @@ -137,7 +137,7 @@ pub fn writeUpdate(j: Jni, allocator: std.mem.Allocator, activity: jobject, upda | ||
| 137 | 137 | defer _ = j.popLocalFrame(null); |
| 138 | 138 | _ = try j.callObjectMethodA(editor, put_string, &.{ |
| 139 | 139 | .{ .l = try j.newStringUtf(field.key) }, |
| 140 | .{ .l = try javaString(j, allocator, text) }, | |
| 140 | .{ .l = try j.newStringUtf8(allocator, text) }, | |
| 141 | 141 | }); |
| 142 | 142 | } |
| 143 | 143 | } |
| @@ -156,7 +156,7 @@ pub fn broadcast(j: Jni, allocator: std.mem.Allocator, activity: jobject, action | ||
| 156 | 156 | const intent = try j.newObjectA( |
| 157 | 157 | intent_cls, |
| 158 | 158 | try j.methodId(intent_cls, "<init>", "(Ljava/lang/String;)V"), |
| 159 | &.{.{ .l = try javaString(j, allocator, action) }}, | |
| 159 | &.{.{ .l = try j.newStringUtf8(allocator, action) }}, | |
| 160 | 160 | ); |
| 161 | 161 | |
| 162 | 162 | const activity_cls = try j.objectClass(activity); |
| @@ -181,13 +181,6 @@ pub fn broadcast(j: Jni, allocator: std.mem.Allocator, activity: jobject, action | ||
| 181 | 181 | ); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | fn javaString(j: Jni, allocator: std.mem.Allocator, text: []const u8) !jni.jstring { | |
| 185 | const terminated = try allocator.allocSentinel(u8, text.len, 0); | |
| 186 | defer allocator.free(terminated); | |
| 187 | @memcpy(terminated, text); | |
| 188 | return j.newStringUtf(terminated.ptr); | |
| 189 | } | |
| 190 | ||
| 191 | 184 | // ============================================================================= |
| 192 | 185 | // Tests |
| 193 | 186 | // ============================================================================= |