mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Full-text search: Escape tab and carriage return in json callbacks
This commit is contained in:
@@ -267,7 +267,8 @@ public class Json_wtr {
|
||||
bfr.Add_byte(b);
|
||||
break;
|
||||
case Byte_ascii.Nl: bfr.Add_byte_repeat(Byte_ascii.Backslash, 2).Add_byte(Byte_ascii.Ltr_n); break; // "\n" -> "\\n"
|
||||
case Byte_ascii.Cr: break;// skip
|
||||
case Byte_ascii.Cr: bfr.Add_byte_repeat(Byte_ascii.Backslash, 2).Add_byte(Byte_ascii.Ltr_r); break; // "\r" -> "\\r"; DATE:2017-03-02
|
||||
case Byte_ascii.Tab: bfr.Add_byte_repeat(Byte_ascii.Backslash, 2).Add_byte(Byte_ascii.Ltr_t); break; // "\t" -> "\\t"; DATE:2017-03-02
|
||||
default: bfr.Add_byte(b); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Json_wtr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Json_wtr_fxt fxt = new Json_wtr_fxt();
|
||||
@Before public void init() {fxt.Clear();} private final Json_wtr_fxt fxt = new Json_wtr_fxt();
|
||||
@Test public void Root() {
|
||||
fxt.Wtr().Doc_nde_bgn().Doc_nde_end();
|
||||
fxt.Test
|
||||
@@ -36,6 +36,26 @@ public class Json_wtr_tst {
|
||||
, "}"
|
||||
);
|
||||
}
|
||||
@Test public void Escaped() {
|
||||
fxt.Wtr()
|
||||
.Doc_nde_bgn()
|
||||
.Kv_str("backslash", "\\")
|
||||
.Kv_str("quote", "\"")
|
||||
.Kv_str("apos", "'")
|
||||
.Kv_str("nl", "\n")
|
||||
.Kv_str("cr", "\r")
|
||||
.Kv_str("tab", "\t")
|
||||
.Doc_nde_end();
|
||||
fxt.Test
|
||||
( "{ 'backslash':'\\\\'"
|
||||
, ", 'quote':'\\\"'"
|
||||
, ", 'apos':'\''"
|
||||
, ", 'nl':'\\\\n'"
|
||||
, ", 'cr':'\\\\r'"
|
||||
, ", 'tab':'\\\\t'"
|
||||
, "}"
|
||||
);
|
||||
}
|
||||
@Test public void Nde() {
|
||||
fxt.Wtr()
|
||||
.Doc_nde_bgn()
|
||||
@@ -100,7 +120,7 @@ public class Json_wtr_tst {
|
||||
}
|
||||
}
|
||||
class Json_wtr_fxt {
|
||||
private final Json_wtr wtr = new Json_wtr().Opt_quote_byte_(Byte_ascii.Apos);
|
||||
private final Json_wtr wtr = new Json_wtr().Opt_quote_byte_(Byte_ascii.Apos);
|
||||
public void Clear() {wtr.Clear();}
|
||||
public Json_wtr Wtr() {return wtr;}
|
||||
public void Test(String... expd) {
|
||||
|
||||
Reference in New Issue
Block a user