Created
August 26, 2017 11:11
-
-
Save eymar/50d2e322fd28640facf1ae5a905547ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object VectorDrawableFixinator { | |
private val regexMap = mapOf("\n" to " ", | |
"(-)(\\.\\d)" to " -0$2", | |
" (\\.\\d)" to " 0$1", | |
"([a-z])(\\.\\d)" to "$1 0$2") | |
fun getContentWithFixedFloatingPoints(value: String): String { | |
var result = value as CharSequence | |
val prepareRegex = "(\\.\\d+)(\\.\\d)".toRegex() | |
while (result.contains(prepareRegex)) { | |
result = result.replace(prepareRegex, "$1 $2") // adds spaces | |
} | |
regexMap.forEach { | |
result = result.replace(it.key.toRegex(), it.value) | |
} | |
val finalRegex = "\\s{2,}".toRegex() | |
result = result.replace(finalRegex, " ") | |
return result.toString() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment