mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.10.3.1
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.langs.lnki_trails; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xol_lnki_trail_mgr implements GfoInvkAble {
|
||||
public Xol_lnki_trail_mgr(Xol_lang_itm lang) {}
|
||||
public void Clear() {trie.Clear();}
|
||||
public int Count() {return trie.Count();}
|
||||
public Btrie_slim_mgr Trie() {return trie;} Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
|
||||
public void Add(byte[] v) {trie.Add_obj(v, v);}
|
||||
public void Del(byte[] v) {trie.Del(v);}
|
||||
private void Add(String... ary) {
|
||||
for (String itm_str : ary) {
|
||||
byte[] itm = Bry_.new_u8(itm_str);
|
||||
trie.Add_obj(itm, itm);
|
||||
}
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_add_range)) Add_range(m);
|
||||
else if (ctx.Match(k, Invk_add_many)) Add_many(m);
|
||||
else if (ctx.Match(k, Invk_add_bulk)) Add_bulk(m);
|
||||
else if (ctx.Match(k, Invk_clear)) Clear();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_add_many = "add_many", Invk_add_range = "add_range", Invk_add_bulk = "add_bulk", Invk_clear = "clear";
|
||||
private void Add_bulk(GfoMsg m) {byte[] src = m.ReadBry("bulk"); Add_bulk(src);}
|
||||
public void Add_bulk(byte[] src) {
|
||||
int pos = 0, src_len = src.length;
|
||||
while (true) {
|
||||
byte[] itm = gplx.core.intls.Utf8_.Get_char_at_pos_as_bry(src, pos);
|
||||
Add(itm);
|
||||
pos += itm.length;
|
||||
if (pos >= src_len) break;
|
||||
}
|
||||
}
|
||||
private void Add_many(GfoMsg m) {
|
||||
int len = m.Args_count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
KeyVal kv = m.Args_getAt(i);
|
||||
Add(kv.Val_to_str_or_empty());
|
||||
}
|
||||
}
|
||||
private void Add_range(GfoMsg m) {
|
||||
byte bgn = Add_rng_extract(m, "bgn");
|
||||
byte end = Add_rng_extract(m, "end");
|
||||
for (byte i = bgn; i <= end; i++)
|
||||
Add(new byte[] {i});
|
||||
}
|
||||
public void Add_range(byte bgn, byte end) {
|
||||
for (byte i = bgn; i <= end; i++)
|
||||
Add(new byte[] {i});
|
||||
}
|
||||
byte Add_rng_extract(GfoMsg m, String key) {
|
||||
byte[] bry = m.ReadBry(key);
|
||||
if (bry.length != 1) throw Err_.new_wo_type("argument must be ascii character", "key", key, "bry", String_.new_u8(bry));
|
||||
return bry[0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.langs.lnki_trails; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_lnki_trail_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xol_lnki_trail_mgr_fxt fxt = new Xol_lnki_trail_mgr_fxt();
|
||||
@Test public void Add_bulk() {
|
||||
fxt.Test_add_bulk("äöüß", "ä", "ö", "ü", "ß");
|
||||
}
|
||||
}
|
||||
class Xol_lnki_trail_mgr_fxt {
|
||||
Xol_lang_itm lang; Xol_lnki_trail_mgr lnki_trail_mgr;
|
||||
public void Clear() {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
lang = new Xol_lang_itm(app.Lang_mgr(), Bry_.new_a7("fr"));
|
||||
lnki_trail_mgr = lang.Lnki_trail_mgr();
|
||||
}
|
||||
public void Test_add_bulk(String raw, String... expd_ary) {
|
||||
lnki_trail_mgr.Add_bulk(Bry_.new_u8(raw));
|
||||
int expd_len = expd_ary.length;
|
||||
Tfds.Eq(expd_len, lang.Lnki_trail_mgr().Count());
|
||||
for (int i = 0; i < expd_len; i++) {
|
||||
byte[] expd_bry = Bry_.new_u8(expd_ary[i]);
|
||||
byte[] actl_bry = (byte[])lnki_trail_mgr.Trie().Match_bgn(expd_bry, 0, expd_bry.length);
|
||||
Tfds.Eq_bry(expd_bry, actl_bry);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user