Replace Regex constructor-like functions with secondary constructors

Historically secondary constructors were not supported in Kotlin/JS, so they had to
be emulated with constructor-like top level functions, now they can be rewritten
as true secondary constructors.

#KT-22003 Fixed
This commit is contained in:
Ilya Gorbunov
2017-12-22 21:48:08 +03:00
parent 053f3b6ac0
commit d9edc5f221
+13 -2
View File
@@ -45,6 +45,13 @@ public data class MatchGroup(val value: String)
*/
public class Regex(pattern: String, options: Set<RegexOption>) {
/** Creates a regular expression from the specified [pattern] string and the specified single [option]. */
public constructor(pattern: String, option: RegexOption) : this(pattern, setOf(option))
/** Creates a regular expression from the specified [pattern] string and the default options. */
public constructor(pattern: String) : this(pattern, emptySet())
/** The pattern string of this regular expression. */
public val pattern: String = pattern
/** The set of options that were used to create this regular expression. */
@@ -170,10 +177,14 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
}
/** Creates a regular expression from the specified [pattern] string and the specified single [option]. */
public fun Regex(pattern: String, option: RegexOption): Regex = Regex(pattern, setOf(option))
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JsName("Regex_sb3q2\$")
public fun Regex_0(pattern: String, option: RegexOption): Regex = Regex(pattern, setOf(option))
/** Creates a regular expression from the specified [pattern] string and the default options. */
public fun Regex(pattern: String): Regex = Regex(pattern, emptySet())
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JsName("Regex_61zpoe\$")
public fun Regex_1(pattern: String): Regex = Regex(pattern, emptySet())