Skip to content

Commit 2b5e4e7

Browse files
committed
Remove raw strings.
1 parent 303f5d7 commit 2b5e4e7

File tree

8 files changed

+3
-20
lines changed

8 files changed

+3
-20
lines changed

jaq-json/src/cbor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ fn encode<W: Write>(v: &Val, encoder: &mut Encoder<W>) -> Result<(), W::Error> {
234234
Val::Num(Num::Dec(d)) => encode(&Val::Num(Num::from_dec_str(d)), encoder),
235235
Val::Str(s, Tag::Utf8) => encoder.text(&String::from_utf8_lossy(s), None),
236236
Val::Str(b, Tag::Bytes) => encoder.bytes(b, None),
237-
Val::Str(b, Tag::Raw) => encoder.write_all(b),
238237
Val::Arr(a) => {
239238
encoder.push(Header::Array(Some(a.len())))?;
240239
a.iter().try_for_each(|x| encode(x, encoder))

jaq-json/src/funs.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{Error, Num, Tag, Val, ValR, ValX};
2-
use alloc::{boxed::Box, string::ToString, vec::Vec};
2+
use alloc::{boxed::Box, vec::Vec};
33
use bstr::ByteSlice;
44
use bytes::{BufMut, Bytes, BytesMut};
55
use jaq_core::box_iter::{box_once, BoxIter};
@@ -16,7 +16,7 @@ impl Val {
1616
Val::Null => Ok(Val::from(0usize)),
1717
Val::Num(n) => Ok(Val::Num(n.length())),
1818
Val::Str(s, Tag::Utf8) => Ok(Val::from(s.chars().count() as isize)),
19-
Val::Str(b, Tag::Bytes | Tag::Raw) => Ok(Val::from(b.len() as isize)),
19+
Val::Str(b, Tag::Bytes) => Ok(Val::from(b.len() as isize)),
2020
Val::Arr(a) => Ok(Val::from(a.len() as isize)),
2121
Val::Obj(o) => Ok(Val::from(o.len() as isize)),
2222
Val::Bool(_) => Err(Error::str(format_args!("{self} has no length"))),
@@ -131,12 +131,6 @@ fn base<D: for<'a> DataT<V<'a> = Val>>() -> Box<[Filter<RunPtr<D>>]> {
131131
let fail = |v| Error::str(format_args!("cannot convert {v} to bytes"));
132132
bome(cv.1.to_bytes().map(pass).map_err(fail))
133133
}),
134-
("torawstring", v(0), |cv| {
135-
box_once(Ok(match cv.1 {
136-
Val::Str(s, _) => Val::Str(s, Tag::Raw),
137-
v => Val::Str(v.to_string().into(), Tag::Raw),
138-
}))
139-
}),
140134
("length", v(0), |cv| bome(cv.1.length())),
141135
("contains", v(1), |cv| {
142136
unary(cv, |x, y| Ok(Val::from(x.contains(&y))))

jaq-json/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ pub enum Val {
7373
/// as well as how a string is printed.
7474
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
7575
pub enum Tag {
76-
/// Sequence of bytes, not to be escaped
77-
Raw,
7876
/// Sequence of bytes, to be escaped
7977
Bytes,
8078
/// Sequence of UTF-8 code points

jaq-json/src/serde_json.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! [`serde_json::Value`] support.
22
use crate::{Num, Tag, Val};
33
use alloc::string::ToString;
4-
use bytes::Bytes;
54
use jaq_std::ValT;
65

76
impl From<serde_json::Value> for Val {
@@ -24,8 +23,6 @@ pub enum SError {
2423
Num(Num),
2524
/// Non-string key in object
2625
Key(Val),
27-
/// Raw string
28-
Raw(Bytes),
2926
}
3027

3128
fn from_key(k: &Val) -> Result<&[u8], SError> {
@@ -48,7 +45,6 @@ impl TryFrom<&Val> for serde_json::Value {
4845
),
4946
Val::Str(s, Tag::Utf8) => String(from_utf8(&*s)),
5047
Val::Str(s, Tag::Bytes) => String(s.iter().copied().map(char::from).collect()),
51-
Val::Str(s, Tag::Raw) => Err(SError::Raw(s.clone()))?,
5248
Val::Arr(a) => Array(a.iter().map(TryInto::try_into).collect::<Result<_, _>>()?),
5349
Val::Obj(o) => Object(
5450
o.iter()

jaq-json/src/toml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn val_item(v: &Val) -> Result<Item, SError> {
128128
fn val_value(v: &Val) -> Result<Value, SError> {
129129
let fail = || SError::Val(v.clone());
130130
Ok(match v {
131-
Val::Null | Val::Str(_, Tag::Bytes | Tag::Raw) => Err(fail())?,
131+
Val::Null | Val::Str(_, Tag::Bytes) => Err(fail())?,
132132
Val::Bool(b) => Value::Boolean(Formatted::new(*b)),
133133
Val::Str(s, Tag::Utf8) => {
134134
Value::String(Formatted::new(String::from_utf8_lossy(s).into_owned()))

jaq-json/src/write.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ macro_rules! write_val {
9292
Val::Null => write!($w, "null"),
9393
Val::Bool(b) => write!($w, "{b}"),
9494
Val::Num(n) => write!($w, "{n}"),
95-
Val::Str(s, Tag::Raw) => write!($w, "{}", bstr(s)),
9695
Val::Str(b, Tag::Bytes) => write_bytes!($w, b),
9796
Val::Str(s, Tag::Utf8) => write_utf8!($w, s, |part| write!($w, "{}", bstr(part))),
9897
Val::Arr(a) => {
@@ -126,7 +125,6 @@ type FormatFn<T> = fn(&mut Formatter, &T) -> fmt::Result;
126125

127126
pub(crate) fn write_with(w: &mut dyn Write, v: &Val, f: WriteFn<Val>) -> io::Result<()> {
128127
match v {
129-
Val::Str(s, Tag::Raw) => w.write_all(s),
130128
Val::Str(b, Tag::Bytes) => write_bytes!(w, b),
131129
Val::Str(s, Tag::Utf8) => write_utf8!(w, s, |part| w.write_all(part)),
132130
_ => write_val!(w, v, |v: &Val| f(w, v)),

jaq-play/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ fn fmt_val(f: &mut Formatter, opts: &PpOpts, level: usize, v: &Val) -> fmt::Resu
8787
Val::Null => span(f, "null", "null"),
8888
Val::Bool(b) => span(f, "boolean", b),
8989
Val::Num(n) => span(f, "number", n),
90-
Val::Str(s, Tag::Raw) => write!(f, "{}", bstr(&escape_bytes(s))),
9190
Val::Str(b, Tag::Bytes) => {
9291
let fun = FormatterFn(move |f: &mut Formatter| write_bytes!(f, b));
9392
span(f, "bytes", escape_str(&fun.to_string()))

jaq/src/write.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ fn write_rec(w: &mut dyn Write, pp: &Pp, level: usize, v: &Val, rec: WriteFn) ->
7474
write_utf8!(w, s, |part| w.write_all(part))
7575
}),
7676
Val::Str(b, Tag::Bytes) => style.write(w, style.red, |w| write_bytes!(w, b)),
77-
Val::Str(s, Tag::Raw) => w.write_all(s),
7877
Val::Arr(a) => {
7978
bold(w, '[')?;
8079
if !a.is_empty() {

0 commit comments

Comments
 (0)