Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / url / android / java / src / org / chromium / url / IDNStringUtil.java
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.url;
6
7 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace;
9
10 import java.net.IDN;
11
12 /**
13  * This class is used to convert unicode IDN domain names to ASCII, when not
14  * building with ICU.
15  */
16 @JNINamespace("url::android")
17 public class IDNStringUtil {
18     /**
19      * Attempts to convert a Unicode string to an ASCII string using IDN rules.
20      * As of May 2014, the underlying Java function IDNA2003.
21      * @param src String to convert.
22      * @return: String containing only ASCII characters on success, null on
23      *                 failure.
24      */
25     @CalledByNative
26     private static String idnToASCII(String src) {
27         try {
28             return IDN.toASCII(src, IDN.USE_STD3_ASCII_RULES);
29         } catch (Exception e) {
30             return null;
31         }
32     }
33 }