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

Mw_parse: Add basic implementation of Mw_preprocessor

This commit is contained in:
gnosygnu
2017-01-09 21:33:45 -05:00
parent 006c14db4e
commit d15630c433
7 changed files with 905 additions and 5 deletions

View File

@@ -164,6 +164,17 @@ public class Bry_ {
rv[i] = b;
return rv;
}
public static byte[] Repeat_bry(byte[] bry, int len) {
int bry_len = bry.length;
int rv_len = len * bry_len;
byte[] rv = new byte[rv_len];
for (int i = 0; i < len; i++) {
for (int j = 0; j < bry_len; j++) {
rv[(i * bry_len) + j] = bry[j];
}
}
return rv;
}
public static byte[] Add(byte[] src, byte b) {
int src_len = src.length;
byte[] rv = new byte[src_len + 1];

View File

@@ -16,7 +16,7 @@ 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;
import org.junit.*; import gplx.core.primitives.*; import gplx.core.brys.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.tests.*;
public class Bry__tst {
private final Bry__fxt fxt = new Bry__fxt();
@Test public void new_ascii_() {
@@ -276,6 +276,9 @@ public class Bry__tst {
fxt.Test__new_u8_nl_apos(String_.Ary("a", "b"), "a\nb");
fxt.Test__new_u8_nl_apos(String_.Ary("a", "b'c", "d"), "a\nb\"c\nd");
}
@Test public void Repeat_bry() {
fxt.Test__repeat_bry("abc" , 3, "abcabcabc");
}
}
class Bry__fxt {
public void Test_trim_end(String raw, byte trim, String expd) {
@@ -292,4 +295,7 @@ class Bry__fxt {
public void Test__new_u8_nl_apos(String[] ary, String expd) {
Tfds.Eq_str_lines(expd, String_.new_u8(Bry_.New_u8_nl_apos(ary)));
}
public void Test__repeat_bry(String s, int count, String expd) {
Gftest.Eq__str(expd, Bry_.Repeat_bry(Bry_.new_u8(s), count));
}
}

View File

@@ -158,6 +158,19 @@ public class Bry_find_ {
}
return Bry_find_.Not_found;
}
public static int Find_bwd__while_space_or_tab(byte[] src, int cur, int end) { // get pos of 1st char that is not \t or \s
if (cur >= src.length) return Bry_find_.Not_found;
for (int i = cur; i >= end; i--) {
byte b = src[i];
switch (b) {
case Byte_ascii.Space: case Byte_ascii.Tab:
break;
default:
return i;
}
}
return Bry_find_.Not_found;
}
public static int Find_bwd_non_ws_or_end(byte[] src, int cur, int end) {
if (cur >= src.length) return Bry_find_.Not_found;
for (int i = cur; i >= end; i--) {