[K/N] Internalize RegexOption.value/mask properties

As a part of efforts to stabilize K/N stdlib.
This commit is contained in:
Abduqodiri Qurbonzoda
2023-04-08 22:27:38 +03:00
committed by Space Team
parent 3a4a00ef84
commit 0d31b0d12c
@@ -7,13 +7,7 @@ package kotlin.text
import kotlin.text.regex.*
@PublishedApi
internal interface FlagEnum {
val value: Int
val mask: Int
}
private fun Iterable<FlagEnum>.toInt(): Int = this.fold(0, { value, option -> value or option.value })
private fun Iterable<RegexOption>.toInt(): Int = this.fold(0, { value, option -> value or option.value })
private fun fromInt(value: Int): Set<RegexOption> =
RegexOption.values().filterTo(mutableSetOf<RegexOption>()) { value and it.mask == it.value }
@@ -21,7 +15,7 @@ private fun fromInt(value: Int): Set<RegexOption> =
/**
* Provides enumeration values to use to set regular expression options.
*/
public actual enum class RegexOption(override val value: Int, override val mask: Int = value) : FlagEnum {
public actual enum class RegexOption(internal val value: Int, internal val mask: Int = value) {
// common
/** Enables case-insensitive matching. Case comparison is Unicode-aware. */
@@ -96,10 +90,10 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
actual constructor(pattern: String): this(Pattern(pattern))
/** Creates a regular expression from the specified [pattern] string and the specified single [option]. */
actual constructor(pattern: String, option: RegexOption): this(Pattern(pattern, ensureUnicodeCase(option.value)))
actual constructor(pattern: String, option: RegexOption): this(Pattern(pattern, option.value))
/** Creates a regular expression from the specified [pattern] string and the specified set of [options]. */
actual constructor(pattern: String, options: Set<RegexOption>): this(Pattern(pattern, ensureUnicodeCase(options.toInt())))
actual constructor(pattern: String, options: Set<RegexOption>): this(Pattern(pattern, options.toInt()))
/** The pattern string of this regular expression. */
@@ -142,9 +136,6 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
return result.toString()
}
// TODO: Remove
private fun ensureUnicodeCase(flags: Int) = flags
}
private fun doMatch(input: CharSequence, mode: Mode): MatchResult? {