also looking at this
fix(android): text going to the JVM is modified UTF-8, and was not being
#168
12 files
+326
-136
| @@ -270,7 +270,7 @@ fn queryUri( | ||
| 270 | 270 | for (args, 0..) |arg, i| { |
| 271 | 271 | // A null argument is a null element, which is what |
| 272 | 272 | // `arrayOf(contactId)` produces when the id was null. |
| 273 | const value: jni.jstring = if (arg) |text| try javaString(j, allocator, text) else null; | |
| 273 | const value: jni.jstring = if (arg) |text| try j.newStringUtf8(allocator, text) else null; | |
| 274 | 274 | try j.setObjectArrayElement(array, i, value); |
| 275 | 275 | } |
| 276 | 276 | break :blk array; |
| @@ -286,9 +286,9 @@ fn queryUri( | ||
| 286 | 286 | &.{ |
| 287 | 287 | .{ .l = uri }, |
| 288 | 288 | .{ .l = null }, |
| 289 | .{ .l = if (selection) |text| try javaString(j, allocator, text) else null }, | |
| 289 | .{ .l = if (selection) |text| try j.newStringUtf8(allocator, text) else null }, | |
| 290 | 290 | .{ .l = args_array }, |
| 291 | .{ .l = if (sort_order) |text| try javaString(j, allocator, text) else null }, | |
| 291 | .{ .l = if (sort_order) |text| try j.newStringUtf8(allocator, text) else null }, | |
| 292 | 292 | }, |
| 293 | 293 | ); |
| 294 | 294 | } |
| @@ -300,7 +300,7 @@ fn columnIndex(j: Jni, allocator: std.mem.Allocator, cursor: jobject, name: []co | ||
| 300 | 300 | return j.callIntMethodA( |
| 301 | 301 | cursor, |
| 302 | 302 | try j.methodId(try j.objectClass(cursor), "getColumnIndexOrThrow", "(Ljava/lang/String;)I"), |
| 303 | &.{.{ .l = try javaString(j, allocator, name) }}, | |
| 303 | &.{.{ .l = try j.newStringUtf8(allocator, name) }}, | |
| 304 | 304 | ); |
| 305 | 305 | } |
| 306 | 306 | |
| @@ -316,13 +316,6 @@ fn columnText( | ||
| 316 | 316 | return try j.stringToUtf8(allocator, value); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | fn javaString(j: Jni, allocator: std.mem.Allocator, text: []const u8) !jni.jstring { | |
| 320 | const terminated = try allocator.allocSentinel(u8, text.len, 0); | |
| 321 | defer allocator.free(terminated); | |
| 322 | @memcpy(terminated, text); | |
| 323 | return j.newStringUtf(terminated.ptr); | |
| 324 | } | |
| 325 | ||
| 326 | 319 | // ============================================================================= |
| 327 | 320 | // addContact |
| 328 | 321 | // ============================================================================= |
| @@ -471,7 +464,7 @@ pub fn addContact(j: Jni, allocator: std.mem.Allocator, activity: jobject, conta | ||
| 471 | 464 | "(Ljava/lang/String;Ljava/util/ArrayList;)[Landroid/content/ContentProviderResult;", |
| 472 | 465 | ), |
| 473 | 466 | &.{ |
| 474 | .{ .l = try javaString(j, allocator, contacts_authority) }, | |
| 467 | .{ .l = try j.newStringUtf8(allocator, contacts_authority) }, | |
| 475 | 468 | .{ .l = ops }, |
| 476 | 469 | }, |
| 477 | 470 | ); |
| @@ -535,11 +528,11 @@ fn appendDataRow( | ||
| 535 | 528 | "withValueBackReference", |
| 536 | 529 | "(Ljava/lang/String;I)Landroid/content/ContentProviderOperation$Builder;", |
| 537 | 530 | ), |
| 538 | &.{ .{ .l = try javaString(j, allocator, col_raw_contact_id) }, .{ .i = 0 } }, | |
| 531 | &.{ .{ .l = try j.newStringUtf8(allocator, col_raw_contact_id) }, .{ .i = 0 } }, | |
| 539 | 532 | ); |
| 540 | 533 | |
| 541 | 534 | _ = try withValue(j, allocator, builder, col_mimetype, item_type); |
| 542 | _ = try withValue(j, allocator, builder, row.value_column, try javaString(j, allocator, row.value)); | |
| 535 | _ = try withValue(j, allocator, builder, row.value_column, try j.newStringUtf8(allocator, row.value)); | |
| 543 | 536 | |
| 544 | 537 | if (row.type_value) |type_value| { |
| 545 | 538 | const integer_cls = try j.findClass("java/lang/Integer"); |
| @@ -581,7 +574,7 @@ fn withValue( | ||
| 581 | 574 | "withValue", |
| 582 | 575 | "(Ljava/lang/String;Ljava/lang/Object;)Landroid/content/ContentProviderOperation$Builder;", |
| 583 | 576 | ), |
| 584 | &.{ .{ .l = try javaString(j, allocator, column) }, .{ .l = value } }, | |
| 577 | &.{ .{ .l = try j.newStringUtf8(allocator, column) }, .{ .l = value } }, | |
| 585 | 578 | ); |
| 586 | 579 | } |
| 587 | 580 | |