1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.7.3.1'

This commit is contained in:
gnosygnu
2016-07-17 21:10:59 -04:00
parent b333db45f8
commit 7a851a41a5
290 changed files with 3048 additions and 2124 deletions

View File

@@ -18,9 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.langs.cases; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*; import gplx.core.intls.*;
public class Xol_case_mgr implements Gfo_invk, Gfo_case_mgr {
private final Object thread_lock = new Object();
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
private final Btrie_rv trv = new Btrie_rv();
private final Btrie_fast_mgr upper_trie = Btrie_fast_mgr.cs(), lower_trie = Btrie_fast_mgr.cs(); private Xol_case_itm[] itms;
public Xol_case_mgr(byte tid) {this.tid = tid;}
public byte Tid() {return tid;} private byte tid;
@@ -61,73 +58,70 @@ public class Xol_case_mgr implements Gfo_invk, Gfo_case_mgr {
public byte[] Case_reuse_upper(byte[] src, int bgn, int end) {return Case_reuse(Bool_.Y, src, bgn, end);}
public byte[] Case_reuse_lower(byte[] src, int bgn, int end) {return Case_reuse(Bool_.N, src, bgn, end);}
public byte[] Case_reuse(boolean upper, byte[] src, int bgn, int end) {
synchronized (thread_lock) { // LOCK:trie; DATE:2016-07-06
int pos = bgn;
tmp_bfr.Clear();
Btrie_fast_mgr trie = upper ? upper_trie : lower_trie;
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Object o = trie.Match_at_w_b0(trv, b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25; TS: DATE:2016-07-06
if (o != null && pos < end) { // pos < end used for casing 1st letter only; upper_1st will pass end of 1
Xol_case_itm itm = (Xol_case_itm)o;
if (upper)
itm.Case_reuse_upper(src, pos, b_len);
else
itm.Case_reuse_lower(src, pos, b_len);
}
else {} // noop
pos += b_len;
}
return src;
}
}
public byte[] Case_reuse_1st_upper(byte[] src) { // NOTE: optimized version called by Frame_ttl; DATE:2014-06-21
synchronized (thread_lock) { // LOCK:trie; DATE:2016-07-06
int src_len = src.length;
if (src_len == 0) return src; // empty bry
byte b = src[0];
Btrie_fast_mgr trie = upper ? upper_trie : lower_trie;
Btrie_rv trv = new Btrie_rv(); // TS.MEM: DATE:2016-07-12
int pos = bgn;
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Object o = upper_trie.Match_at_w_b0(trv, b, src, 0, b_len);
if (o == null) return src; // 1st letter is not a lower case char (either num, symbol, or upper)
Xol_case_itm itm = (Xol_case_itm)o;
itm.Case_build_upper(tmp_bfr);
tmp_bfr.Add_mid(src, trv.Pos(), src_len);
return tmp_bfr.To_bry_and_clear();
Object o = trie.Match_at_w_b0(trv, b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25; TS: DATE:2016-07-06
if (o != null && pos < end) { // pos < end used for casing 1st letter only; upper_1st will pass end of 1
Xol_case_itm itm = (Xol_case_itm)o;
if (upper)
itm.Case_reuse_upper(src, pos, b_len);
else
itm.Case_reuse_lower(src, pos, b_len);
}
else {} // noop
pos += b_len;
}
return src;
}
public byte[] Case_reuse_1st_upper(byte[] src) { // NOTE: optimized version called by Frame_ttl; DATE:2014-06-21
int src_len = src.length;
if (src_len == 0) return src; // empty bry
byte b = src[0];
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Btrie_rv trv = new Btrie_rv(); // TS.MEM: DATE:2016-07-12
Object o = upper_trie.Match_at_w_b0(trv, b, src, 0, b_len);
if (o == null) return src; // 1st letter is not a lower case char (either num, symbol, or upper)
Xol_case_itm itm = (Xol_case_itm)o;
Bry_bfr tmp_bfr = Bry_bfr_.New(); // TS.MEM: DATE:2016-07-12
itm.Case_build_upper(tmp_bfr);
tmp_bfr.Add_mid(src, trv.Pos(), src_len);
return tmp_bfr.To_bry_and_clear();
}
public byte[] Case_build_upper(byte[] src) {return Case_build_upper(src, 0, src.length);}
public byte[] Case_build_upper(byte[] src, int bgn, int end) {return Case_build(Bool_.Y, src, bgn, end);}
public byte[] Case_build_lower(byte[] src) {return Case_build_lower(src, 0, src.length);}
public byte[] Case_build_lower(byte[] src, int bgn, int end) {return Case_build(Bool_.N, src, bgn, end);}
public byte[] Case_build(boolean upper, byte[] src, int bgn, int end) {
synchronized (thread_lock) { // LOCK:trie; DATE:2016-07-06
int pos = bgn;
tmp_bfr.Clear();
Btrie_fast_mgr trie = upper ? upper_trie : lower_trie;
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Btrie_fast_mgr trie = upper ? upper_trie : lower_trie;
Btrie_rv trv = new Btrie_rv(); // TS.MEM: DATE:2016-07-12
Bry_bfr tmp_bfr = Bry_bfr_.New(); // TS.MEM: DATE:2016-07-12
int pos = bgn;
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Object o = trie.Match_at_w_b0(trv, b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25;
if (o != null && pos < end) { // pos < end used for casing 1st letter only; upper_1st will pass end of 1
Xol_case_itm itm = (Xol_case_itm)o;
if (upper)
itm.Case_build_upper(tmp_bfr);
else
itm.Case_build_lower(tmp_bfr);
}
else {
tmp_bfr.Add_mid(src, pos, pos + b_len);
}
pos += b_len;
Object o = trie.Match_at_w_b0(trv, b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25;
if (o != null && pos < end) { // pos < end used for casing 1st letter only; upper_1st will pass end of 1
Xol_case_itm itm = (Xol_case_itm)o;
if (upper)
itm.Case_build_upper(tmp_bfr);
else
itm.Case_build_lower(tmp_bfr);
}
return tmp_bfr.To_bry_and_clear();
else {
tmp_bfr.Add_mid(src, pos, pos + b_len);
}
pos += b_len;
}
return tmp_bfr.To_bry_and_clear();
}
public byte[] Case_build_1st_upper(Bry_bfr bfr, byte[] src, int bgn, int end) {return Case_build_1st(bfr, Bool_.Y, src, bgn, end);}
public byte[] Case_build_1st_lower(Bry_bfr bfr, byte[] src, int bgn, int end) {return Case_build_1st(bfr, Bool_.N, src, bgn, end);}

View File

@@ -19,9 +19,9 @@ package gplx.xowa.langs.cases; import gplx.*; import gplx.xowa.*; import gplx.xo
import gplx.core.intls.*;
public class Xol_case_mgr_ {
@gplx.Internal protected static Xol_case_mgr new_() {return new Xol_case_mgr(Gfo_case_mgr_.Tid_custom);}
public static Xol_case_mgr A7() {if (mgr_a7 == null) mgr_a7 = new_mgr_a7_(); return mgr_a7;} private static Xol_case_mgr mgr_a7;
public static Xol_case_mgr U8() {if (mgr_u8 == null) mgr_u8 = new_mgr_u8_(); return mgr_u8;} private static Xol_case_mgr mgr_u8;
private static Xol_case_mgr new_mgr_a7_() {
public static Xol_case_mgr A7() {if (mgr_a7 == null) mgr_a7 = New__a7(); return mgr_a7;} private static Xol_case_mgr mgr_a7;
public static Xol_case_mgr U8() {if (mgr_u8 == null) mgr_u8 = New__u8(); return mgr_u8;} private static Xol_case_mgr mgr_u8;
private static Xol_case_mgr New__a7() {
Xol_case_mgr rv = new Xol_case_mgr(Gfo_case_mgr_.Tid_a7);
Xol_case_itm[] itms = new Xol_case_itm[]
{ Xol_case_itm_.new_(0, "a", "A")
@@ -54,7 +54,7 @@ public class Xol_case_mgr_ {
rv.Add_bulk(itms);
return rv;
}
private static Xol_case_mgr new_mgr_u8_() {
private static Xol_case_mgr New__u8() {
Xol_case_mgr rv = new Xol_case_mgr(Gfo_case_mgr_.Tid_u8);
Xol_case_itm[] itms = new Xol_case_itm[]
{ Xol_case_itm_.new_(Xol_case_itm_.Tid_both, Bry_.New_by_ints(97), Bry_.New_by_ints(65)) // a -> A -- LATIN CAPITAL LETTER A