Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Unified Diff: url/android/java/src/org/chromium/url/IDNStringUtil.java

Issue 257673002: Make it possible to build url/ without ICU on android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix GN/GYP Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: url/android/java/src/org/chromium/url/IDNStringUtil.java
diff --git a/url/android/java/src/org/chromium/url/IDNStringUtil.java b/url/android/java/src/org/chromium/url/IDNStringUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..5b4d20708b4722ae424f1cc45d877977fa1f06c4
--- /dev/null
+++ b/url/android/java/src/org/chromium/url/IDNStringUtil.java
@@ -0,0 +1,33 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.url;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
+import java.net.IDN;
+
+/**
+ * This class is used to convert unicode IDN domain names to ASCII, when not
+ * building with ICU.
+ */
+@JNINamespace("url::android")
+public class IDNStringUtil {
+ /**
+ * Attempts to convert a Unicode string to an ASCII string using IDN rules.
+ * @param src String to convert.
+ * @return: String containing only ASCII characters on success, empty string
+ * on failure. Will also return an empty string if the src
+ * string has a length of 0.
+ */
+ @CalledByNative
+ private static String idnToASCII(String src) {
+ try {
+ return IDN.toASCII(src, IDN.USE_STD3_ASCII_RULES);
+ } catch (Exception e) {
+ return "";
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698