Home | History | Annotate | Download | only in icu
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package libcore.icu;
     18 
     19 public final class NativeIDN {
     20     public static String toASCII(String s, int flags) {
     21         return convert(s, flags, true);
     22     }
     23 
     24     public static String toUnicode(String s, int flags) {
     25         try {
     26             return convert(s, flags, false);
     27         } catch (IllegalArgumentException ex) {
     28             // The RI documentation explicitly states that this method can't fail.
     29             // ICU4C disagrees, as does the RI in practice.
     30             // The RI just returns the input string if it can't
     31             return s;
     32         }
     33     }
     34 
     35     private static String convert(String s, int flags, boolean toAscii) {
     36         if (s == null) {
     37             throw new NullPointerException("s == null");
     38         }
     39         return convertImpl(s, flags, toAscii);
     40     }
     41     private static native String convertImpl(String s, int flags, boolean toAscii);
     42 
     43     private NativeIDN() {}
     44 }
     45