Remove Regex() and toRegex() overloads with vararg options. Now only zero, one or set of options are allowed.
This commit is contained in:
@@ -153,10 +153,13 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a regular expression from the specified [pattern] string and the specified [options].
|
||||
*/
|
||||
public fun Regex(pattern: String, vararg options: RegexOption): Regex = Regex(pattern, options.toSet())
|
||||
/** 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))
|
||||
|
||||
/** Creates a regular expression from the specified [pattern] string and the default options. */
|
||||
public fun Regex(pattern: String): Regex = Regex(pattern, emptySet())
|
||||
|
||||
|
||||
|
||||
|
||||
private fun RegExp.findNext(input: String, from: Int): MatchResult? {
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package kotlin
|
||||
|
||||
import kotlin.text.*
|
||||
|
||||
/**
|
||||
* Converts the string into a regular expression [Regex] with the specified [options].
|
||||
* Converts the string into a regular expression [Regex] with the default options.
|
||||
*/
|
||||
public fun String.toRegex(vararg options: RegexOption): Regex = Regex(this, *options)
|
||||
public fun String.toRegex(): Regex = Regex(this)
|
||||
|
||||
/**
|
||||
* Converts the string into a regular expression [Regex] with the specified single [option].
|
||||
*/
|
||||
public fun String.toRegex(option: RegexOption): Regex = Regex(this, option)
|
||||
|
||||
/**
|
||||
* Converts the string into a regular expression [Regex] with the specified set of [options].
|
||||
|
||||
@@ -90,11 +90,16 @@ public data class MatchGroup(public val value: String, public val range: IntRang
|
||||
*/
|
||||
public class Regex internal (private val nativePattern: Pattern) {
|
||||
|
||||
|
||||
/** Creates a regular expression from the specified [pattern] string and the default options. */
|
||||
public constructor(pattern: String): this(Pattern.compile(pattern))
|
||||
|
||||
/** Creates a regular expression from the specified [pattern] string and the specified single [option]. */
|
||||
public constructor(pattern: String, option: RegexOption): this(Pattern.compile(pattern, ensureUnicodeCase(option.value)))
|
||||
|
||||
/** Creates a regular expression from the specified [pattern] string and the specified set of [options]. */
|
||||
public constructor(pattern: String, options: Set<RegexOption>): this(Pattern.compile(pattern, ensureUnicodeCase(options.toInt())))
|
||||
|
||||
/** Creates a regular expression from the specified [pattern] string and the specified [options]. */
|
||||
public constructor(pattern: String, vararg options: RegexOption) : this(pattern, options.toSet())
|
||||
|
||||
/** The pattern string of this regular expression. */
|
||||
public val pattern: String
|
||||
@@ -189,7 +194,7 @@ public class Regex internal (private val nativePattern: Pattern) {
|
||||
|
||||
companion object {
|
||||
/** Returns a literal regex for the specified [literal] string. */
|
||||
public fun fromLiteral(literal: String): Regex = Regex(literal, RegexOption.LITERAL)
|
||||
public fun fromLiteral(literal: String): Regex = literal.toRegex(RegexOption.LITERAL)
|
||||
/** Returns a literal pattern for the specified [literal] string. */
|
||||
public fun escape(literal: String): String = Pattern.quote(literal)
|
||||
/** Returns a literal replacement expression for the specified [literal] string. */
|
||||
|
||||
@@ -87,7 +87,7 @@ class RegexTest {
|
||||
test fun escapeLiteral() {
|
||||
val literal = """[-\/\\^$*+?.()|[\]{}]"""
|
||||
assertTrue(Regex.fromLiteral(literal).matches(literal))
|
||||
assertTrue(Regex(Regex.escape(literal)).matches(literal))
|
||||
assertTrue(Regex.escape(literal).toRegex().matches(literal))
|
||||
}
|
||||
|
||||
test fun replace() {
|
||||
|
||||
Reference in New Issue
Block a user