src/java.base/share/classes/java/lang/String.java
changeset 50098 92560438d306
parent 50051 f5231f5762fc
child 50175 589ed2770141
equal deleted inserted replaced
50097:ed8a43d83fcc 50098:92560438d306
  2600 
  2600 
  2601     /**
  2601     /**
  2602      * Returns a string whose value is this string, with all leading
  2602      * Returns a string whose value is this string, with all leading
  2603      * and trailing space removed, where space is defined
  2603      * and trailing space removed, where space is defined
  2604      * as any character whose codepoint is less than or equal to
  2604      * as any character whose codepoint is less than or equal to
  2605      * {@code '\u005Cu0020'} (the space character).
  2605      * {@code 'U+0020'} (the space character).
  2606      * <p>
  2606      * <p>
  2607      * If this {@code String} object represents an empty character
  2607      * If this {@code String} object represents an empty character
  2608      * sequence, or the first and last characters of character sequence
  2608      * sequence, or the first and last characters of character sequence
  2609      * represented by this {@code String} object both have codes
  2609      * represented by this {@code String} object both have codes
  2610      * that are not space (as defined above), then a
  2610      * that are not space (as defined above), then a
  2631      *          has no leading or trailing space.
  2631      *          has no leading or trailing space.
  2632      */
  2632      */
  2633     public String trim() {
  2633     public String trim() {
  2634         String ret = isLatin1() ? StringLatin1.trim(value)
  2634         String ret = isLatin1() ? StringLatin1.trim(value)
  2635                                 : StringUTF16.trim(value);
  2635                                 : StringUTF16.trim(value);
       
  2636         return ret == null ? this : ret;
       
  2637     }
       
  2638 
       
  2639     /**
       
  2640      * Returns a string whose value is this string, with all leading
       
  2641      * and trailing {@link Character#isWhitespace(int) white space}
       
  2642      * removed.
       
  2643      * <p>
       
  2644      * If this {@code String} object represents an empty string,
       
  2645      * or if all code points in this string are
       
  2646      * {@link Character#isWhitespace(int) white space}, then an empty string
       
  2647      * is returned.
       
  2648      * <p>
       
  2649      * Otherwise, returns a substring of this string beginning with the first
       
  2650      * code point that is not a {@link Character#isWhitespace(int) white space}
       
  2651      * up to and including the last code point that is not a
       
  2652      * {@link Character#isWhitespace(int) white space}.
       
  2653      * <p>
       
  2654      * This method may be used to strip
       
  2655      * {@link Character#isWhitespace(int) white space} from
       
  2656      * the beginning and end of a string.
       
  2657      *
       
  2658      * @return  a string whose value is this string, with all leading
       
  2659      *          and trailing white space removed
       
  2660      *
       
  2661      * @see Character#isWhitespace(int)
       
  2662      *
       
  2663      * @since 11
       
  2664      */
       
  2665     public String strip() {
       
  2666         String ret = isLatin1() ? StringLatin1.strip(value)
       
  2667                                 : StringUTF16.strip(value);
       
  2668         return ret == null ? this : ret;
       
  2669     }
       
  2670 
       
  2671     /**
       
  2672      * Returns a string whose value is this string, with all leading
       
  2673      * {@link Character#isWhitespace(int) white space} removed.
       
  2674      * <p>
       
  2675      * If this {@code String} object represents an empty string,
       
  2676      * or if all code points in this string are
       
  2677      * {@link Character#isWhitespace(int) white space}, then an empty string
       
  2678      * is returned.
       
  2679      * <p>
       
  2680      * Otherwise, returns a substring of this string beginning with the first
       
  2681      * code point that is not a {@link Character#isWhitespace(int) white space}
       
  2682      * up to to and including the last code point of this string.
       
  2683      * <p>
       
  2684      * This method may be used to trim
       
  2685      * {@link Character#isWhitespace(int) white space} from
       
  2686      * the beginning of a string.
       
  2687      *
       
  2688      * @return  a string whose value is this string, with all leading white
       
  2689      *          space removed
       
  2690      *
       
  2691      * @see Character#isWhitespace(int)
       
  2692      *
       
  2693      * @since 11
       
  2694      */
       
  2695     public String stripLeading() {
       
  2696         String ret = isLatin1() ? StringLatin1.stripLeading(value)
       
  2697                                 : StringUTF16.stripLeading(value);
       
  2698         return ret == null ? this : ret;
       
  2699     }
       
  2700 
       
  2701     /**
       
  2702      * Returns a string whose value is this string, with all trailing
       
  2703      * {@link Character#isWhitespace(int) white space} removed.
       
  2704      * <p>
       
  2705      * If this {@code String} object represents an empty string,
       
  2706      * or if all characters in this string are
       
  2707      * {@link Character#isWhitespace(int) white space}, then an empty string
       
  2708      * is returned.
       
  2709      * <p>
       
  2710      * Otherwise, returns a substring of this string beginning with the first
       
  2711      * code point of this string up to and including the last code point
       
  2712      * that is not a {@link Character#isWhitespace(int) white space}.
       
  2713      * <p>
       
  2714      * This method may be used to trim
       
  2715      * {@link Character#isWhitespace(int) white space} from
       
  2716      * the end of a string.
       
  2717      *
       
  2718      * @return  a string whose value is this string, with all trailing white
       
  2719      *          space removed
       
  2720      *
       
  2721      * @see Character#isWhitespace(int)
       
  2722      *
       
  2723      * @since 11
       
  2724      */
       
  2725     public String stripTrailing() {
       
  2726         String ret = isLatin1() ? StringLatin1.stripTrailing(value)
       
  2727                                 : StringUTF16.stripTrailing(value);
  2636         return ret == null ? this : ret;
  2728         return ret == null ? this : ret;
  2637     }
  2729     }
  2638 
  2730 
  2639     /**
  2731     /**
  2640      * This object (which is already a string!) is itself returned.
  2732      * This object (which is already a string!) is itself returned.