android-ktx icon indicating copy to clipboard operation
android-ktx copied to clipboard

Add SpannableString.overlay and .overlayAll to apply spans to substrings

Open shekibobo opened this issue 6 years ago • 5 comments

The overlay methods will apply a provided span to matching substrings of the receiver. In .overlay, it will apply to only the first matching occurrence, while .overlayAll will apply the span to all matching occurrences of the substring.

Because spans are not copyable, you provide a spanBuilder lambda to generate a new span to apply to each occurrence.

This supports case-insensitive matching.

shekibobo avatar Mar 05 '18 21:03 shekibobo

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
  • Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • The email used to register you as an authorized contributor must be the email used for the Git commit. Check your existing CLA data and verify that your email is set on your git commits.
  • The email used to register you as an authorized contributor must also be attached to your GitHub account.

googlebot avatar Mar 05 '18 21:03 googlebot

CLAs look good, thanks!

googlebot avatar Mar 06 '18 22:03 googlebot

Thanks! I just expanded the tests to get a little more coverage and a bit more specificity of each case. We now test the following for both methods:

  • No matches
  • Multiple matches
  • Case sensitivity
  • Start index
  • Multiple different spans applied successfully

shekibobo avatar Mar 07 '18 19:03 shekibobo

This is great. Thank you.

My biggest concern here is that the only thing Kotlin-specific is the fact that this is an extension function instead of a static method. I'm going to try to get this into the normal support library somewhere and then we can just hang it as an extension and alias.

JakeWharton avatar Mar 07 '18 22:03 JakeWharton

Okay, sounds awesome, thanks!

shekibobo avatar Mar 08 '18 12:03 shekibobo