Skip to content

Commit 6f71c9f

Browse files
committed
Add lineSeparator to Filesystem
1 parent fc3837b commit 6f71c9f

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

runtime/runtime-core/api/runtime-core.api

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,7 @@ public abstract interface class aws/smithy/kotlin/runtime/util/Filesystem {
23292329
public static final field Companion Laws/smithy/kotlin/runtime/util/Filesystem$Companion;
23302330
public abstract fun fileExists (Ljava/lang/String;)Z
23312331
public abstract fun getFilePathSeparator ()Ljava/lang/String;
2332+
public abstract fun getLineSeparator ()Ljava/lang/String;
23322333
public abstract fun readFileOrNull (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
23332334
public abstract fun writeFile (Ljava/lang/String;[BLkotlin/coroutines/Continuation;)Ljava/lang/Object;
23342335
}
@@ -2338,6 +2339,10 @@ public final class aws/smithy/kotlin/runtime/util/Filesystem$Companion {
23382339
public static synthetic fun fromMap$default (Laws/smithy/kotlin/runtime/util/Filesystem$Companion;Ljava/util/Map;Ljava/lang/String;ILjava/lang/Object;)Laws/smithy/kotlin/runtime/util/Filesystem;
23392340
}
23402341

2342+
public final class aws/smithy/kotlin/runtime/util/Filesystem$DefaultImpls {
2343+
public static fun getLineSeparator (Laws/smithy/kotlin/runtime/util/Filesystem;)Ljava/lang/String;
2344+
}
2345+
23412346
public final class aws/smithy/kotlin/runtime/util/FlowUtilKt {
23422347
public static final fun mergeSequential ([Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow;
23432348
}
@@ -2406,6 +2411,10 @@ public final class aws/smithy/kotlin/runtime/util/PlatformProvider$Companion {
24062411
public final fun getSystem ()Laws/smithy/kotlin/runtime/util/PlatformProvider;
24072412
}
24082413

2414+
public final class aws/smithy/kotlin/runtime/util/PlatformProvider$DefaultImpls {
2415+
public static fun getLineSeparator (Laws/smithy/kotlin/runtime/util/PlatformProvider;)Ljava/lang/String;
2416+
}
2417+
24092418
public abstract interface class aws/smithy/kotlin/runtime/util/PropertyProvider {
24102419
public abstract fun getAllProperties ()Ljava/util/Map;
24112420
public abstract fun getProperty (Ljava/lang/String;)Ljava/lang/String;
@@ -2429,6 +2438,7 @@ public final class aws/smithy/kotlin/runtime/util/TestPlatformProvider : aws/smi
24292438
public fun getAllEnvVars ()Ljava/util/Map;
24302439
public fun getAllProperties ()Ljava/util/Map;
24312440
public fun getFilePathSeparator ()Ljava/lang/String;
2441+
public fun getLineSeparator ()Ljava/lang/String;
24322442
public fun getProperty (Ljava/lang/String;)Ljava/lang/String;
24332443
public fun getenv (Ljava/lang/String;)Ljava/lang/String;
24342444
public fun isAndroid ()Z

runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/util/Filesystem.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public interface Filesystem {
1616
*/
1717
public val filePathSeparator: String
1818

19+
/**
20+
* The string which represents a line separator on this file system. For example, on Windows, this is CRLF.
21+
*/
22+
public val lineSeparator: String
23+
get() = "\n"
24+
1925
/**
2026
* Read the contents of a file as a [String] or return null on any error.
2127
*

runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/util/Platform.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public interface PlatformProvider :
3636
internal expect object SystemDefaultProvider : PlatformProvider {
3737
override fun osInfo(): OperatingSystem
3838
override val filePathSeparator: String
39+
override val lineSeparator: String
3940
override fun fileExists(path: String): Boolean
4041
override fun getAllEnvVars(): Map<String, String>
4142
override fun getAllProperties(): Map<String, String>
@@ -50,6 +51,12 @@ internal expect object SystemDefaultProvider : PlatformProvider {
5051
override val isNative: Boolean
5152
}
5253

54+
internal val OperatingSystem.lineSeparator: String
55+
get() = when {
56+
family == OsFamily.Windows -> "\r\n"
57+
else -> "\n"
58+
}
59+
5360
public data class OperatingSystem(val family: OsFamily, val version: String?)
5461

5562
public enum class OsFamily {

runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/util/PlatformJVM.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ internal actual object SystemDefaultProvider : PlatformProvider {
7171
* segment char is '/'.
7272
*/
7373
actual override val filePathSeparator: String by lazy { File.separator }
74+
75+
actual override val lineSeparator: String by lazy { osInfo().lineSeparator }
7476
}
7577

7678
private fun isAndroid(): Boolean = try {

0 commit comments

Comments
 (0)