7
7
// option. This file may not be copied, modified, or distributed
8
8
// except according to those terms.
9
9
10
- //! The [ `BufferQueue`] struct and helper types.
10
+ //! The `BufferQueue` struct and helper types.
11
11
//!
12
12
//! This type is designed for the efficient parsing of string data, especially where many
13
13
//! significant characters are from the ascii range 0-63. This includes, for example, important
@@ -35,7 +35,7 @@ use util::smallcharset::SmallCharSet;
35
35
pub enum SetResult {
36
36
/// A character from the `SmallCharSet`.
37
37
FromSet ( char ) ,
38
- /// A block of text containing no characters from the `SmallCharSet`.
38
+ /// A string buffer containing no characters from the `SmallCharSet`.
39
39
NotFromSet ( StrTendril ) ,
40
40
}
41
41
@@ -62,12 +62,14 @@ impl BufferQueue {
62
62
self . buffers . is_empty ( )
63
63
}
64
64
65
- /// Get the tendril at the beginning of the queue.
65
+ /// Get the buffer at the beginning of the queue.
66
66
pub fn pop_front ( & mut self ) -> Option < StrTendril > {
67
67
self . buffers . pop_front ( )
68
68
}
69
69
70
70
/// Add a buffer to the beginning of the queue.
71
+ ///
72
+ /// If the buffer is empty, it will be skipped.
71
73
pub fn push_front ( & mut self , buf : StrTendril ) {
72
74
if buf. len32 ( ) == 0 {
73
75
return ;
@@ -76,20 +78,25 @@ impl BufferQueue {
76
78
}
77
79
78
80
/// Add a buffer to the end of the queue.
81
+ ///
82
+ /// If the buffer is empty, it will be skipped.
79
83
pub fn push_back ( & mut self , buf : StrTendril ) {
80
84
if buf. len32 ( ) == 0 {
81
85
return ;
82
86
}
83
87
self . buffers . push_back ( buf) ;
84
88
}
85
89
86
- /// Look at the next available character, if any .
90
+ /// Look at the next available character without removing it , if the queue is not empty .
87
91
pub fn peek ( & self ) -> Option < char > {
88
92
// Invariant: all buffers in the queue are non-empty.
93
+ debug_assert ! ( self . buffers. iter( ) . skip_while( |el| el. len32( ) != 0 ) . next( ) . is_none( ) ) ;
89
94
self . buffers . front ( ) . map ( |b| b. chars ( ) . next ( ) . unwrap ( ) )
90
95
}
91
96
92
- /// Get the next character, if one is available.
97
+ /// Get the next character if one is available, removing it from the queue.
98
+ ///
99
+ /// This function manages the buffers, removing them as they become empty.
93
100
pub fn next ( & mut self ) -> Option < char > {
94
101
let ( result, now_empty) = match self . buffers . front_mut ( ) {
95
102
None => ( None , false ) ,
0 commit comments