Rename Regex.hasMatch to containsMatchIn, and add corresponding contains function to CharSequence.
This commit is contained in:
@@ -777,6 +777,12 @@ public operator fun String.contains(seq: CharSequence, ignoreCase: Boolean = fal
|
||||
public operator fun String.contains(char: Char, ignoreCase: Boolean = false): Boolean =
|
||||
indexOf(char, ignoreCase = ignoreCase) >= 0
|
||||
|
||||
/**
|
||||
* Returns `true` if this string contains at least one match of the specified regular expression [regex].
|
||||
*/
|
||||
public operator fun CharSequence.contains(regex: Regex): Boolean = regex.containsMatchIn(this)
|
||||
|
||||
|
||||
// rangesDelimitedBy
|
||||
|
||||
|
||||
|
||||
@@ -114,8 +114,11 @@ public class Regex internal constructor(private val nativePattern: Pattern) {
|
||||
/** Indicates whether the regular expression matches the entire [input]. */
|
||||
public fun matches(input: CharSequence): Boolean = nativePattern.matcher(input).matches()
|
||||
|
||||
/** Indicates whether the regular expression can find at least a match in the specified [input]. */
|
||||
public fun hasMatch(input: CharSequence): Boolean = nativePattern.matcher(input).find()
|
||||
/** Indicates whether the regular expression can find at least one match in the specified [input]. */
|
||||
public fun containsMatchIn(input: CharSequence): Boolean = nativePattern.matcher(input).find()
|
||||
|
||||
@Deprecated("Use containsMatchIn() or 'in' operator instead.", ReplaceWith("this in input"))
|
||||
public fun hasMatch(input: CharSequence): Boolean = containsMatchIn(input)
|
||||
|
||||
/**
|
||||
* Returns the first match of a regular expression in the [input], beginning at the specified [startIndex].
|
||||
|
||||
@@ -14,7 +14,7 @@ class RegexTest {
|
||||
assertFalse(input.matches(p))
|
||||
assertFalse(p.matches(input))
|
||||
|
||||
assertTrue(p.hasMatch(input))
|
||||
assertTrue(p in input)
|
||||
|
||||
val first = p.find(input)
|
||||
assertTrue(first != null); first!!
|
||||
|
||||
Reference in New Issue
Block a user