< prev index next >

src/java.base/share/classes/jdk/internal/icu/impl/Norm2AllModes.java

Print this page
rev 57619 : imported patch 8174270
   1 /*
   2  * Copyright (c) 2015, 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
  23  * questions.
  24  */
  25 
  26 /*
  27  *******************************************************************************
  28  *   Copyright (C) 2009-2014, International Business Machines
  29  *   Corporation and others.  All Rights Reserved.
  30  *******************************************************************************
  31  */
  32 
  33 package sun.text.normalizer;
  34 
  35 import java.io.IOException;
  36 
  37 final class Norm2AllModes {


  38     // Public API dispatch via Normalizer2 subclasses -------------------------- ***
  39 
  40     // Normalizer2 implementation for the old UNORM_NONE.
  41     public static final class NoopNormalizer2 extends Normalizer2 {
  42         @Override
  43         public StringBuilder normalize(CharSequence src, StringBuilder dest) {
  44             if(dest!=src) {
  45                 dest.setLength(0);
  46                 return dest.append(src);
  47             } else {
  48                 throw new IllegalArgumentException();
  49             }
  50         }
  51 
  52         @Override
  53         public Appendable normalize(CharSequence src, Appendable dest) {
  54             if(dest!=src) {
  55                 try {
  56                     return dest.append(src);
  57                 } catch(IOException e) {


 248     private static Norm2AllModes getInstanceFromSingleton(Norm2AllModesSingleton singleton) {
 249         if(singleton.exception!=null) {
 250             throw singleton.exception;
 251         }
 252         return singleton.allModes;
 253     }
 254 
 255     public static Norm2AllModes getNFCInstance() {
 256         return getInstanceFromSingleton(NFCSingleton.INSTANCE);
 257     }
 258 
 259     public static Norm2AllModes getNFKCInstance() {
 260         return getInstanceFromSingleton(NFKCSingleton.INSTANCE);
 261     }
 262 
 263     public static final NoopNormalizer2 NOOP_NORMALIZER2=new NoopNormalizer2();
 264 
 265     private static final class Norm2AllModesSingleton {
 266         private Norm2AllModesSingleton(String name) {
 267             try {
 268                 String DATA_FILE_NAME = "/sun/text/resources/" + name + ".nrm";
 269                 NormalizerImpl impl=new NormalizerImpl().load(DATA_FILE_NAME);
 270                 allModes=new Norm2AllModes(impl);
 271             } catch (RuntimeException e) {
 272                 exception=e;
 273             }
 274         }
 275 
 276         private Norm2AllModes allModes;
 277         private RuntimeException exception;
 278     }
 279 
 280     private static final class NFCSingleton {
 281         private static final Norm2AllModesSingleton INSTANCE=new Norm2AllModesSingleton("nfc");
 282     }
 283 
 284     private static final class NFKCSingleton {
 285         private static final Norm2AllModesSingleton INSTANCE=new Norm2AllModesSingleton("nfkc");
 286     }
 287 }
   1 /*
   2  * Copyright (c) 2015, 2020, 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
  23  * questions.
  24  */
  25 
  26 /*
  27  *******************************************************************************
  28  *   Copyright (C) 2009-2014, International Business Machines
  29  *   Corporation and others.  All Rights Reserved.
  30  *******************************************************************************
  31  */
  32 
  33 package jdk.internal.icu.impl;
  34 
  35 import java.io.IOException;
  36 
  37 import jdk.internal.icu.text.Normalizer2;
  38 
  39 public final class Norm2AllModes {
  40     // Public API dispatch via Normalizer2 subclasses -------------------------- ***
  41 
  42     // Normalizer2 implementation for the old UNORM_NONE.
  43     public static final class NoopNormalizer2 extends Normalizer2 {
  44         @Override
  45         public StringBuilder normalize(CharSequence src, StringBuilder dest) {
  46             if(dest!=src) {
  47                 dest.setLength(0);
  48                 return dest.append(src);
  49             } else {
  50                 throw new IllegalArgumentException();
  51             }
  52         }
  53 
  54         @Override
  55         public Appendable normalize(CharSequence src, Appendable dest) {
  56             if(dest!=src) {
  57                 try {
  58                     return dest.append(src);
  59                 } catch(IOException e) {


 250     private static Norm2AllModes getInstanceFromSingleton(Norm2AllModesSingleton singleton) {
 251         if(singleton.exception!=null) {
 252             throw singleton.exception;
 253         }
 254         return singleton.allModes;
 255     }
 256 
 257     public static Norm2AllModes getNFCInstance() {
 258         return getInstanceFromSingleton(NFCSingleton.INSTANCE);
 259     }
 260 
 261     public static Norm2AllModes getNFKCInstance() {
 262         return getInstanceFromSingleton(NFKCSingleton.INSTANCE);
 263     }
 264 
 265     public static final NoopNormalizer2 NOOP_NORMALIZER2=new NoopNormalizer2();
 266 
 267     private static final class Norm2AllModesSingleton {
 268         private Norm2AllModesSingleton(String name) {
 269             try {
 270                 String DATA_FILE_NAME = "/jdk/internal/icu/impl/data/icudt64b/" + name + ".nrm";
 271                 NormalizerImpl impl=new NormalizerImpl().load(DATA_FILE_NAME);
 272                 allModes=new Norm2AllModes(impl);
 273             } catch (RuntimeException e) {
 274                 exception=e;
 275             }
 276         }
 277 
 278         private Norm2AllModes allModes;
 279         private RuntimeException exception;
 280     }
 281 
 282     private static final class NFCSingleton {
 283         private static final Norm2AllModesSingleton INSTANCE=new Norm2AllModesSingleton("nfc");
 284     }
 285 
 286     private static final class NFKCSingleton {
 287         private static final Norm2AllModesSingleton INSTANCE=new Norm2AllModesSingleton("nfkc");
 288     }
 289 }
< prev index next >