Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package kotlin.text
import kotlin.native.internal.escapeAnalysis.Escapes
import kotlin.native.internal.GCUnsafeCall
import kotlin.native.internal.escapeAnalysis.PointsTo
import formatImpl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably I miss something but where is fromatImpl located?

Copy link
Author

@Rfontt Rfontt Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I create a new file called StringFormat.kt in text common package.

libraries/stdlib/src/kotlin/text/StringFormat.kt

And all the logic is there.

That name, formatImpl, was based on other methods that already exist in the common package.

I tried putting it in String.kt, but the code and logic became too extensive.


/**
* Returns the index within this string of the first occurrence of the specified character, starting from the specified offset.
Expand Down Expand Up @@ -604,3 +605,5 @@ private val STRING_CASE_INSENSITIVE_ORDER = Comparator<String> { a, b -> a.compa

public actual val String.Companion.CASE_INSENSITIVE_ORDER: Comparator<String>
get() = STRING_CASE_INSENSITIVE_ORDER

public actual fun String.format(vararg args: Any?): String = formatImpl(args)
18 changes: 18 additions & 0 deletions libraries/stdlib/js/src/kotlin/text/stringJs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package kotlin.text

import formatImpl
import kotlin.js.RegExp

/**
Expand Down Expand Up @@ -358,3 +359,20 @@ private val STRING_CASE_INSENSITIVE_ORDER = Comparator<String> { a, b -> a.compa
@SinceKotlin("1.2")
public actual val String.Companion.CASE_INSENSITIVE_ORDER: Comparator<String>
get() = STRING_CASE_INSENSITIVE_ORDER

/**
* JavaScript implementation of String.format for Kotlin Multiplatform.
*
* This is the actual implementation for JavaScript targets that delegates
* to the shared format logic in common code.
*
* Example:
* ```kotlin
* "Hello %s".format("World") // Returns "Hello World"
* "Value: %d".format(42) // Returns "Value: 42"
* ```
*
* @param args Arguments to insert into the format string
* @return Formatted string with placeholders replaced
*/
public actual fun String.format(vararg args: Any?): String = formatImpl(args)
2 changes: 1 addition & 1 deletion libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public actual inline fun String.toCharArray(
* @sample samples.text.StringsJvmSpecific.formatExtension
*/
@kotlin.internal.InlineOnly
public inline fun String.format(vararg args: Any?): String = java.lang.String.format(this, *args)
public actual inline fun String.format(vararg args: Any?): String = java.lang.String.format(this, *args)

/**
* Uses the provided [format] as a format string and returns a string obtained
Expand Down
Loading