Skip to content

Instantly share code, notes, and snippets.

@Oleur
Last active December 20, 2021 16:41
Show Gist options
  • Save Oleur/4c6c4d7fe31b0e754efc8720d3267dd2 to your computer and use it in GitHub Desktop.
Save Oleur/4c6c4d7fe31b0e754efc8720d3267dd2 to your computer and use it in GitHub Desktop.
Compose offsets for PhoneNumber VisualTransformation
val originalToTransformed = mutableListOf<Int>()
val transformedToOriginal = mutableListOf<Int>()
var specialCharsCount = 0
formatted?.forEachIndexed { index, char ->
if (!PhoneNumberUtils.isNonSeparator(char)) {
specialCharsCount++
} else {
originalToTransformed.add(index)
}
transformedToOriginal.add(index - specialCharsCount)
}
originalToTransformed.add(originalToTransformed.maxOrNull()?.plus(1) ?: 0)
transformedToOriginal.add(transformedToOriginal.maxOrNull()?.plus(1) ?: 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment