mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Mw_parse.Apos: Add initial implementation
This commit is contained in:
54
400_xowa/src/gplx/langs/phps/utls/Php_preg_.java
Normal file
54
400_xowa/src/gplx/langs/phps/utls/Php_preg_.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.phps.utls; import gplx.*; import gplx.langs.*; import gplx.langs.phps.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Php_preg_ {
|
||||
public static byte[][] Split(Int_list list, byte[] src, int src_bgn, int src_end, byte[] dlm, boolean extend) {
|
||||
// find delimiters
|
||||
int dlm_len = dlm.length;
|
||||
byte dlm_nth = dlm[dlm_len - 1];
|
||||
int i = src_bgn;
|
||||
list.Add(src_bgn);
|
||||
while (true) {
|
||||
if (i == src_end) break;
|
||||
int dlm_end = i + dlm_len;
|
||||
if (dlm_end < src_end && Bry_.Eq(src, i, dlm_end, dlm)) {
|
||||
if (extend) {
|
||||
dlm_end = Bry_find_.Find_fwd_while(src, i, src_end, dlm_nth);
|
||||
}
|
||||
list.Add(i);
|
||||
list.Add(dlm_end);
|
||||
i = dlm_end;
|
||||
}
|
||||
else
|
||||
i++;
|
||||
}
|
||||
list.Add(src_end);
|
||||
|
||||
// create brys
|
||||
int rv_len = list.Len() - 1;
|
||||
if (rv_len == 1) return null;
|
||||
byte[][] rv = new byte[rv_len][];
|
||||
for (i = 0; i < rv_len; i += 2) {
|
||||
rv[i ] = Bry_.Mid(src, list.Get_at(i + 0), list.Get_at(i + 1));
|
||||
if (i + 1 == rv_len) break;
|
||||
rv[i + 1] = Bry_.Mid(src, list.Get_at(i + 1), list.Get_at(i + 2));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
33
400_xowa/src/gplx/langs/phps/utls/Php_preg___tst.java
Normal file
33
400_xowa/src/gplx/langs/phps/utls/Php_preg___tst.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.phps.utls; import gplx.*; import gplx.langs.*; import gplx.langs.phps.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Php_preg___tst {
|
||||
private final Php_preg___fxt fxt = new Php_preg___fxt();
|
||||
@Test public void Split() {
|
||||
fxt.Test__split("a''b''c", "''", Bool_.N, "a", "''", "b", "''", "c");
|
||||
}
|
||||
}
|
||||
class Php_preg___fxt {
|
||||
public void Test__split(String src, String dlm, boolean extend, String... expd) {Test__split(src, 0, String_.Len(src), dlm, extend, expd);}
|
||||
public void Test__split(String src, int src_bgn, int src_end, String dlm, boolean extend, String... expd) {
|
||||
gplx.core.primitives.Int_list rv = new gplx.core.primitives.Int_list();
|
||||
byte[][] actl = Php_preg_.Split(rv, Bry_.new_u8(src), src_bgn, src_end, Bry_.new_u8(dlm), extend);
|
||||
Gftest.Eq__ary(expd, String_.Ary(actl), "find_failed");
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.phps.utls; import gplx.*; import gplx.langs.*; import gplx.langs.phps.*;
|
||||
public class Php_str_ {
|
||||
public static byte[] Substr(byte[] src, int bgn, int len) {return Bry_.Mid(src, bgn, bgn + len);}
|
||||
public static byte[] Substr(byte[] src, int bgn) {
|
||||
return src;
|
||||
}
|
||||
public static byte[] Substr(byte[] src, int bgn, int len) {
|
||||
return Bry_.Mid(src, bgn, bgn + len);
|
||||
}
|
||||
public static int Strspn_fwd__byte(byte[] src, byte find, int bgn, int max, int src_len) {
|
||||
if (max == -1) max = src_len;
|
||||
int rv = 0;
|
||||
|
||||
Reference in New Issue
Block a user