Restore default values in actual functions that have default values in expect

Suppress error about default argument values in actuals.
The suppression can be removed when/if KT-23548 is implemented.

This is to avoid degrading experience in docs and IDE when working with
these functions.
This commit is contained in:
Ilya Gorbunov
2018-04-12 17:38:42 +03:00
parent f7546c809d
commit 9c7fefba69
4 changed files with 36 additions and 18 deletions
+6 -3
View File
@@ -76,11 +76,13 @@ public actual class Regex actual constructor(pattern: String, options: Set<Regex
* @param startIndex An index to start search with, by default 0. Must be not less than zero and not greater than `input.length()` * @param startIndex An index to start search with, by default 0. Must be not less than zero and not greater than `input.length()`
* @return An instance of [MatchResult] if match was found or `null` otherwise. * @return An instance of [MatchResult] if match was found or `null` otherwise.
*/ */
public actual fun find(input: CharSequence, startIndex: Int /*= 0*/): MatchResult? = nativePattern.findNext(input.toString(), startIndex) @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = nativePattern.findNext(input.toString(), startIndex)
/** Returns a sequence of all occurrences of a regular expression within the [input] string, beginning at the specified [startIndex]. /** Returns a sequence of all occurrences of a regular expression within the [input] string, beginning at the specified [startIndex].
*/ */
public actual fun findAll(input: CharSequence, startIndex: Int /*= 0*/): Sequence<MatchResult> = generateSequence({ find(input, startIndex) }, { match -> match.next() }) @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = generateSequence({ find(input, startIndex) }, { match -> match.next() })
/** /**
* Attempts to match the entire [input] CharSequence against the pattern. * Attempts to match the entire [input] CharSequence against the pattern.
@@ -144,7 +146,8 @@ public actual class Regex actual constructor(pattern: String, options: Set<Regex
* *
* @param limit The maximum number of times the split can occur. * @param limit The maximum number of times the split can occur.
*/ */
public actual fun split(input: CharSequence, limit: Int /*= 0*/): List<String> { @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun split(input: CharSequence, limit: Int = 0): List<String> {
require(limit >= 0) { "Limit must be non-negative, but was $limit" } require(limit >= 0) { "Limit must be non-negative, but was $limit" }
val matches = findAll(input).let { if (limit == 0) it else it.take(limit - 1) } val matches = findAll(input).let { if (limit == 0) it else it.take(limit - 1) }
val result = mutableListOf<String>() val result = mutableListOf<String>()
+12 -6
View File
@@ -46,7 +46,8 @@ public fun String.matches(regex: String): Boolean {
public actual fun CharSequence.isBlank(): Boolean = length == 0 || (if (this is String) this else this.toString()).matches("^[\\s\\xA0]+$") public actual fun CharSequence.isBlank(): Boolean = length == 0 || (if (this is String) this else this.toString()).matches("^[\\s\\xA0]+$")
public actual fun String?.equals(other: String?, ignoreCase: Boolean /*= false*/): Boolean = @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String?.equals(other: String?, ignoreCase: Boolean = false): Boolean =
if (this == null) if (this == null)
other == null other == null
else if (!ignoreCase) else if (!ignoreCase)
@@ -55,7 +56,8 @@ public actual fun String?.equals(other: String?, ignoreCase: Boolean /*= false*/
other != null && this.toLowerCase() == other.toLowerCase() other != null && this.toLowerCase() == other.toLowerCase()
public actual fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean /*= false*/): Boolean @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean
= regionMatchesImpl(thisOffset, other, otherOffset, length, ignoreCase) = regionMatchesImpl(thisOffset, other, otherOffset, length, ignoreCase)
@@ -107,14 +109,18 @@ public actual fun CharSequence.repeat(n: Int): String {
} }
} }
public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean /*= false*/): String = @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String =
nativeReplace(RegExp(Regex.escape(oldValue), if (ignoreCase) "gi" else "g"), Regex.escapeReplacement(newValue)) nativeReplace(RegExp(Regex.escape(oldValue), if (ignoreCase) "gi" else "g"), Regex.escapeReplacement(newValue))
public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean /*= false*/): String = @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String =
nativeReplace(RegExp(Regex.escape(oldChar.toString()), if (ignoreCase) "gi" else "g"), newChar.toString()) nativeReplace(RegExp(Regex.escape(oldChar.toString()), if (ignoreCase) "gi" else "g"), newChar.toString())
public actual fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean /*= false*/): String = @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean = false): String =
nativeReplace(RegExp(Regex.escape(oldValue), if (ignoreCase) "i" else ""), Regex.escapeReplacement(newValue)) nativeReplace(RegExp(Regex.escape(oldValue), if (ignoreCase) "i" else ""), Regex.escapeReplacement(newValue))
public actual fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean /*= false*/): String = @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String =
nativeReplace(RegExp(Regex.escape(oldChar.toString()), if (ignoreCase) "i" else ""), newChar.toString()) nativeReplace(RegExp(Regex.escape(oldChar.toString()), if (ignoreCase) "i" else ""), newChar.toString())
@@ -39,7 +39,8 @@ internal actual inline fun String.nativeLastIndexOf(str: String, fromIndex: Int)
* *
* @param ignoreCase `true` to ignore character case when comparing strings. By default `false`. * @param ignoreCase `true` to ignore character case when comparing strings. By default `false`.
*/ */
public actual fun String?.equals(other: String?, ignoreCase: Boolean /*= false*/): Boolean { @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String?.equals(other: String?, ignoreCase: Boolean = false): Boolean {
if (this === null) if (this === null)
return other === null return other === null
return if (!ignoreCase) return if (!ignoreCase)
@@ -51,7 +52,8 @@ public actual fun String?.equals(other: String?, ignoreCase: Boolean /*= false*/
/** /**
* Returns a new string with all occurrences of [oldChar] replaced with [newChar]. * Returns a new string with all occurrences of [oldChar] replaced with [newChar].
*/ */
public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean /*= false*/): String { @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String {
if (!ignoreCase) if (!ignoreCase)
return (this as java.lang.String).replace(oldChar, newChar) return (this as java.lang.String).replace(oldChar, newChar)
else else
@@ -62,14 +64,16 @@ public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boole
* Returns a new string obtained by replacing all occurrences of the [oldValue] substring in this string * Returns a new string obtained by replacing all occurrences of the [oldValue] substring in this string
* with the specified [newValue] string. * with the specified [newValue] string.
*/ */
public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean/* = false*/): String = @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String =
splitToSequence(oldValue, ignoreCase = ignoreCase).joinToString(separator = newValue) splitToSequence(oldValue, ignoreCase = ignoreCase).joinToString(separator = newValue)
/** /**
* Returns a new string with the first occurrence of [oldChar] replaced with [newChar]. * Returns a new string with the first occurrence of [oldChar] replaced with [newChar].
*/ */
public actual fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean /*= false*/): String { @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String {
val index = indexOf(oldChar, ignoreCase = ignoreCase) val index = indexOf(oldChar, ignoreCase = ignoreCase)
return if (index < 0) this else this.replaceRange(index, index + 1, newChar.toString()) return if (index < 0) this else this.replaceRange(index, index + 1, newChar.toString())
} }
@@ -78,7 +82,8 @@ public actual fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase:
* Returns a new string obtained by replacing the first occurrence of the [oldValue] substring in this string * Returns a new string obtained by replacing the first occurrence of the [oldValue] substring in this string
* with the specified [newValue] string. * with the specified [newValue] string.
*/ */
public actual fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean /*= false*/): String { @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean = false): String {
val index = indexOf(oldValue, ignoreCase = ignoreCase) val index = indexOf(oldValue, ignoreCase = ignoreCase)
return if (index < 0) this else this.replaceRange(index, index + oldValue.length, newValue) return if (index < 0) this else this.replaceRange(index, index + oldValue.length, newValue)
} }
@@ -333,7 +338,8 @@ public inline fun String.offsetByCodePoints(index: Int, codePointOffset: Int): I
* @param otherOffset the start offset in the other char sequence of the substring to compare. * @param otherOffset the start offset in the other char sequence of the substring to compare.
* @param length the length of the substring to compare. * @param length the length of the substring to compare.
*/ */
public actual fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean /*= false*/): Boolean { @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean {
if (this is String && other is String) if (this is String && other is String)
return this.regionMatches(thisOffset, other, otherOffset, length, ignoreCase) return this.regionMatches(thisOffset, other, otherOffset, length, ignoreCase)
else else
@@ -128,12 +128,14 @@ internal constructor(private val nativePattern: Pattern) : Serializable {
* @param startIndex An index to start search with, by default 0. Must be not less than zero and not greater than `input.length()` * @param startIndex An index to start search with, by default 0. Must be not less than zero and not greater than `input.length()`
* @return An instance of [MatchResult] if match was found or `null` otherwise. * @return An instance of [MatchResult] if match was found or `null` otherwise.
*/ */
public actual fun find(input: CharSequence, startIndex: Int /*= 0*/): MatchResult? = nativePattern.matcher(input).findNext(startIndex, input) @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = nativePattern.matcher(input).findNext(startIndex, input)
/** /**
* Returns a sequence of all occurrences of a regular expression within the [input] string, beginning at the specified [startIndex]. * Returns a sequence of all occurrences of a regular expression within the [input] string, beginning at the specified [startIndex].
*/ */
public actual fun findAll(input: CharSequence, startIndex: Int /*= 0*/): Sequence<MatchResult> = generateSequence({ find(input, startIndex) }, MatchResult::next) @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = generateSequence({ find(input, startIndex) }, MatchResult::next)
/** /**
* Attempts to match the entire [input] CharSequence against the pattern. * Attempts to match the entire [input] CharSequence against the pattern.
@@ -189,7 +191,8 @@ internal constructor(private val nativePattern: Pattern) : Serializable {
* @param limit Non-negative value specifying the maximum number of substrings the string can be split to. * @param limit Non-negative value specifying the maximum number of substrings the string can be split to.
* Zero by default means no limit is set. * Zero by default means no limit is set.
*/ */
public actual fun split(input: CharSequence, limit: Int /*= 0*/): List<String> { @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun split(input: CharSequence, limit: Int = 0): List<String> {
require(limit >= 0, { "Limit must be non-negative, but was $limit." } ) require(limit >= 0, { "Limit must be non-negative, but was $limit." } )
return nativePattern.split(input, if (limit == 0) -1 else limit).asList() return nativePattern.split(input, if (limit == 0) -1 else limit).asList()
} }