Rename Pattern to Regex.

toRegex now converts string to our regex, and toPattern converts to JVM Pattern.
This commit is contained in:
Ilya Gorbunov
2015-04-09 16:16:52 +03:00
parent a4784dfa78
commit 559c1604d7
13 changed files with 52 additions and 50 deletions
@@ -19,19 +19,19 @@ package kotlin.text
private val TODO: Nothing get() = throw java.lang.UnsupportedOperationException()
public enum class PatternOption(val value: String) {
IGNORE_CASE : PatternOption("i")
MULTILINE : PatternOption("m")
public enum class RegexOption(val value: String) {
IGNORE_CASE : RegexOption("i")
MULTILINE : RegexOption("m")
}
public data class MatchGroup(val value: String)
public class Pattern (pattern: String, options: Set<PatternOption>) {
public class Regex(pattern: String, options: Set<RegexOption>) {
public val pattern: String = pattern
public val options: Set<PatternOption> = options.toSet()
public val options: Set<RegexOption> = options.toSet()
private val nativePattern: RegExp = RegExp(pattern, options.map { it.value }.joinToString() + "g")
@@ -52,13 +52,13 @@ public class Pattern (pattern: String, options: Set<PatternOption>) {
public override fun toString(): String = nativePattern.toString()
companion object {
public fun fromLiteral(literal: String): Pattern = Pattern(escape(literal))
public fun fromLiteral(literal: String): Regex = Regex(escape(literal))
public fun escape(literal: String): String = TODO
public fun escapeReplacement(literal: String): String = literal.nativeReplace(RegExp("\\$", "g"), "$$$$")
}
}
public fun Pattern(pattern: String, vararg options: PatternOption): Pattern = Pattern(pattern, options.toSet())
public fun Regex(pattern: String, vararg options: RegexOption): Regex = Regex(pattern, options.toSet())
private fun RegExp.findNext(input: String, from: Int): MatchResult? {
+4 -4
View File
@@ -19,19 +19,19 @@ public fun String.nativeStartsWith(s: String, position: Int): Boolean = noImpl
native("endsWith")
public fun String.nativeEndsWith(s: String): Boolean = noImpl
deprecated("Use split(Pattern) instead.")
deprecated("Use split(Regex) instead.")
library("splitString")
public fun String.splitWithRegex(regex: String): Array<String> = noImpl
deprecated("Use split(Pattern) instead.")
deprecated("Use split(Regex) instead.")
library("splitString")
public fun String.splitWithRegex(regex: String, limit: Int): Array<String> = noImpl
deprecated("Use split(Pattern) instead.")
deprecated("Use split(Regex) instead.")
library("splitString")
public fun String.split(regex: String): Array<String> = noImpl
deprecated("Use split(Pattern) instead.")
deprecated("Use split(Regex) instead.")
library("splitString")
public fun String.split(regex: String, limit: Int): Array<String> = noImpl
+2 -2
View File
@@ -81,7 +81,7 @@ public inline fun String.decapitalize(): String {
public fun String.replace(oldValue: String, newValue: String): String =
nativeReplace(RegExp(kotlin.text.Pattern.escape(oldValue),"g"), kotlin.text.Pattern.escapeReplacement(newValue))
nativeReplace(RegExp(kotlin.text.Regex.escape(oldValue),"g"), kotlin.text.Regex.escapeReplacement(newValue))
public fun String.replace(oldChar: Char, newChar: Char): String =
nativeReplace(RegExp(kotlin.text.Pattern.escape(oldChar.toString()),"g"), newChar.toString())
nativeReplace(RegExp(kotlin.text.Regex.escape(oldChar.toString()),"g"), newChar.toString())