lineTerminator 属性

String lineTerminator
继承

writeln 添加的行结束,并替换某些方法中的 "\n"

其值必须是 "\n"(默认值)或 "\r\n" 中的一个。

当设置为 "\r\n" 时,writewritelnwriteAllwriteCharCode 这几个方法将把它们参数中嵌入的新行 "\n" 转换为 "\r\n"。如果它们的参数已经包含 "\r\n" 序列,则不会进行转换。即使序列是在不同的方法调用中生成的,也是如此。

如果 lineTerminator"\n",则写入的字符串不会被修改。将 lineTerminator 设置为 Platform.lineTerminator 将导致 "write" 方法输出平台的行结束符。

stdout.lineTerminator = Platform.lineTerminator;
stderr.lineTerminator = Platform.lineTerminator;

lineTerminator 的值对字节取向的方法(如 add)没有影响。

lineTerminator 的值不影响 print 函数的输出。

如果设置为除 "\n""\r\n" 之外的其他值,则抛出 ArgumentError

实现

//
/// Setting `lineTerminator` to [Platform.lineTerminator] will result in
/// "write" methods outputting the line endings for the platform:
///
/// ```dart
/// stdout.lineTerminator = Platform.lineTerminator;
/// stderr.lineTerminator = Platform.lineTerminator;
/// ```
///
/// The value of `lineTerminator` has no effect on byte-oriented methods
/// such as [add].
///
/// The value of `lineTerminator` does not effect the output of the [print]
/// function.
///
/// Throws [ArgumentError] if set to a value other than `"\n"` or `"\r\n"`.
String get lineTerminator => _windowsLineTerminator ? "\r\n" : "\n";
void lineTerminator=(String lineTerminator)
继承

实现

set lineTerminator(String lineTerminator) {
  if (lineTerminator == "\r\n") {
    assert(!_lastWrittenCharIsCR || _windowsLineTerminator);
    _windowsLineTerminator = true;
  } else if (lineTerminator == "\n") {
    _windowsLineTerminator = false;
    _lastWrittenCharIsCR = false;
  } else {
    throw ArgumentError.value(lineTerminator, "lineTerminator",
        r'invalid line terminator, must be one of "\r" or "\r\n"');
  }
}