also looking at this
fix(android): text going to the JVM is modified UTF-8, and was not being
#168
12 files
+326
-136
| @@ -136,7 +136,7 @@ pub fn execute(j: Jni, allocator: std.mem.Allocator, db: jobject, sql: []const u | ||
| 136 | 136 | try j.callVoidMethodA( |
| 137 | 137 | db, |
| 138 | 138 | try j.methodId(db_cls, "execSQL", "(Ljava/lang/String;[Ljava/lang/Object;)V"), |
| 139 | &.{ .{ .l = try javaString(j, allocator, sql) }, .{ .l = bind } }, | |
| 139 | &.{ .{ .l = try j.newStringUtf8(allocator, sql) }, .{ .l = bind } }, | |
| 140 | 140 | ); |
| 141 | 141 | } |
| 142 | 142 | |
| @@ -161,7 +161,7 @@ pub fn query( | ||
| 161 | 161 | "rawQuery", |
| 162 | 162 | "(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;", |
| 163 | 163 | ), |
| 164 | &.{ .{ .l = try javaString(j, allocator, sql) }, .{ .l = bind } }, | |
| 164 | &.{ .{ .l = try j.newStringUtf8(allocator, sql) }, .{ .l = bind } }, | |
| 165 | 165 | ); |
| 166 | 166 | |
| 167 | 167 | try out.append(allocator, '['); |
| @@ -212,20 +212,13 @@ pub fn query( | ||
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | fn javaString(j: Jni, allocator: std.mem.Allocator, text: []const u8) !jni.jstring { | |
| 216 | const terminated = try allocator.allocSentinel(u8, text.len, 0); | |
| 217 | defer allocator.free(terminated); | |
| 218 | @memcpy(terminated, text); | |
| 219 | return j.newStringUtf(terminated.ptr); | |
| 220 | } | |
| 221 | ||
| 222 | 215 | fn stringArray(j: Jni, allocator: std.mem.Allocator, values: []const []const u8) !jobject { |
| 223 | 216 | const string_cls = try j.findClass("java/lang/String"); |
| 224 | 217 | const array = try j.newObjectArray(values.len, string_cls); |
| 225 | 218 | for (values, 0..) |value, i| { |
| 226 | 219 | try j.pushLocalFrame(4); |
| 227 | 220 | defer _ = j.popLocalFrame(null); |
| 228 | try j.setObjectArrayElement(array, i, try javaString(j, allocator, value)); | |
| 221 | try j.setObjectArrayElement(array, i, try j.newStringUtf8(allocator, value)); | |
| 229 | 222 | } |
| 230 | 223 | return array; |
| 231 | 224 | } |