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

HTTP Server: Generalize file:///root logic even more [#524]

This commit is contained in:
gnosygnu
2019-08-14 21:51:50 -04:00
parent 1e254caa79
commit 5ac949e8c0
4 changed files with 47 additions and 100 deletions

View File

@@ -978,6 +978,43 @@ public class Bry_ {
}
return bfr.To_bry_and_clear();
}
public static byte[] Replace_many(byte[] src, byte[] find, byte[] repl) {
Bry_bfr bfr = null;
int src_len = src.length;
int find_len = find.length;
int pos = 0;
while (true) {
// find find_bgn
int find_bgn = Bry_find_.Find_fwd(src, find, pos, src_len);
// exit if nothing found
if (find_bgn == Bry_find_.Not_found)
break;
// lazy-instantiation
if (bfr == null)
bfr = Bry_bfr_.New();
// add everything up to find_bgn
bfr.Add_mid(src, pos, find_bgn);
// add repl
bfr.Add(repl);
// move pos forward
pos = find_bgn + find_len;
}
// nothing found; return src
if (bfr == null)
return src;
else {
// add rest
bfr.Add_mid(src, pos, src_len);
return bfr.To_bry_and_clear();
}
}
public static int Trim_end_pos(byte[] src, int end) {
for (int i = end - 1; i > -1; i--) {
switch (src[i]) {