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"');
  }
}