From 6f6bfd15ed1df0380105612315fef0a0717a0f0c Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 21 Nov 2018 18:04:11 +0300 Subject: [PATCH] Prepare to hide native specific regex methods from public API --- backend.native/tests/harmony_regex/PatternTest2.kt | 8 +++----- runtime/src/main/kotlin/kotlin/text/Regex.kt | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/backend.native/tests/harmony_regex/PatternTest2.kt b/backend.native/tests/harmony_regex/PatternTest2.kt index d72877b7bef..296961d9f74 100644 --- a/backend.native/tests/harmony_regex/PatternTest2.kt +++ b/backend.native/tests/harmony_regex/PatternTest2.kt @@ -32,13 +32,11 @@ class PatternTest2 { var testString = "foo123" assertTrue(regex.matches(testString)) - assertTrue(regex.containsMatchIn(testString, 0)) - assertTrue(regex.lookingAt(testString)) + assertTrue(regex in testString) testString = "fox" assertFalse(regex.matches(testString)) - assertFalse(regex.containsMatchIn(testString, 0)) - assertFalse(regex.lookingAt(testString)) + assertFalse(regex in testString) assertTrue(Regex("foo.*").matches("foo123")) assertFalse(Regex("foo.*").matches("fox")) @@ -880,7 +878,7 @@ class PatternTest2 { @Test fun testCompile2() { val findString = "\\Qimport\\E" val regex = Regex(findString) - regex.containsMatchIn("import a.A;\n\n import b.B;\nclass C {}", 0) + assertTrue(regex in "import a.A;\n\n import b.B;\nclass C {}") } @Test fun testCompile3() { diff --git a/runtime/src/main/kotlin/kotlin/text/Regex.kt b/runtime/src/main/kotlin/kotlin/text/Regex.kt index 603a6327cba..46945a2f26a 100644 --- a/runtime/src/main/kotlin/kotlin/text/Regex.kt +++ b/runtime/src/main/kotlin/kotlin/text/Regex.kt @@ -256,6 +256,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte * * @param replacement A replacement expression that can include substitutions. */ + @Suppress("DEPRECATION_ERROR") actual fun replaceFirst(input: CharSequence, replacement: String): String = replaceFirst(input) { match -> processReplacement(match, replacement) } @@ -297,9 +298,11 @@ public actual class Regex internal constructor(internal val nativePattern: Patte 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 /** @@ -307,6 +310,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte * 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