mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v3.1.4.2
This commit is contained in:
@@ -84,6 +84,37 @@ public class Bry_ {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static byte[] New_u8_nl_apos(String... lines) {
|
||||
Bry_bfr bfr = Bry_bfr_.Get();
|
||||
try {
|
||||
New_u8_nl_apos(bfr, lines);
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
finally {bfr.Mkr_rls();}
|
||||
}
|
||||
public static void New_u8_nl_apos(Bry_bfr bfr, String... lines) {
|
||||
int lines_len = lines.length;
|
||||
for (int i = 0; i < lines_len; ++i) {
|
||||
if (i != 0) bfr.Add_byte_nl();
|
||||
byte[] line = Bry_.new_u8(lines[i]);
|
||||
boolean dirty = false;
|
||||
int prv = 0;
|
||||
int line_len = line.length;
|
||||
for (int j = 0; j < line_len; ++j) {
|
||||
byte b = line[j];
|
||||
if (b == Byte_ascii.Apos) {
|
||||
bfr.Add_mid(line, prv, j);
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
dirty = true;
|
||||
prv = j + 1;
|
||||
}
|
||||
}
|
||||
if (dirty)
|
||||
bfr.Add_mid(line, prv, line_len);
|
||||
else
|
||||
bfr.Add(line);
|
||||
}
|
||||
}
|
||||
public static void new_u8__write(String str, int str_len, byte[] bry, int bry_pos) {
|
||||
for (int i = 0; i < str_len; ++i) {
|
||||
char c = str.charAt(i);
|
||||
|
||||
@@ -271,6 +271,11 @@ public class Bry__tst {
|
||||
fxt.Test_Mid_w_trim("", ""); // handle 0 bytes
|
||||
fxt.Test_Mid_w_trim(" ", ""); // handle all ws
|
||||
}
|
||||
@Test public void New_u8_nl_apos() {
|
||||
fxt.Test__new_u8_nl_apos(String_.Ary("a"), "a");
|
||||
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");
|
||||
}
|
||||
}
|
||||
class Bry__fxt {
|
||||
public void Test_trim_end(String raw, byte trim, String expd) {
|
||||
@@ -284,4 +289,7 @@ class Bry__fxt {
|
||||
public void Test_add_w_dlm(String dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(Bry_.new_u8(dlm), Bry_.Ary(itms))));}
|
||||
public void Test_add_w_dlm(byte dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(dlm, Bry_.Ary(itms))));}
|
||||
public void Test_Mid_w_trim(String src, String expd) {byte[] bry = Bry_.new_u8(src); Tfds.Eq(expd, String_.new_u8(Bry_.Mid_w_trim(bry, 0, bry.length)));}
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,6 +319,14 @@ public class String_ implements GfoInvkAble {
|
||||
sb.Add(val).Add("\n");
|
||||
return sb.To_str();
|
||||
}
|
||||
public static String Concat_lines_nl_apos_skip_last(String... lines) {
|
||||
Bry_bfr bfr = Bry_bfr_.Get();
|
||||
try {
|
||||
Bry_.New_u8_nl_apos(bfr, lines);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
finally {bfr.Mkr_rls();}
|
||||
}
|
||||
public static String Concat_lines_nl_skip_last(String... ary) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
int ary_len = ary.length; int ary_end = ary_len - 1;
|
||||
|
||||
Reference in New Issue
Block a user