changeset 49332:fc3f1ec7cd52 raw-string-literal

0000000: Clean up comments, trimMarkers and use isWhitespace
author jlaskey
date Mon, 12 Mar 2018 13:39:06 -0300
parents 5a2e574f43fb
children bc38df004048
files src/java.base/share/classes/java/lang/String.java src/java.base/share/classes/java/lang/StringUTF16.java test/jdk/java/lang/String/RawStringLiteralLib.java
diffstat 3 files changed, 22 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/String.java	Fri Mar 09 14:58:54 2018 -0400
+++ b/src/java.base/share/classes/java/lang/String.java	Mon Mar 12 13:39:06 2018 -0300
@@ -2845,7 +2845,7 @@
 
     /**
      * When applied to a multi-line string, removes left and right
-     * margins from each line.
+     * margins from each line based on provided markers.
      * <p>
      * Each line of the multi-line string is first trimmed. If
      * the trimmed line contains the {@code leftMarker} at the
@@ -2862,7 +2862,7 @@
      * @return  string with margins removed
      * @since 11
      */
-    public String trimMargins(String leftMarker, String rightMarker) {
+    public String trimMarkers(String leftMarker, String rightMarker) {
         Objects.requireNonNull(leftMarker);
         Objects.requireNonNull(rightMarker);
         if (isEmpty()) {
@@ -3246,8 +3246,8 @@
     }
 
     /**
-     * The constants of this enumerated type provide a simple classification of the
-     * types of escape sequence catagories based on the
+     * The constants of this enumerated type provide a simple classification
+     * of the types of escape sequence catagories based on the
      * <cite>The Java&trade; Language Specification</cite>.
      */
     public enum EscapeType {
@@ -3267,9 +3267,9 @@
     }
 
     /**
-     * Translates all escape sequences in the string into character
-     * representations specified in sections 3.3 and 3.10.6 of the
-     * <cite>The Java&trade; Language Specification</cite>.
+     * Translates all Unicode escapes and escape sequences in the string into
+     * characters represented by those escapes specified in sections 3.3 and
+     * 3.10.6 of the <cite>The Java&trade; Language Specification</cite>.
      * <p>
      * Each  unicode escape in the form {@code \u005Cunnnn} is translated to
      * the unicode character whose code point is {@code 0xnnnn}. Care should be
@@ -3342,8 +3342,9 @@
     }
 
     /**
-     * Selectively translates escape sequences in the string into character
-     * representations specified in sections 3.3 and 3.10.6 of the
+     * Selectively translates all Unicode escapes and escape sequences in
+     * the string into characters represented by those escapes specified in
+     * sections 3.3 and 3.10.6 of the
      * <cite>The Java&trade; Language Specification</cite>.
      * <p>
      * Which escape sequences that are translated is based on {@link EscapeType}
@@ -3393,10 +3394,10 @@
     }
 
     /**
-     * Translates all characters in the string that would require
-     * escape sequences in a source string literal into escape
-     * sequence representations specified in sections 3.3 and 3.10.6
-     * of the <cite>The Java&trade; Language Specification</cite>.
+     * Translates all quotes, backslashes, non-ASCII and non-graphics
+     * characters into escape sequence representations specified in
+     * sections 3.3 and 3.10.6 of the
+     * <cite>The Java&trade; Language Specification</cite>.
      * <p>
      * Characters in the code point range {@code \u005Cu0000..\u005Cu001F}
      * are translated to unicode escapes unless they have a special
@@ -3416,10 +3417,10 @@
     }
 
     /**
-     * Selectively translates characters in the string that would require
-     * escape sequences in a source string literal into escape
-     * sequence representations specified in sections 3.3 and 3.10.6
-     * of the <cite>The Java&trade; Language Specification</cite>.
+     * Selectively translates all quotes, backslashes, non-ASCII and
+     * non-graphics characters into escape sequence representations
+     * specified in sections 3.3 and 3.10.6 of the
+     * <cite>The Java&trade; Language Specification</cite>.
      * <p>
      * Which characters that are translated is based on {@link EscapeType}
      * {@code escapes} specified.
--- a/src/java.base/share/classes/java/lang/StringUTF16.java	Fri Mar 09 14:58:54 2018 -0400
+++ b/src/java.base/share/classes/java/lang/StringUTF16.java	Mon Mar 12 13:39:06 2018 -0300
@@ -853,7 +853,7 @@
         int left = 0;
         while (left < length) {
             char ch = getChar(value, left);
-            if (ch > ' ' && ch != '\u2007' && ch != '\u202F') {
+            if (ch > ' ' && !Character.isWhitespace(ch)) {
                 break;
             }
             left++;
@@ -866,7 +866,7 @@
         int right = length;
         while (0 < right) {
             char ch = getChar(value, right - 1);
-            if (ch > ' ' && ch != '\u2007' && ch != '\u202F') {
+            if (ch > ' ' && !Character.isWhitespace(ch)) {
                 break;
             }
             right--;
--- a/test/jdk/java/lang/String/RawStringLiteralLib.java	Fri Mar 09 14:58:54 2018 -0400
+++ b/test/jdk/java/lang/String/RawStringLiteralLib.java	Mon Mar 12 13:39:06 2018 -0300
@@ -110,7 +110,7 @@
             }
         }
 
-        // trimMargins
+        // trimMarkers
         for (String prefix : List.of("", "\n", "   \n"))
         for (String suffix : List.of("", "\n", "   \n"))
         for (String middle : List.of("",
@@ -131,7 +131,7 @@
                            leftMargin + middle + rightMargin + "\n" +
                            leftMargin + "   def   " + rightMargin + "\n" +
                            suffix;
-            String output = input.trimMargins(leftMargin, rightMargin);
+            String output = input.trimMarkers(leftMargin, rightMargin);
 
             Iterator<String> inputIterator = input.lines().iterator();
             Iterator<String> outputIterator = output.lines().iterator();