Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions src/main/java/me/towdium/pinin/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ public class Keyboard {
public static Keyboard DAQIAN = new Keyboard(PHONETIC_LOCAL, DAQIAN_KEYS, Keyboard::standard, false, false);
public static Keyboard XIAOHE = new Keyboard(null, XIAOHE_KEYS, Keyboard::zero, true, false);
public static Keyboard ZIRANMA = new Keyboard(null, ZIRANMA_KEYS, Keyboard::zero, true, false);
public static Keyboard SOUGOU = new Keyboard(null, SOUGOU_KEYS, Keyboard::zero, true, false);
public static Keyboard GUOBIAO = new Keyboard(null, GUOBIAO_KEYS, Keyboard::zero, true, false);
public static Keyboard MICROSOFT = new Keyboard(null, MICROSOFT_KEYS, Keyboard::zero, true, false);
public static Keyboard PINYINPP = new Keyboard(null, PINYINPP_KEYS, Keyboard::zero, true, false);
public static Keyboard ZIGUANG = new Keyboard(null, ZIGUANG_KEYS, Keyboard::zero, true, false);
public static Keyboard SOUGOU = new Keyboard(null, SOUGOU_KEYS, Keyboard::zeroOInitial, true, false);
public static Keyboard ZHINENG_ABC = new Keyboard(null, ZHINENG_ABC_KEYS, Keyboard::zeroOInitial, true, false);
public static Keyboard GUOBIAO = new Keyboard(null, GUOBIAO_KEYS, Keyboard::zeroAInitial, true, false);
public static Keyboard MICROSOFT = new Keyboard(null, MICROSOFT_KEYS, Keyboard::zeroOInitial, true, false);
public static Keyboard PINYINPP = new Keyboard(null, PINYINPP_KEYS, Keyboard::zeroFirstInitial, true, false);
public static Keyboard ZIGUANG = new Keyboard(null, ZIGUANG_KEYS, Keyboard::zeroOInitial, true, false);

final Map<String, String> local;
final Map<String, String> keys;
Expand Down Expand Up @@ -175,6 +176,32 @@ public static List<String> zero(String s) {
return ss;
}

public static List<String> zeroOInitial(String s) {
List<String> ss = standard(s);
if (ss.size() == 2) {
ss.add(0,"o");
}
return ss;
}

public static List<String> zeroAInitial(String s) {
List<String> ss = standard(s);
if (ss.size() == 2) {
ss.add(0,"a");
}
return ss;
}

public static List<String> zeroFirstInitial(String s) {
List<String> ss = standard(s);
if (ss.size() == 2) {
String finale = ss.get(0);
ss.set(0, Character.toString(finale.charAt(0)));
ss.add(1,finale);
}
return ss;
}

public Collection<String> split(String s) {
if (local != null) {
String cut = s.substring(0, s.length() - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/towdium/pinin/elements/Phoneme.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public IndexSet match(String source, int start, boolean partial) {
if (strs.length == 1 && strs[0].isEmpty()) return ret;
for (String str : strs) {
int size = strCmp(source, str, start);
if (partial && start + size == source.length()) ret.set(size); // ending match
if (partial && size != 0 && start + size == source.length()) ret.set(size); // ending match
else if (size == str.length()) ret.set(size); // full match
}
return ret;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/me/towdium/pinin/PinInTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void xiaohe() {
assert p.contains("测试文本", "ceuiwfbf");
assert p.contains("测试文本", "ceuiwf2");
assert !p.contains("测试文本", "ceuiw2");
assert p.contains("合金炉", "hej");
assert !p.contains("合金炉", "hej");
assert p.contains("洗矿场", "xikl4");
assert p.contains("月球", "ytqq");
}
Expand All @@ -192,7 +192,7 @@ public void ziranma() {
assert p.contains("测试文本", "ceuiwfbf");
assert p.contains("测试文本", "ceuiwf2");
assert !p.contains("测试文本", "ceuiw2");
assert p.contains("合金炉", "hej");
assert !p.contains("合金炉", "hej");
assert p.contains("洗矿场", "xikd4");
assert p.contains("月球", "ytqq");
assert p.contains("安全", "anqr");
Expand Down