@@ -129,16 +129,18 @@ impl TitleCursor {
129129 /// 切分节点名。
130130 pub fn split_on < ' de > ( & self , dtb : RefDtb < ' de > ) -> ( & ' de str , BodyCursor ) {
131131 let mut index = self . 0 + 1 ;
132+ let mut len = 0 ;
132133
133134 let structure = & dtb. borrow ( ) . structure ;
134- let ptr = structure[ index..] . as_ptr ( ) as * const u8 ;
135135 while let Some ( block) = structure. get ( index) {
136136 index += 1 ;
137137 if block. is_end_of_str ( ) {
138138 let end = block. str_end ( ) ;
139- let s = unsafe { core :: slice :: from_raw_parts ( ptr , end. offset_from ( ptr ) as _ ) } ;
140- let s = unsafe { core :: str :: from_utf8_unchecked ( s ) } ;
139+ len += end;
140+ let s = structure [ self . 0 + 1 ] . lead_str ( len ) ;
141141 return ( s, AnyCursor ( index, PhantomData ) ) ;
142+ } else {
143+ len += 4 ;
142144 }
143145 }
144146 todo ! ( )
@@ -158,12 +160,7 @@ impl TitleCursor {
158160 body. skip_str_on ( dtb) ;
159161 body. escape_from ( dtb) ;
160162 if let Cursor :: Title ( c) = body. move_on ( dtb) {
161- let s = unsafe {
162- core:: slice:: from_raw_parts (
163- structure[ c. 0 + 1 ..] . as_ptr ( ) as * const u8 ,
164- name_bytes. len ( ) + 1 ,
165- )
166- } ;
163+ let s = structure[ c. 0 + 1 ] . lead_slice ( name_bytes. len ( ) + 1 ) ;
167164 if let [ name @ .., b'@' ] = s {
168165 if name == name_bytes {
169166 body. 0 += 1 + name_skip;
@@ -213,15 +210,15 @@ impl PropCursor {
213210
214211 pub fn data_on < ' a > ( & self , dtb : RefDtb < ' a > ) -> & ' a [ u8 ] {
215212 if let [ _, len_data, _, data @ ..] = & dtb. borrow ( ) . structure [ self . 0 ..] {
216- unsafe { core :: slice :: from_raw_parts ( data. as_ptr ( ) as _ , len_data. as_usize ( ) ) }
213+ data[ 0 ] . lead_slice ( len_data. as_usize ( ) )
217214 } else {
218215 todo ! ( )
219216 }
220217 }
221218
222219 pub fn map_on < T > ( & self , dtb : RefDtb < ' _ > , f : impl FnOnce ( & [ u8 ] ) -> T ) -> T {
223220 if let [ _, len_data, _, data @ ..] = & dtb. borrow ( ) . structure [ self . 0 ..] {
224- f ( unsafe { core :: slice :: from_raw_parts ( data. as_ptr ( ) as _ , len_data. as_usize ( ) ) } )
221+ f ( data[ 0 ] . lead_slice ( len_data. as_usize ( ) ) )
225222 } else {
226223 todo ! ( )
227224 }
0 commit comments