Generalize String extensions to take CharSequence as receiver and parameters where applicable.

This commit is contained in:
Ilya Gorbunov
2015-10-12 05:54:08 +03:00
parent 05615dd48b
commit 4a621cbb5f
5 changed files with 65 additions and 57 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
* the given function [transform] that takes [MatchResult] and returns a string to be used as a
* replacement for that match.
*/
public inline fun replace(input: CharSequence, transform: (MatchResult) -> String): String {
public inline fun replace(input: CharSequence, transform: (MatchResult) -> CharSequence): String {
var match = match(input)
if (match == null) return input.toString()
+1 -3
View File
@@ -43,9 +43,7 @@ public inline fun String.matches(regex : String) : Boolean {
return result != null && result.size() > 0
}
public inline fun CharSequence.isEmpty(): Boolean = this.length() == 0
public fun String.isBlank(): Boolean = length() == 0 || matches("^[\\s\\xA0]+$")
public fun CharSequence.isBlank(): Boolean = length() == 0 || (if (this is String) this else this.toString()).matches("^[\\s\\xA0]+$")
public fun String?.equals(anotherString: String?, ignoreCase: Boolean = false): Boolean =
if (this == null)