Drop deprecated API: String operations.
This commit is contained in:
@@ -8,14 +8,6 @@ import java.util.NoSuchElementException
|
||||
import kotlin.text.MatchResult
|
||||
import kotlin.text.Regex
|
||||
|
||||
/** Returns the string with leading and trailing text matching the given string removed */
|
||||
@Deprecated("Use removeSurrounding(text, text) or removePrefix(text).removeSuffix(text)")
|
||||
public fun String.trim(text: String): String = removePrefix(text).removeSuffix(text)
|
||||
|
||||
/** Returns the string with the prefix and postfix text trimmed */
|
||||
@Deprecated("Use removeSurrounding(prefix, suffix) or removePrefix(prefix).removeSuffix(suffix)")
|
||||
public fun String.trim(prefix: String, postfix: String): String = removePrefix(prefix).removeSuffix(postfix)
|
||||
|
||||
/**
|
||||
* Returns the string with leading and trailing characters matching the [predicate] trimmed.
|
||||
*/
|
||||
@@ -82,12 +74,6 @@ public fun String.trimStart(vararg chars: Char): String = trimStart { it in char
|
||||
*/
|
||||
public fun String.trimEnd(vararg chars: Char): String = trimEnd { it in chars }
|
||||
|
||||
@Deprecated("Use removePrefix() instead", ReplaceWith("removePrefix(prefix)"))
|
||||
public fun String.trimLeading(prefix: String): String = removePrefix(prefix)
|
||||
|
||||
@Deprecated("Use removeSuffix() instead", ReplaceWith("removeSuffix(postfix)"))
|
||||
public fun String.trimTrailing(postfix: String): String = removeSuffix(postfix)
|
||||
|
||||
/**
|
||||
* Returns a string with leading and trailing whitespace trimmed.
|
||||
*/
|
||||
@@ -98,17 +84,11 @@ public fun String.trim(): String = trim { it.isWhitespace() }
|
||||
*/
|
||||
public fun String.trimStart(): String = trimStart { it.isWhitespace() }
|
||||
|
||||
@Deprecated("Use trimStart instead.", ReplaceWith("trimStart()"))
|
||||
public fun String.trimLeading(): String = trimStart { it.isWhitespace() }
|
||||
|
||||
/**
|
||||
* Returns a string with trailing whitespace removed.
|
||||
*/
|
||||
public fun String.trimEnd(): String = trimEnd { it.isWhitespace() }
|
||||
|
||||
@Deprecated("Use trimEnd instead.", ReplaceWith("trimEnd()"))
|
||||
public fun String.trimTrailing(): String = trimEnd { it.isWhitespace() }
|
||||
|
||||
/**
|
||||
* Left pad a String with a specified character or space.
|
||||
*
|
||||
@@ -923,10 +903,6 @@ public fun String.splitToSequence(vararg delimiters: String, ignoreCase: Boolean
|
||||
public fun String.split(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): List<String> =
|
||||
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList()
|
||||
|
||||
@Deprecated("Use split(delimiters) instead.", ReplaceWith("split(*delimiters, ignoreCase = ignoreCase, limit = limit)"))
|
||||
public fun String.splitBy(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): List<String> =
|
||||
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList()
|
||||
|
||||
/**
|
||||
* Splits this string to a sequence of strings around occurrences of the specified [delimiters].
|
||||
*
|
||||
|
||||
@@ -29,13 +29,6 @@ internal fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = (this as
|
||||
*/
|
||||
internal fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int = (this as java.lang.String).lastIndexOf(str, fromIndex)
|
||||
|
||||
|
||||
/**
|
||||
* Compares this string to another string, ignoring case considerations.
|
||||
*/
|
||||
@Deprecated("Use equals(anotherString, ignoreCase = true) instead", ReplaceWith("equals(anotherString, ignoreCase = true)"))
|
||||
public fun String.equalsIgnoreCase(anotherString: String): Boolean = equals(anotherString, ignoreCase = true)
|
||||
|
||||
/**
|
||||
* Returns `true` if this string is equal to [anotherString], optionally ignoring character case.
|
||||
*
|
||||
@@ -83,16 +76,6 @@ public fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: B
|
||||
return if (index < 0) this else this.replaceRange(index, index + oldValue.length(), newValue)
|
||||
}
|
||||
|
||||
@Deprecated("Use String.replaceFirst instead.", ReplaceWith("replaceFirst(oldValue, newValue, ignoreCase = ignoreCase)"))
|
||||
public fun String.replaceFirstLiteral(oldValue: String, newValue: String, ignoreCase: Boolean = false): String = replaceFirst(oldValue, newValue, ignoreCase = ignoreCase)
|
||||
|
||||
/**
|
||||
* Returns a new string obtained by replacing each substring of this string that matches the given regular expression
|
||||
* with the given [replacement].
|
||||
*/
|
||||
@Deprecated("Use String.replace(Regex, String) instead. You can convert regex parameter with .toRegex() extension function.", ReplaceWith("replace(regex.toRegex(), replacement)"))
|
||||
public fun String.replaceAll(regex: String, replacement: String): String = (this as java.lang.String).replaceAll(regex, replacement)
|
||||
|
||||
/**
|
||||
* Returns a copy of this string converted to upper case using the rules of the default locale.
|
||||
*/
|
||||
@@ -270,12 +253,6 @@ public fun String.codePointBefore(index: Int): Int = (this as java.lang.String).
|
||||
*/
|
||||
public fun String.codePointCount(beginIndex: Int, endIndex: Int): Int = (this as java.lang.String).codePointCount(beginIndex, endIndex)
|
||||
|
||||
/**
|
||||
* Compares two strings lexicographically, ignoring case differences.
|
||||
*/
|
||||
@Deprecated("Use compareTo with true passed to ignoreCase parameter.", ReplaceWith("compareTo(str, ignoreCase = true)"))
|
||||
public fun String.compareToIgnoreCase(str: String): Int = (this as java.lang.String).compareToIgnoreCase(str)
|
||||
|
||||
/**
|
||||
* Compares two strings lexicographically, optionally ignoring case differences.
|
||||
*/
|
||||
@@ -321,28 +298,11 @@ public fun String.intern(): String = (this as java.lang.String).intern()
|
||||
*/
|
||||
public fun String.isBlank(): Boolean = length() == 0 || all { it.isWhitespace() }
|
||||
|
||||
/**
|
||||
* Returns `true` if this string matches the given regular expression.
|
||||
*/
|
||||
@Deprecated("Use String.matches(Regex) instead. You can convert regex parameter with .toRegex() extension function.", ReplaceWith("matches(regex.toRegex())"))
|
||||
public fun String.matches(regex: String): Boolean = (this as java.lang.String).matches(regex)
|
||||
|
||||
/**
|
||||
* Returns the index within this string that is offset from the given [index] by [codePointOffset] code points.
|
||||
*/
|
||||
public fun String.offsetByCodePoints(index: Int, codePointOffset: Int): Int = (this as java.lang.String).offsetByCodePoints(index, codePointOffset)
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified range in this string is equal to the specified range in another string.
|
||||
* @param ignoreCase if `true`, character case is ignored when comparing.
|
||||
* @param toffset the start offset in this string of the substring to compare.
|
||||
* @param other the string against a substring of which the comparison is performed.
|
||||
* @param ooffset the start offset in the other string of the substring to compare.
|
||||
* @param len the length of the substring to compare.
|
||||
*/
|
||||
@Deprecated("Use regionMatches overload with ignoreCase as optional last parameter.", ReplaceWith("regionMatches(toffset, other, ooffset, len, ignoreCase)"))
|
||||
public fun String.regionMatches(ignoreCase: Boolean, toffset: Int, other: String, ooffset: Int, len: Int): Boolean = (this as java.lang.String).regionMatches(ignoreCase, toffset, other, ooffset, len)
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified range in this string is equal to the specified range in another string.
|
||||
* @param thisOffset the start offset in this string of the substring to compare.
|
||||
@@ -424,15 +384,6 @@ public fun String.toByteArray(charset: String): ByteArray = (this as java.lang.S
|
||||
*/
|
||||
public fun String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray = (this as java.lang.String).getBytes(charset)
|
||||
|
||||
@Deprecated("Use toByteArray() instead to emphasize copy behaviour", ReplaceWith("toByteArray()"))
|
||||
public fun String.getBytes(): ByteArray = (this as java.lang.String).getBytes()
|
||||
|
||||
@Deprecated("Use toByteArray(charset) instead to emphasize copy behaviour", ReplaceWith("toByteArray(charset)"))
|
||||
public fun String.getBytes(charset: Charset): ByteArray = (this as java.lang.String).getBytes(charset)
|
||||
|
||||
@Deprecated("Use toByteArray(charset) instead to emphasize copy behaviour", ReplaceWith("toByteArray(charset)"))
|
||||
public fun String.getBytes(charset: String): ByteArray = (this as java.lang.String).getBytes(charset)
|
||||
|
||||
/**
|
||||
* Returns a subsequence of this sequence specified by given [range].
|
||||
*/
|
||||
@@ -449,13 +400,6 @@ public fun String.toPattern(flags: Int = 0): java.util.regex.Pattern {
|
||||
return java.util.regex.Pattern.compile(this, flags)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new [StringReader] for reading the contents of this string.
|
||||
*/
|
||||
@Deprecated("Use reader() method instead in kotlin.io package", ReplaceWith("this.reader()", "kotlin.io.reader"))
|
||||
public val String.reader: StringReader
|
||||
get() = StringReader(this)
|
||||
|
||||
/**
|
||||
* Returns a copy of this string having its first letter uppercased, or the original string,
|
||||
* if it's empty or already starts with an upper case letter.
|
||||
@@ -517,31 +461,6 @@ public inline fun <T : Appendable> String.takeWhileTo(result: T, predicate: (Cha
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces every [regexp] occurence in the text with the value returned by the given function [body] that
|
||||
* takes a [MatchResult].
|
||||
*/
|
||||
@Deprecated("Use String.replace(Regex, (MatchResult)->String) instead. You can convert regex parameter with .toRegex() extension function.")
|
||||
public fun String.replaceAll(regexp: String, body: (java.util.regex.MatchResult) -> String): String {
|
||||
val sb = StringBuilder(this.length())
|
||||
val p = regexp.toPattern()
|
||||
val m = p.matcher(this)
|
||||
|
||||
var lastIdx = 0
|
||||
while (m.find()) {
|
||||
sb.append(this, lastIdx, m.start())
|
||||
sb.append(body(m.toMatchResult()))
|
||||
lastIdx = m.end()
|
||||
}
|
||||
|
||||
if (lastIdx == 0) {
|
||||
return this;
|
||||
}
|
||||
|
||||
sb.append(this, lastIdx, this.length())
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* A Comparator that orders strings ignoring character case.
|
||||
|
||||
@@ -206,16 +206,6 @@ public class Regex internal constructor(private val nativePattern: Pattern) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this [Pattern] to an instance of [Regex].
|
||||
*
|
||||
* Provides the way to use Regex API on the instances of [Pattern].
|
||||
*/
|
||||
@Deprecated("Use extension toRegex instead in kotlin package.")
|
||||
@HiddenDeclaration
|
||||
public fun Pattern.toRegex(): Regex = Regex(this)
|
||||
|
||||
|
||||
// implementation
|
||||
|
||||
private fun Matcher.findNext(from: Int, input: CharSequence): MatchResult? {
|
||||
|
||||
Reference in New Issue
Block a user