Skip to content

Instantly share code, notes, and snippets.

@eymar
Created August 26, 2017 11:11
Show Gist options
  • Save eymar/50d2e322fd28640facf1ae5a905547ca to your computer and use it in GitHub Desktop.
Save eymar/50d2e322fd28640facf1ae5a905547ca to your computer and use it in GitHub Desktop.
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