< prev index next >

src/java.base/share/classes/sun/text/normalizer/Normalizer2.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 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


 118      * @stable ICU 49
 119      */
 120     public static Normalizer2 getNFKDInstance() {
 121         return Norm2AllModes.getNFKCInstance().decomp;
 122     }
 123 
 124     /**
 125      * Returns the normalized form of the source string.
 126      * @param src source string
 127      * @return normalized src
 128      * @stable ICU 4.4
 129      */
 130     public String normalize(CharSequence src) {
 131         if(src instanceof String) {
 132             // Fastpath: Do not construct a new String if the src is a String
 133             // and is already normalized.
 134             int spanLength=spanQuickCheckYes(src);
 135             if(spanLength==src.length()) {
 136                 return (String)src;
 137             }

 138             StringBuilder sb=new StringBuilder(src.length()).append(src, 0, spanLength);
 139             return normalizeSecondAndAppend(sb, src.subSequence(spanLength, src.length())).toString();
 140         }

 141         return normalize(src, new StringBuilder(src.length())).toString();
 142     }
 143 
 144     /**
 145      * Writes the normalized form of the source string to the destination string
 146      * (replacing its contents) and returns the destination string.
 147      * The source and destination strings must be different objects.
 148      * @param src source string
 149      * @param dest destination string; its contents is replaced with normalized src
 150      * @return dest
 151      * @stable ICU 4.4
 152      */
 153     public abstract StringBuilder normalize(CharSequence src, StringBuilder dest);
 154 
 155     /**
 156      * Writes the normalized form of the source string to the destination Appendable
 157      * and returns the destination Appendable.
 158      * The source and destination strings must be different objects.
 159      *
 160      * <p>Any {@link java.io.IOException} is wrapped into a {@link com.ibm.icu.util.ICUUncheckedIOException}.


   1 /*
   2  * Copyright (c) 2015, 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


 118      * @stable ICU 49
 119      */
 120     public static Normalizer2 getNFKDInstance() {
 121         return Norm2AllModes.getNFKCInstance().decomp;
 122     }
 123 
 124     /**
 125      * Returns the normalized form of the source string.
 126      * @param src source string
 127      * @return normalized src
 128      * @stable ICU 4.4
 129      */
 130     public String normalize(CharSequence src) {
 131         if(src instanceof String) {
 132             // Fastpath: Do not construct a new String if the src is a String
 133             // and is already normalized.
 134             int spanLength=spanQuickCheckYes(src);
 135             if(spanLength==src.length()) {
 136                 return (String)src;
 137             }
 138             if (spanLength != 0) {
 139                 StringBuilder sb=new StringBuilder(src.length()).append(src, 0, spanLength);
 140                 return normalizeSecondAndAppend(sb, src.subSequence(spanLength, src.length())).toString();
 141             }
 142         }
 143         return normalize(src, new StringBuilder(src.length())).toString();
 144     }
 145 
 146     /**
 147      * Writes the normalized form of the source string to the destination string
 148      * (replacing its contents) and returns the destination string.
 149      * The source and destination strings must be different objects.
 150      * @param src source string
 151      * @param dest destination string; its contents is replaced with normalized src
 152      * @return dest
 153      * @stable ICU 4.4
 154      */
 155     public abstract StringBuilder normalize(CharSequence src, StringBuilder dest);
 156 
 157     /**
 158      * Writes the normalized form of the source string to the destination Appendable
 159      * and returns the destination Appendable.
 160      * The source and destination strings must be different objects.
 161      *
 162      * <p>Any {@link java.io.IOException} is wrapped into a {@link com.ibm.icu.util.ICUUncheckedIOException}.


< prev index next >