Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snakeCaseToCamelCase localization issues #83

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
// App version
versionName = '2.0.1'
versionName = '2.0.2'
versionCode = 1

// SDK and tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.novasama.substrate_sdk_android.hash.isNegative
import java.math.BigInteger
import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.util.Locale

inline fun <T, R> Iterable<T>.tryFindNonNull(transform: (T) -> R?): R? {
for (item in this) {
Expand Down Expand Up @@ -108,7 +109,7 @@ fun ByteArray.split(divider: ByteArray): List<ByteArray> {
internal fun String.snakeCaseToCamelCase(): String {
return split("_").mapIndexed { index, segment ->
if (index > 0) { // do not capitalize first segment
segment.capitalize()
segment.capitalize(Locale.ROOT)
} else {
segment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.novasama.substrate_sdk_android.runtime.definitions.types.generics

import io.novasama.substrate_sdk_android.encrypt.EncryptionType
import io.novasama.substrate_sdk_android.runtime.definitions.types.composite.DictEnum
import java.util.Locale

class MultiSignature(val encryptionType: EncryptionType, val value: ByteArray)

Expand All @@ -16,7 +17,7 @@ fun Extrinsic.Signature.tryExtractMultiSignature(): MultiSignature? {
}

private val EncryptionType.multiSignatureName
get() = rawName.capitalize()
get() = rawName.capitalize(Locale.ROOT)

fun MultiSignature.prepareForEncoding(): Any {
return DictEnum.Entry(encryptionType.multiSignatureName, value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package io.novasama.substrate_sdk_android.extensions

import org.junit.Assert.*
import org.junit.Assert.assertEquals
import org.junit.Test
import java.util.Locale

class SnakeToCamelCaseTest {

@Test
fun test() {
fun shouldPerformConversion() {
runTest("", "")
runTest("test", "test")
runTest("one_two", "oneTwo")
runTest("one_two_three", "oneTwoThree")
}

@Test
fun shouldIgnoreLocale() {
// turkish languages is one of those who has exotic rules for letter capitalization, specifically for letter 'i'
Locale.setDefault(Locale("tr"))

runTest("fund_index", "fundIndex")
}

private fun runTest(
origin: String,
expected: String
Expand Down
Loading