Skip to content

Instantly share code, notes, and snippets.

@Nublo
Created July 23, 2019 10:02
Show Gist options
  • Save Nublo/2862fac2815ccc3f72f8eef791644de5 to your computer and use it in GitHub Desktop.
Save Nublo/2862fac2815ccc3f72f8eef791644de5 to your computer and use it in GitHub Desktop.
class DigitsTrimStartFilter(private val max: Int) : InputFilter {
override fun filter(...): CharSequence? {
val s = source.subSequence(start, end).filter { it.isDigit() }
val keep = max - (dest.length - (dend - dstart))
return when {
keep <= 0 -> ""
keep >= s.length -> null // keep original
else -> s.subSequence(s.length - keep, s.length)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment