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 { private func map(_ string: String) -> KotlinCharArray {
let array = KotlinCharArray(size: Int32(string.count)) return string.toKotlinCharArray()
for i in 0 ..< string.count {
array.set(index: Int32(i), value: (string as NSString).character(at: i))
}
return array
} }
} }

View File

@ -1,5 +1,6 @@
import SwiftUI import SwiftUI
import CoreData import CoreData
import BankingUiSwift
extension StringProtocol { extension StringProtocol {
@ -74,19 +75,46 @@ extension String {
} }
// TODO: implement passing multiple arguments to localize() // TODO: implement passing multiple arguments to localize()
// func localize(_ arguments: CVarArg...) -> String { // func localize(_ arguments: CVarArg...) -> String {
// return localize(arguments) // return localize(arguments)
// } // }
// //
// func localize(_ arguments: [CVarArg]) -> String { // func localize(_ arguments: [CVarArg]) -> String {
// return String(format: NSLocalizedString(self, comment: ""), arguments) // return String(format: NSLocalizedString(self, comment: ""), arguments)
// return String(format: NSLocalizedString(self, comment: ""), getVaList(arguments)) // return String(format: NSLocalizedString(self, comment: ""), getVaList(arguments))
// } // }
func localize(_ arguments: CVarArg) -> String { func localize(_ arguments: CVarArg) -> String {
return String(format: NSLocalizedString(self, comment: ""), arguments) 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))
}
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)
}
} }

View File

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