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