| @@ -106,7 +106,7 @@ fn openPrefs(j: Jni, allocator: std.mem.Allocator, activity: jobject, group: []c |
| 106 | 106 | "getSharedPreferences", |
| 107 | 107 | "(Ljava/lang/String;I)Landroid/content/SharedPreferences;", |
| 108 | 108 | ), |
| 109 | | - &.{ .{ .l = try j.newStringUtf(name.ptr) }, .{ .i = mode_private } }, |
| 109 | + &.{ .{ .l = try j.newStringUtf8(allocator, name) }, .{ .i = mode_private } }, |
| 110 | 110 | ); |
| 111 | 111 | } |
| 112 | 112 | |
| @@ -134,8 +134,8 @@ pub fn set( |
| 134 | 134 | "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;", |
| 135 | 135 | ), |
| 136 | 136 | &.{ |
| 137 | | - .{ .l = try javaString(j, allocator, key) }, |
| 138 | | - .{ .l = try javaString(j, allocator, value) }, |
| 137 | + .{ .l = try j.newStringUtf8(allocator, key) }, |
| 138 | + .{ .l = try j.newStringUtf8(allocator, value) }, |
| 139 | 139 | }, |
| 140 | 140 | ); |
| 141 | 141 | |
| @@ -167,7 +167,7 @@ pub fn remove( |
| 167 | 167 | "remove", |
| 168 | 168 | "(Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;", |
| 169 | 169 | ), |
| 170 | | - &.{.{ .l = try javaString(j, allocator, key) }}, |
| 170 | + &.{.{ .l = try j.newStringUtf8(allocator, key) }}, |
| 171 | 171 | ); |
| 172 | 172 | try j.callVoidMethodA(editor, try j.methodId(editor_cls, "apply", "()V"), &.{}); |
| 173 | 173 | } |
| @@ -194,7 +194,7 @@ pub fn get( |
| 194 | 194 | "getString", |
| 195 | 195 | "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", |
| 196 | 196 | ), |
| 197 | | - &.{ .{ .l = try javaString(j, allocator, key) }, .{ .l = null } }, |
| 197 | + &.{ .{ .l = try j.newStringUtf8(allocator, key) }, .{ .l = null } }, |
| 198 | 198 | ); |
| 199 | 199 | |
| 200 | 200 | if (value == null) return null; |
| @@ -212,13 +212,6 @@ fn editorFor(j: Jni, prefs: jobject) !jobject { |
| 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 | // ============================================================================= |
| 223 | 216 | // Tests |
| 224 | 217 | // ============================================================================= |