[regex] Remove native-specific API
This commit is contained in:
committed by
Ilya Matveev
parent
aa0f0f169d
commit
6cacbfbc36
@@ -33,10 +33,12 @@ class PatternTest2 {
|
|||||||
var testString = "foo123"
|
var testString = "foo123"
|
||||||
assertTrue(regex.matches(testString))
|
assertTrue(regex.matches(testString))
|
||||||
assertTrue(regex in testString)
|
assertTrue(regex in testString)
|
||||||
|
assertTrue(regex.find(testString) != null)
|
||||||
|
|
||||||
testString = "fox"
|
testString = "fox"
|
||||||
assertFalse(regex.matches(testString))
|
assertFalse(regex.matches(testString))
|
||||||
assertFalse(regex in testString)
|
assertFalse(regex in testString)
|
||||||
|
assertFalse(regex.find(testString) != null)
|
||||||
|
|
||||||
assertTrue(Regex("foo.*").matches("foo123"))
|
assertTrue(Regex("foo.*").matches("foo123"))
|
||||||
assertFalse(Regex("foo.*").matches("fox"))
|
assertFalse(Regex("foo.*").matches("fox"))
|
||||||
|
|||||||
@@ -256,9 +256,17 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
|
|||||||
*
|
*
|
||||||
* @param replacement A replacement expression that can include substitutions.
|
* @param replacement A replacement expression that can include substitutions.
|
||||||
*/
|
*/
|
||||||
@Suppress("DEPRECATION_ERROR")
|
actual fun replaceFirst(input: CharSequence, replacement: String): String {
|
||||||
actual fun replaceFirst(input: CharSequence, replacement: String): String
|
val match = find(input) ?: return input.toString()
|
||||||
= replaceFirst(input) { match -> processReplacement(match, replacement) }
|
val length = input.length
|
||||||
|
val result = StringBuilder(length)
|
||||||
|
result.append(input, 0, match.range.start)
|
||||||
|
result.append(processReplacement(match, replacement))
|
||||||
|
if (match.range.endInclusive + 1 < length) {
|
||||||
|
result.append(input, match.range.endInclusive + 1, length)
|
||||||
|
}
|
||||||
|
return result.toString()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits the [input] CharSequence around matches of this regular expression.
|
* Splits the [input] CharSequence around matches of this regular expression.
|
||||||
@@ -296,30 +304,4 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
|
|||||||
* and may match strings differently.
|
* and may match strings differently.
|
||||||
*/
|
*/
|
||||||
override fun toString(): String = nativePattern.toString()
|
override fun toString(): String = nativePattern.toString()
|
||||||
|
|
||||||
// Native specific =================================================================================================
|
|
||||||
@Deprecated("The function is going to be removed from public API", level = DeprecationLevel.ERROR)
|
|
||||||
fun lookingAt(input: CharSequence): Boolean = doMatch(input, Mode.FIND) != null
|
|
||||||
|
|
||||||
/** Indicates whether the regular expression can find at least one match in the specified [input] starting with [index]. */
|
|
||||||
@Deprecated("The function is going to be removed from public API", level = DeprecationLevel.ERROR)
|
|
||||||
fun containsMatchIn(input: CharSequence, index: Int): Boolean = find(input, index) != null
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces the first occurrence of this regular expression in the specified [input] string with the result of calling
|
|
||||||
* the given function [transform] that takes a [MatchResult] representing the occurrence and returns a string to be used as a
|
|
||||||
* replacement for that occurrence.
|
|
||||||
*/
|
|
||||||
@Deprecated("The function is going to be removed from public API", level = DeprecationLevel.ERROR)
|
|
||||||
fun replaceFirst(input: CharSequence, transform: (MatchResult) -> CharSequence): String {
|
|
||||||
val match = find(input) ?: return input.toString()
|
|
||||||
val length = input.length
|
|
||||||
val result = StringBuilder(length)
|
|
||||||
result.append(input, 0, match.range.start)
|
|
||||||
result.append(transform(match))
|
|
||||||
if (match.range.endInclusive + 1 < length) {
|
|
||||||
result.append(input, match.range.endInclusive + 1, length)
|
|
||||||
}
|
|
||||||
return result.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user