Extracted extension methods to convert KotlinCharArray

This commit is contained in:
dankito 2020-10-16 16:22:20 +02:00
parent 08b7eb28a7
commit 82c0a5938e
3 changed files with 45 additions and 31 deletions

View File

@ -479,13 +479,7 @@ class AuthenticationService {
}
private func map(_ string: String) -> KotlinCharArray {
let array = KotlinCharArray(size: Int32(string.count))
for i in 0 ..< string.count {
array.set(index: Int32(i), value: (string as NSString).character(at: i))
}
return array
return string.toKotlinCharArray()
}
}

View File

@ -1,5 +1,6 @@
import SwiftUI
import CoreData
import BankingUiSwift
extension StringProtocol {
@ -69,26 +70,53 @@ extension StringProtocol {
extension String {
func localize() -> String {
return NSLocalizedString(self, comment: "")
func localize() -> String {
return NSLocalizedString(self, comment: "")
}
// TODO: implement passing multiple arguments to localize()
// func localize(_ arguments: CVarArg...) -> String {
// return localize(arguments)
// }
//
// func localize(_ arguments: [CVarArg]) -> String {
// return String(format: NSLocalizedString(self, comment: ""), arguments)
// return String(format: NSLocalizedString(self, comment: ""), getVaList(arguments))
// }
func localize(_ arguments: CVarArg) -> String {
return String(format: NSLocalizedString(self, comment: ""), arguments)
}
func toKotlinCharArray() -> KotlinCharArray {
let array = KotlinCharArray(size: Int32(self.count))
for i in 0 ..< self.count {
array.set(index: Int32(i), value: (self as NSString).character(at: i))
}
// TODO: implement passing multiple arguments to localize()
// func localize(_ arguments: CVarArg...) -> String {
// return localize(arguments)
// }
//
// func localize(_ arguments: [CVarArg]) -> String {
// return String(format: NSLocalizedString(self, comment: ""), arguments)
// return String(format: NSLocalizedString(self, comment: ""), getVaList(arguments))
// }
func localize(_ arguments: CVarArg) -> String {
return String(format: NSLocalizedString(self, comment: ""), arguments)
}
return array
}
}
extension KotlinCharArray {
func toString() -> String {
var mapped = [Character]()
for i in 0 ..< self.size {
if let scalar = Unicode.Scalar(self.get(index: i)) {
mapped.append(Character(scalar))
}
}
return String(mapped)
}
}
extension Optional where Wrapped == String {

View File

@ -86,15 +86,7 @@ class CoreDataBankingPersistence: IBankingPersistence, ITransactionPartySearcher
}
private func map(_ array: KotlinCharArray) -> String {
var mapped = [Character]()
for i in 0 ..< array.size {
if let scalar = Unicode.Scalar(array.get(index: i)) {
mapped.append(Character(scalar))
}
}
return String(mapped)
return array.toString()
}