mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Create core dbs in proper subdirectory
This commit is contained in:
@@ -13,3 +13,42 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_url_encoder { // NOTE: redundant with Gfo_url_encoder, but is simpler; DATE:2016-09-15
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public byte[] Encode(byte[] src) {
|
||||
int src_len = src.length;
|
||||
boolean dirty = false;
|
||||
for (int i = 0; i < src_len; ++i) {
|
||||
byte b = src[i];
|
||||
byte[] repl = null;
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: repl = Bry__underline; break;
|
||||
case Byte_ascii.Amp: repl = Bry__amp; break;
|
||||
case Byte_ascii.Apos: repl = Bry__apos; break;
|
||||
case Byte_ascii.Eq: repl = Bry__eq; break;
|
||||
case Byte_ascii.Plus: repl = Bry__plus; break;
|
||||
}
|
||||
|
||||
// not a replacement sequence
|
||||
if (repl == null) {
|
||||
// if dirty, add to bfr; else, ignore
|
||||
if (dirty)
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
else {
|
||||
// if clean, add everything before cur_pos to bfr
|
||||
if (!dirty) {
|
||||
bfr.Add_mid(src, 0, i);
|
||||
dirty = true;
|
||||
}
|
||||
bfr.Add(repl);
|
||||
}
|
||||
}
|
||||
return dirty ? bfr.To_bry_and_clear() : src;
|
||||
}
|
||||
private static final byte[] Bry__amp = Bry_.new_a7("%26"), Bry__eq = Bry_.new_a7("%3D")
|
||||
, Bry__plus = Bry_.new_a7("%2B"), Bry__apos = Bry_.new_a7("%27")
|
||||
, Bry__underline = new byte[] {Byte_ascii.Underline}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,17 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoa_url_encoder__tst {
|
||||
private final Xoa_url_encoder__fxt fxt = new Xoa_url_encoder__fxt();
|
||||
@Test public void Syms__diff() {fxt.Test__encode(" &'=+", "_%26%27%3D%2B");}
|
||||
@Test public void Syms__same() {fxt.Test__encode("!\"#$%()*,-./:;<>?@[\\]^_`{|}~", "!\"#$%()*,-./:;<>?@[\\]^_`{|}~");}
|
||||
@Test public void Mixed() {fxt.Test__encode("a &'=+b", "a_%26%27%3D%2Bb");} // PURPOSE: make sure dirty flag is set
|
||||
}
|
||||
class Xoa_url_encoder__fxt {
|
||||
private final Xoa_url_encoder encoder = new Xoa_url_encoder();
|
||||
public void Test__encode(String raw, String expd) {
|
||||
Gftest.Eq__bry(Bry_.new_u8(expd), encoder.Encode(Bry_.new_u8(raw)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user