File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -119,15 +119,22 @@ where
119119/// \n} ");
120120///
121121/// ```
122+ #[ inline]
122123pub fn strip_comments_in_place ( s : & mut str ) -> Result < ( ) > {
123124 // Safety: we have made sure the text is UTF-8
124125 strip_buf ( & mut Top , unsafe { s. as_bytes_mut ( ) } )
125126}
126127
128+ #[ inline]
127129pub fn strip ( s : & mut str ) -> Result < ( ) > {
128130 strip_comments_in_place ( s)
129131}
130132
133+ #[ inline]
134+ pub fn strip_slice ( s : & mut [ u8 ] ) -> Result < ( ) > {
135+ strip_buf ( & mut Top , s)
136+ }
137+
131138fn consume_comment_whitespace_until_maybe_bracket (
132139 state : & mut State ,
133140 buf : & mut [ u8 ] ,
Original file line number Diff line number Diff line change 1- use json_strip_comments:: { StripComments , strip, strip_comments_in_place} ;
1+ use json_strip_comments:: { StripComments , strip, strip_comments_in_place, strip_slice } ;
22
33use std:: io:: { ErrorKind , Read } ;
44
@@ -404,3 +404,18 @@ fn special_characters_in_comments() {
404404 assert ! ( stripped. contains( r#""key": "value""# ) ) ;
405405 assert ! ( stripped. contains( r#""key2": "value2""# ) ) ;
406406}
407+
408+ #[ test]
409+ fn slice_api ( ) {
410+ let mut json = String :: from (
411+ r#"{
412+ "a": 1, // comment after comma
413+ "b": 2
414+ }"# ,
415+ )
416+ . into_bytes ( ) ;
417+ strip_slice ( & mut json) . unwrap ( ) ;
418+ let json = String :: from_utf8 ( json) . unwrap ( ) ;
419+ assert ! ( json. contains( r#""a": 1,"# ) ) ;
420+ assert ! ( json. contains( r#""b": 2"# ) ) ;
421+ }
You can’t perform that action at this time.
0 commit comments