Skip to content

Commit 972358e

Browse files
committed
0.8.6 no dtoa yet, fix escaping of 0x7F, fixes #58
1 parent 01f1ed5 commit 972358e

File tree

6 files changed

+58
-779
lines changed

6 files changed

+58
-779
lines changed

src/codegen.rs

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,36 @@ use std::num::FpCategory;
33
use JsonValue;
44

55
extern crate itoa;
6-
use dtoa;
76

87
const QU: u8 = b'"';
98
const BS: u8 = b'\\';
10-
const B: u8 = b'b';
11-
const T: u8 = b't';
12-
const N: u8 = b'n';
13-
const F: u8 = b'f';
14-
const R: u8 = b'r';
15-
const U: u8 = b'u';
16-
9+
const BB: u8 = b'b';
10+
const TT: u8 = b't';
11+
const NN: u8 = b'n';
12+
const FF: u8 = b'f';
13+
const RR: u8 = b'r';
14+
const UU: u8 = b'u';
15+
const __: u8 = 0;
16+
17+
// Look up table for characters that need escaping in a product string
1718
static ESCAPED: [u8; 256] = [
1819
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
19-
U, U, U, U, U, U, U, U, B, T, N, U, F, R, U, U, // 0
20-
U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, // 1
21-
0, 0, QU, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2
22-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3
23-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4
24-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, BS, 0, 0, 0, // 5
25-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6
26-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, U, // 7
27-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8
28-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9
29-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A
30-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // B
31-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // C
32-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // D
33-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // E
34-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // F
20+
UU, UU, UU, UU, UU, UU, UU, UU, BB, TT, NN, UU, FF, RR, UU, UU, // 0
21+
UU, UU, UU, UU, UU, UU, UU, UU, UU, UU, UU, UU, UU, UU, UU, UU, // 1
22+
__, __, QU, __, __, __, __, __, __, __, __, __, __, __, __, __, // 2
23+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // 3
24+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // 4
25+
__, __, __, __, __, __, __, __, __, __, __, __, BS, __, __, __, // 5
26+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // 6
27+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // 7
28+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // 8
29+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // 9
30+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // A
31+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // B
32+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // C
33+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // D
34+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // E
35+
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // F
3536
];
3637

3738
pub trait Generator {
@@ -99,7 +100,12 @@ pub trait Generator {
99100
if num.fract() == 0.0 && num.abs() < 1e19 {
100101
itoa::write(self.get_writer(), num as i64).unwrap();
101102
} else {
102-
dtoa::write(self.get_writer(), num).unwrap();
103+
let abs = num.abs();
104+
if abs < 1e-15 || abs > 1e19 {
105+
write!(self.get_writer(), "{:e}", num).unwrap();
106+
} else {
107+
write!(self.get_writer(), "{}", num).unwrap();
108+
}
103109
}
104110
},
105111
FpCategory::Zero => {

src/dtoa/diyfp.rs

Lines changed: 0 additions & 251 deletions
This file was deleted.

0 commit comments

Comments
 (0)