mirror of
https://github.com/dart-lang/sdk
synced 2024-10-01 19:19:16 +00:00
Add a Platform.lineTerminator static method
Bug: https://github.com/dart-lang/sdk/issues/52379 Change-Id: Ic3a7f06252f8a69dcfdb29c00f16557c34529652 CoreLibraryReviewExempt: Aske is on holiday Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297260 Reviewed-by: Siva Annamalai <asiva@google.com> Commit-Queue: Brian Quinlan <bquinlan@google.com> Reviewed-by: Lasse Nielsen <lrn@google.com> Reviewed-by: Alexander Aprelev <aam@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
parent
a48d2cf02c
commit
a75e857df5
|
@ -15,6 +15,9 @@
|
|||
- **Breaking change** [#51486][]:
|
||||
- Added `sameSite` to the `Cookie` class.
|
||||
- Added class `SameSite`.
|
||||
- Added `Platform.lineTerminator` which exposes the character or characters
|
||||
that the operating system uses to separate lines of text, e.g.,
|
||||
`"\r\n"` on Windows.
|
||||
|
||||
[#51486]: https://github.com/dart-lang/sdk/issues/51486
|
||||
|
||||
|
|
|
@ -240,4 +240,16 @@ final class Platform {
|
|||
/// possibly followed by whitespace and other version and
|
||||
/// build details.
|
||||
static String get version => _version;
|
||||
|
||||
/// The current operating system's default line terminator.
|
||||
///
|
||||
/// The default character sequence that the operating system
|
||||
/// uses to separate or terminate text lines.
|
||||
///
|
||||
/// The line terminator is currently the single line-feed character,
|
||||
/// U+000A or `"\n"`, on all supported operating systems except Windows,
|
||||
/// which uses the carriage-return + line-feed sequence, U+000D U+000A or
|
||||
/// `"\r\n"`
|
||||
@pragma("vm:platform-const")
|
||||
static String get lineTerminator => isWindows ? '\r\n' : '\n';
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import "dart:io";
|
||||
import "dart:isolate";
|
||||
|
||||
|
@ -31,6 +32,10 @@ test() {
|
|||
Expect.equals(Platform.isAndroid, Platform.operatingSystem == "android");
|
||||
var sep = Platform.pathSeparator;
|
||||
Expect.isTrue(sep == '/' || (os == 'windows' && sep == '\\'));
|
||||
final eol = Platform.lineTerminator;
|
||||
Expect.isTrue(
|
||||
(eol == '\n' && os != 'windows') || (eol == '\r\n' && os == 'windows'),
|
||||
"unexpected line ending ${utf8.encode(eol)} on $os");
|
||||
var hostname = Platform.localHostname;
|
||||
Expect.isTrue(hostname is String && hostname != "");
|
||||
var environment = Platform.environment;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:convert';
|
||||
import "dart:io";
|
||||
import "dart:isolate";
|
||||
|
||||
|
@ -33,6 +34,10 @@ test() {
|
|||
Expect.equals(Platform.isAndroid, Platform.operatingSystem == "android");
|
||||
var sep = Platform.pathSeparator;
|
||||
Expect.isTrue(sep == '/' || (os == 'windows' && sep == '\\'));
|
||||
final eol = Platform.lineTerminator;
|
||||
Expect.isTrue(
|
||||
(eol == '\n' && os != 'windows') || (eol == '\r\n' && os == 'windows'),
|
||||
"unexpected line ending ${utf8.encode(eol)} on $os");
|
||||
var hostname = Platform.localHostname;
|
||||
Expect.isTrue(hostname is String && hostname != "");
|
||||
var environment = Platform.environment;
|
||||
|
|
Loading…
Reference in a new issue