1 /*
2 * Copyright (c) 1994, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
2681 *
2682 * @since 11
2683 */
2684 public String strip() {
2685 String ret = isLatin1() ? StringLatin1.strip(value)
2686 : StringUTF16.strip(value);
2687 return ret == null ? this : ret;
2688 }
2689
2690 /**
2691 * Returns a string whose value is this string, with all leading
2692 * {@link Character#isWhitespace(int) white space} removed.
2693 * <p>
2694 * If this {@code String} object represents an empty string,
2695 * or if all code points in this string are
2696 * {@link Character#isWhitespace(int) white space}, then an empty string
2697 * is returned.
2698 * <p>
2699 * Otherwise, returns a substring of this string beginning with the first
2700 * code point that is not a {@link Character#isWhitespace(int) white space}
2701 * up to to and including the last code point of this string.
2702 * <p>
2703 * This method may be used to trim
2704 * {@link Character#isWhitespace(int) white space} from
2705 * the beginning of a string.
2706 *
2707 * @return a string whose value is this string, with all leading white
2708 * space removed
2709 *
2710 * @see Character#isWhitespace(int)
2711 *
2712 * @since 11
2713 */
2714 public String stripLeading() {
2715 String ret = isLatin1() ? StringLatin1.stripLeading(value)
2716 : StringUTF16.stripLeading(value);
2717 return ret == null ? this : ret;
2718 }
2719
2720 /**
2721 * Returns a string whose value is this string, with all trailing
|
1 /*
2 * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
2681 *
2682 * @since 11
2683 */
2684 public String strip() {
2685 String ret = isLatin1() ? StringLatin1.strip(value)
2686 : StringUTF16.strip(value);
2687 return ret == null ? this : ret;
2688 }
2689
2690 /**
2691 * Returns a string whose value is this string, with all leading
2692 * {@link Character#isWhitespace(int) white space} removed.
2693 * <p>
2694 * If this {@code String} object represents an empty string,
2695 * or if all code points in this string are
2696 * {@link Character#isWhitespace(int) white space}, then an empty string
2697 * is returned.
2698 * <p>
2699 * Otherwise, returns a substring of this string beginning with the first
2700 * code point that is not a {@link Character#isWhitespace(int) white space}
2701 * up to and including the last code point of this string.
2702 * <p>
2703 * This method may be used to trim
2704 * {@link Character#isWhitespace(int) white space} from
2705 * the beginning of a string.
2706 *
2707 * @return a string whose value is this string, with all leading white
2708 * space removed
2709 *
2710 * @see Character#isWhitespace(int)
2711 *
2712 * @since 11
2713 */
2714 public String stripLeading() {
2715 String ret = isLatin1() ? StringLatin1.stripLeading(value)
2716 : StringUTF16.stripLeading(value);
2717 return ret == null ? this : ret;
2718 }
2719
2720 /**
2721 * Returns a string whose value is this string, with all trailing
|