mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.2.1'
This commit is contained in:
@@ -18,7 +18,10 @@ 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 Bry_bfr tmp_bfr = Bry_bfr_.New(); private Btrie_fast_mgr upper_trie = Btrie_fast_mgr.cs(), lower_trie = Btrie_fast_mgr.cs(); private Xol_case_itm[] itms;
|
||||
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;
|
||||
public Gfo_case_itm Get_or_null(byte bgn_byte, byte[] src, int bgn, int end) {
|
||||
@@ -58,65 +61,73 @@ 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) {
|
||||
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_bgn_w_byte(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_reuse_upper(src, pos, b_len);
|
||||
else
|
||||
itm.Case_reuse_lower(src, pos, b_len);
|
||||
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;
|
||||
}
|
||||
else {} // noop
|
||||
pos += b_len;
|
||||
return src;
|
||||
}
|
||||
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);
|
||||
Object o = upper_trie.Match_bgn_w_byte(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);
|
||||
int pos = upper_trie.Match_pos();
|
||||
tmp_bfr.Add_mid(src, pos, src_len);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
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];
|
||||
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();
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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_bgn_w_byte(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);
|
||||
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;
|
||||
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;
|
||||
}
|
||||
else {
|
||||
tmp_bfr.Add_mid(src, pos, pos + b_len);
|
||||
}
|
||||
pos += b_len;
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
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);}
|
||||
|
||||
Reference in New Issue
Block a user