]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/engine/HtmlEntry.java
Fix flags of Scotland. Fix bug with URL encoding HTMLEntry titles.
[Dictionary.git] / src / com / hughes / android / dictionary / engine / HtmlEntry.java
index c7e06282e52aadec67c29d9f897ecc2e543601d2..612c6c1b7040ed1acd4fab4050768033a58ffe55 100644 (file)
@@ -1,7 +1,6 @@
 package com.hughes.android.dictionary.engine;
 
 import android.content.Intent;
-import android.net.Uri;
 import android.util.Log;
 
 import com.hughes.android.dictionary.C;
@@ -13,9 +12,7 @@ import com.ibm.icu.text.Transliterator;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.io.RandomAccessFile;
-import java.io.UnsupportedEncodingException;
 import java.lang.ref.SoftReference;
-import java.net.URLEncoder;
 import java.util.List;
 import java.util.regex.Pattern;
 
@@ -161,9 +158,9 @@ public class HtmlEntry extends AbstractEntry implements RAFSerializable<HtmlEntr
     public static String htmlBody(final List<HtmlEntry> htmlEntries, final String indexShortName) {
         final StringBuilder result = new StringBuilder();
         for (final HtmlEntry htmlEntry : htmlEntries) {
-            final String titleEscaped = StringUtil.escapeToPureHtmlUnicode(htmlEntry.title);
+            final String titleEscaped = StringUtil.escapeUnicodeToPureHtml(htmlEntry.title);
             result.append(String.format("<h1><a href=\"%s\">%s</a></h1>\n<p>%s\n", 
-                    formatQuickdicUrl(indexShortName, titleEscaped), titleEscaped,
+                    formatQuickdicUrl(indexShortName, htmlEntry.title), titleEscaped,
                     htmlEntry.getHtml()));
         }
         return result.toString();
@@ -172,23 +169,19 @@ public class HtmlEntry extends AbstractEntry implements RAFSerializable<HtmlEntr
     public static String formatQuickdicUrl(final String indexShortName, final String text) {
         assert !indexShortName.contains(":");
         assert text.length() > 0;
-        try {
-            return String.format("qd:%s:%s", indexShortName, URLEncoder.encode(text, "UTF-8"));
-        } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException(e);
-        }
+        return String.format("q://d?%s&%s", indexShortName, StringUtil.encodeForUrl(text));
     }
-
+    
     public static boolean isQuickdicUrl(String url) {
-        return url.startsWith("qd:");
+        return url.startsWith("q://d?");
     }
     
     public static void quickdicUrlToIntent(final String url, final Intent intent) {
-        int firstColon = url.indexOf(":");
+        int firstColon = url.indexOf("?");
         if (firstColon == -1) return;
-        int secondColon = url.indexOf(":", firstColon + 1);
+        int secondColon = url.indexOf("&", firstColon + 1);
         if (secondColon == -1) return;
-        intent.putExtra(C.SEARCH_TOKEN, Uri.decode(url.substring(secondColon + 1)));
+        intent.putExtra(C.SEARCH_TOKEN, StringUtil.decodeFromUrl(url.substring(secondColon + 1)));
     }
     
     // --------------------------------------------------------------------