提交 399c52fb 编写于 作者: M martin

6900043: Add method to return line.separator property

Summary: Add System.lineSeparator(), returning getProperty("line.separator")
Reviewed-by: darcy
上级 caeae0a4
...@@ -619,6 +619,20 @@ public final class System { ...@@ -619,6 +619,20 @@ public final class System {
return props; return props;
} }
/**
* Returns the system-dependent line separator string. It always
* returns the same value - the initial value of the {@linkplain
* #getProperty(String) system property} {@code line.separator}.
*
* <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
* Windows systems it returns {@code "\r\n"}.
*/
public static String lineSeparator() {
return lineSeparator;
}
private static String lineSeparator;
/** /**
* Sets the system properties to the <code>Properties</code> * Sets the system properties to the <code>Properties</code>
* argument. * argument.
...@@ -1104,6 +1118,7 @@ public final class System { ...@@ -1104,6 +1118,7 @@ public final class System {
private static void initializeSystemClass() { private static void initializeSystemClass() {
props = new Properties(); props = new Properties();
initProperties(props); initProperties(props);
lineSeparator = props.getProperty("line.separator");
sun.misc.Version.init(); sun.misc.Version.init();
// Workaround until DownloadManager initialization is revisited. // Workaround until DownloadManager initialization is revisited.
...@@ -1192,7 +1207,7 @@ public final class System { ...@@ -1192,7 +1207,7 @@ public final class System {
} }
/* returns the class of the caller. */ /* returns the class of the caller. */
static Class getCallerClass() { static Class<?> getCallerClass() {
// NOTE use of more generic Reflection.getCallerClass() // NOTE use of more generic Reflection.getCallerClass()
return Reflection.getCallerClass(3); return Reflection.getCallerClass(3);
} }
......
...@@ -2552,9 +2552,6 @@ public final class Formatter implements Closeable, Flushable { ...@@ -2552,9 +2552,6 @@ public final class Formatter implements Closeable, Flushable {
private boolean dt = false; private boolean dt = false;
private char c; private char c;
// cache the line separator
private String ls;
private int index(String s) { private int index(String s) {
if (s != null) { if (s != null) {
try { try {
...@@ -2702,9 +2699,7 @@ public final class Formatter implements Closeable, Flushable { ...@@ -2702,9 +2699,7 @@ public final class Formatter implements Closeable, Flushable {
printHashCode(arg); printHashCode(arg);
break; break;
case Conversion.LINE_SEPARATOR: case Conversion.LINE_SEPARATOR:
if (ls == null) a.append(System.lineSeparator());
ls = System.getProperty("line.separator");
a.append(ls);
break; break;
case Conversion.PERCENT_SIGN: case Conversion.PERCENT_SIGN:
a.append('%'); a.append('%');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册