mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Mw_parse: Add basic implementation for magiclinks
This commit is contained in:
@@ -40,6 +40,7 @@ public class Regx_adp {
|
||||
return (Regx_match[])rv.To_ary(Regx_match.class);
|
||||
}
|
||||
private Pattern under;
|
||||
public Pattern Under() {return under;}
|
||||
void Under_sync() {
|
||||
try {under = Pattern.compile(pattern, Pattern.DOTALL | Pattern.UNICODE_CHARACTER_CLASS);} // JRE.7:UNICODE_CHARACTER_CLASS; added during %w fix for en.w:A#; DATE:2015-06-10
|
||||
catch (Exception e) { // NOTE: if invalid, then default to empty pattern (which should return nothing); EX:d:〆る generates [^]; DATE:2013-10-20
|
||||
|
||||
@@ -17,10 +17,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.regxs; import gplx.*; import gplx.langs.*;
|
||||
public class Regx_group {
|
||||
public Regx_group(boolean rslt, int bgn, int end, String val) {this.rslt = rslt; this.bgn = bgn; this.end = end; this.val = val;}
|
||||
public boolean Rslt() {return rslt;} private boolean rslt;
|
||||
public int Bgn() {return bgn;} int bgn;
|
||||
public int End() {return end;} int end;
|
||||
public String Val() {return val;} private String val;
|
||||
public static final Regx_group[] Ary_empty = new Regx_group[0];
|
||||
public Regx_group(boolean rslt, int bgn, int end, String val) {
|
||||
this.rslt = rslt;
|
||||
this.bgn = bgn;
|
||||
this.end = end;
|
||||
this.val = val;
|
||||
}
|
||||
public boolean Rslt() {return rslt;} private boolean rslt;
|
||||
public int Bgn() {return bgn;} private int bgn;
|
||||
public int End() {return end;} private int end;
|
||||
public String Val() {return val;} private String val;
|
||||
public void Init(boolean rslt, int bgn, int end, String val) {
|
||||
this.rslt = rslt;
|
||||
this.bgn = bgn;
|
||||
this.end = end;
|
||||
this.val = val;
|
||||
}
|
||||
public static final Regx_group[] Ary_empty = new Regx_group[0];
|
||||
}
|
||||
|
||||
@@ -24,5 +24,5 @@ public class Regx_match {
|
||||
public int Find_end() {return find_end;} int find_end;
|
||||
public int Find_len() {return find_end - find_bgn;}
|
||||
public Regx_group[] Groups() {return groups;} Regx_group[] groups = Regx_group.Ary_empty;
|
||||
public static final Regx_match[] Ary_empty = new Regx_match[0];
|
||||
public static final Regx_match[] Ary_empty = new Regx_match[0];
|
||||
}
|
||||
|
||||
46
100_core/src/gplx/langs/regxs/Regx_rslt.java
Normal file
46
100_core/src/gplx/langs/regxs/Regx_rslt.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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.langs.regxs; import gplx.*; import gplx.langs.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
public class Regx_rslt {// THREAD.UNSAFE
|
||||
private int src_pos;
|
||||
private Regx_group tmp_grp = new Regx_group(false, -1, -1, null);
|
||||
public Matcher match;
|
||||
public int Groups__len() {return match.groupCount() + 1;} // +1 to include group=0 which is entire pattern
|
||||
public Regx_group Groups__get_at(int i) {
|
||||
tmp_grp.Init(true, match.start(i), match.end(i), null);
|
||||
return tmp_grp;
|
||||
}
|
||||
public void Init(Regx_adp regex, String src, int src_bgn) {
|
||||
match = regex.Under().matcher(src);
|
||||
this.src_pos = src_bgn;
|
||||
}
|
||||
public boolean Match_next() {
|
||||
this.found = match.find(src_pos);
|
||||
if (found) {
|
||||
this.find_bgn = match.start();
|
||||
this.find_end = match.end();
|
||||
this.src_pos = find_end;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
public boolean Found() {return found;} private boolean found;
|
||||
public int Find_bgn() {return find_bgn;} private int find_bgn;
|
||||
public int Find_end() {return find_end;} private int find_end;
|
||||
}
|
||||
Reference in New Issue
Block a user