0001-Fix-issue-with.patch
1 | From 52a2885e28309631edab2fe653c956600107394b Mon Sep 17 00:00:00 2001 |
2 | From: Julien Lepiller <julien@lepiller.eu> |
3 | Date: Sat, 25 Jun 2022 15:57:04 +0200 |
4 | Subject: [PATCH 1/2] =?UTF-8?q?Fix=20issue=20with=20=E3=80=85?= |
5 | MIME-Version: 1.0 |
6 | Content-Type: text/plain; charset=UTF-8 |
7 | Content-Transfer-Encoding: 8bit |
8 | |
9 | --- |
10 | .idea/gradle.xml | 3 +-- |
11 | .idea/runConfigurations.xml | 12 ---------- |
12 | .../java/eu/lepiller/nani/result/Result.java | 23 +++++++++++++------ |
13 | 3 files changed, 17 insertions(+), 21 deletions(-) |
14 | delete mode 100644 .idea/runConfigurations.xml |
15 | |
16 | diff --git a/.idea/gradle.xml b/.idea/gradle.xml |
17 | index 91df564..dffceeb 100644 |
18 | --- a/.idea/gradle.xml |
19 | +++ b/.idea/gradle.xml |
20 | @@ -4,7 +4,7 @@ |
21 | <component name="GradleSettings"> |
22 | <option name="linkedExternalProjectsSettings"> |
23 | <GradleProjectSettings> |
24 | - <option name="testRunner" value="PLATFORM" /> |
25 | + <option name="testRunner" value="GRADLE" /> |
26 | <option name="distributionType" value="DEFAULT_WRAPPED" /> |
27 | <option name="externalProjectPath" value="$PROJECT_DIR$" /> |
28 | <option name="modules"> |
29 | @@ -14,7 +14,6 @@ |
30 | <option value="$PROJECT_DIR$/rubytextview" /> |
31 | </set> |
32 | </option> |
33 | - <option name="resolveModulePerSourceSet" value="false" /> |
34 | </GradleProjectSettings> |
35 | </option> |
36 | </component> |
37 | diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml |
38 | deleted file mode 100644 |
39 | index 7f68460..0000000 |
40 | --- a/.idea/runConfigurations.xml |
41 | +++ /dev/null |
42 | @@ -1,12 +0,0 @@ |
43 | -<?xml version="1.0" encoding="UTF-8"?> |
44 | -<project version="4"> |
45 | - <component name="RunConfigurationProducerService"> |
46 | - <option name="ignoredProducers"> |
47 | - <set> |
48 | - <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" /> |
49 | - <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" /> |
50 | - <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" /> |
51 | - </set> |
52 | - </option> |
53 | - </component> |
54 | -</project> |
55 | \ No newline at end of file |
56 | diff --git a/app/src/main/java/eu/lepiller/nani/result/Result.java b/app/src/main/java/eu/lepiller/nani/result/Result.java |
57 | index ed1cfb5..ff7e87c 100644 |
58 | --- a/app/src/main/java/eu/lepiller/nani/result/Result.java |
59 | +++ b/app/src/main/java/eu/lepiller/nani/result/Result.java |
60 | @@ -1,5 +1,6 @@ |
61 | package eu.lepiller.nani.result; |
62 | |
63 | +import android.os.Build; |
64 | import android.util.Log; |
65 | |
66 | import com.moji4j.MojiConverter; |
67 | @@ -9,8 +10,7 @@ import java.util.List; |
68 | import java.util.regex.Matcher; |
69 | import java.util.regex.Pattern; |
70 | |
71 | -import static java.lang.Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS; |
72 | -import static java.lang.Character.UnicodeBlock.KATAKANA; |
73 | +import static java.lang.Character.UnicodeBlock.*; |
74 | |
75 | public class Result { |
76 | public static class Source { |
77 | @@ -133,6 +133,16 @@ public class Result { |
78 | return null; |
79 | } |
80 | |
81 | + private static boolean isKanji(char c) { |
82 | + Character.UnicodeBlock b = of(c); |
83 | + return b == CJK_UNIFIED_IDEOGRAPHS || |
84 | + b == CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || |
85 | + b == CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B || |
86 | + (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && b == CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C) || |
87 | + (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && b == CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D) || |
88 | + b == CJK_SYMBOLS_AND_PUNCTUATION; |
89 | + } |
90 | + |
91 | public String getKanjiFurigana() { |
92 | String txt = getKanji(); |
93 | String reading = getReading(); |
94 | @@ -142,12 +152,12 @@ public class Result { |
95 | ArrayList<String> portions = new ArrayList<>(); |
96 | |
97 | StringBuilder current = new StringBuilder(); |
98 | - Character.UnicodeBlock b = CJK_UNIFIED_IDEOGRAPHS; |
99 | + boolean currentBlockIsKanji = true; |
100 | |
101 | MojiConverter converter = new MojiConverter(); |
102 | for(int i=0; i<txt.length(); i++) { |
103 | - Character.UnicodeBlock b2 = Character.UnicodeBlock.of(txt.charAt(i)); |
104 | - if(b == b2) { |
105 | + boolean currentCharIsKanji = isKanji(txt.charAt(i)); |
106 | + if(currentBlockIsKanji == currentCharIsKanji) { |
107 | // if the headwork contains katakana, convert it to hiragana to match pronunciation |
108 | // better. |
109 | current.append(txt.charAt(i)); |
110 | @@ -158,8 +168,7 @@ public class Result { |
111 | current = new StringBuilder(); |
112 | current.append(txt.charAt(i)); |
113 | } |
114 | - |
115 | - b = b2; |
116 | + currentBlockIsKanji = currentCharIsKanji; |
117 | } |
118 | String str = current.toString(); |
119 | if(!str.isEmpty()) |
120 | -- |
121 | 2.36.1 |
122 | |
123 |