mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 00:35:26 +02:00
parent
0793f0a19b
commit
e6f74c56f8
@ -75,3 +75,15 @@ fun String.isExpression(): Boolean {
|
|||||||
// Rest of the string must be just like positive
|
// Rest of the string must be just like positive
|
||||||
return this.drop(1).isExpression()
|
return this.drop(1).isExpression()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun String.normalizeSuperscript(): String = this
|
||||||
|
.replace('⁰', '0')
|
||||||
|
.replace('¹', '1')
|
||||||
|
.replace('²', '2')
|
||||||
|
.replace('³', '3')
|
||||||
|
.replace('⁴', '4')
|
||||||
|
.replace('⁵', '5')
|
||||||
|
.replace('⁶', '6')
|
||||||
|
.replace('⁷', '7')
|
||||||
|
.replace('⁸', '8')
|
||||||
|
.replace('⁹', '9')
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.sadellie.unitto.data.common
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class NormalizeSuperscriptTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun normalizeSuperscript() {
|
||||||
|
val input = "⁰¹²³⁴⁵⁶⁷⁸⁹"
|
||||||
|
assertEquals("0123456789", input.normalizeSuperscript())
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ package com.sadellie.unitto.data.model.unit
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.sadellie.unitto.data.common.lev
|
import com.sadellie.unitto.data.common.lev
|
||||||
|
import com.sadellie.unitto.data.common.normalizeSuperscript
|
||||||
import com.sadellie.unitto.data.model.UnitGroup
|
import com.sadellie.unitto.data.model.UnitGroup
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
@ -52,7 +53,10 @@ fun Sequence<AbstractUnit>.filterByLev(stringA: String, context: Context): Seque
|
|||||||
// List of pair: Unit and it's levDist
|
// List of pair: Unit and it's levDist
|
||||||
val unitsWithDist = mutableListOf<Pair<AbstractUnit, Int>>()
|
val unitsWithDist = mutableListOf<Pair<AbstractUnit, Int>>()
|
||||||
this.forEach { unit ->
|
this.forEach { unit ->
|
||||||
val unitShortName: String = context.getString(unit.shortName).lowercase()
|
val unitShortName: String = context
|
||||||
|
.getString(unit.shortName)
|
||||||
|
.lowercase()
|
||||||
|
.normalizeSuperscript()
|
||||||
/**
|
/**
|
||||||
* There is a chance that we search for unit with a specific short name. Such cases are
|
* There is a chance that we search for unit with a specific short name. Such cases are
|
||||||
* should be higher in the list. Best possible match.
|
* should be higher in the list. Best possible match.
|
||||||
@ -62,7 +66,10 @@ fun Sequence<AbstractUnit>.filterByLev(stringA: String, context: Context): Seque
|
|||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
|
|
||||||
val unitFullName: String = context.getString(unit.displayName).lowercase()
|
val unitFullName: String = context
|
||||||
|
.getString(unit.displayName)
|
||||||
|
.lowercase()
|
||||||
|
.normalizeSuperscript()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There is chance that unit name doesn't need any edits (contains part of the query)
|
* There is chance that unit name doesn't need any edits (contains part of the query)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user