@@ -7,7 +7,7 @@ const HEX_DIGITS: [u8; 16] = *b"0123456789abcdef";
7
7
8
8
/// Escapes a byte into provided buffer; returns length of escaped
9
9
/// representation.
10
- pub ( super ) fn escape_ascii_into ( output : & mut [ u8 ; 4 ] , byte : u8 ) -> Range < u8 > {
10
+ pub ( crate ) fn escape_ascii_into ( output : & mut [ u8 ; 4 ] , byte : u8 ) -> Range < u8 > {
11
11
let ( data, len) = match byte {
12
12
b'\t' => ( [ b'\\' , b't' , 0 , 0 ] , 2 ) ,
13
13
b'\r' => ( [ b'\\' , b'r' , 0 , 0 ] , 2 ) ,
@@ -25,11 +25,10 @@ pub(super) fn escape_ascii_into(output: &mut [u8; 4], byte: u8) -> Range<u8> {
25
25
}
26
26
27
27
/// Escapes a character into provided buffer using `\u{NNNN}` representation.
28
- pub ( super ) fn escape_unicode_into ( output : & mut [ u8 ; 10 ] , ch : char ) -> Range < u8 > {
29
- let ch = ( ch as u32 ) & 0x1f_ffff ;
30
-
28
+ pub ( crate ) fn escape_unicode_into ( output : & mut [ u8 ; 10 ] , ch : char ) -> Range < u8 > {
31
29
output[ 9 ] = b'}' ;
32
30
31
+ let ch = ch as u32 ;
33
32
output[ 3 ] = HEX_DIGITS [ ( ( ch >> 20 ) & 15 ) as usize ] ;
34
33
output[ 4 ] = HEX_DIGITS [ ( ( ch >> 16 ) & 15 ) as usize ] ;
35
34
output[ 5 ] = HEX_DIGITS [ ( ( ch >> 12 ) & 15 ) as usize ] ;
@@ -50,24 +49,25 @@ pub(super) fn escape_unicode_into(output: &mut [u8; 10], ch: char) -> Range<u8>
50
49
/// This is essentially equivalent to array’s IntoIter except that indexes are
51
50
/// limited to u8 to reduce size of the structure.
52
51
#[ derive( Clone , Debug ) ]
53
- pub ( super ) struct EscapeIterInner < const N : usize > {
52
+ pub ( crate ) struct EscapeIterInner < const N : usize > {
54
53
// Invariant: data[alive] is all ASCII.
55
- pub ( super ) data : [ u8 ; N ] ,
54
+ pub ( crate ) data : [ u8 ; N ] ,
56
55
57
56
// Invariant: alive.start <= alive.end <= N.
58
- pub ( super ) alive : Range < u8 > ,
57
+ pub ( crate ) alive : Range < u8 > ,
59
58
}
60
59
61
60
impl < const N : usize > EscapeIterInner < N > {
62
61
pub fn new ( data : [ u8 ; N ] , alive : Range < u8 > ) -> Self {
62
+ const { assert ! ( N < 256 ) } ;
63
63
debug_assert ! ( alive. start <= alive. end && usize :: from( alive. end) <= N , "{alive:?}" ) ;
64
64
let this = Self { data, alive } ;
65
65
debug_assert ! ( this. as_bytes( ) . is_ascii( ) , "Expected ASCII, got {:?}" , this. as_bytes( ) ) ;
66
66
this
67
67
}
68
68
69
69
fn as_bytes ( & self ) -> & [ u8 ] {
70
- & self . data [ ( self . alive . start as usize ) ..( self . alive . end as usize ) ]
70
+ & self . data [ usize :: from ( self . alive . start ) ..usize :: from ( self . alive . end ) ]
71
71
}
72
72
73
73
pub fn as_str ( & self ) -> & str {
0 commit comments