Skip to content

Commit 300d0fc

Browse files
author
Richard Dodd
committed
Debug check invariant, add more docs
1 parent 936512e commit 300d0fc

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

markup5ever/util/buffer_queue.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
//! The [`BufferQueue`] struct and helper types.
10+
//! The `BufferQueue` struct and helper types.
1111
//!
1212
//! This type is designed for the efficient parsing of string data, especially where many
1313
//! significant characters are from the ascii range 0-63. This includes, for example, important
@@ -35,7 +35,7 @@ use util::smallcharset::SmallCharSet;
3535
pub enum SetResult {
3636
/// A character from the `SmallCharSet`.
3737
FromSet(char),
38-
/// A block of text containing no characters from the `SmallCharSet`.
38+
/// A string buffer containing no characters from the `SmallCharSet`.
3939
NotFromSet(StrTendril),
4040
}
4141

@@ -62,12 +62,14 @@ impl BufferQueue {
6262
self.buffers.is_empty()
6363
}
6464

65-
/// Get the tendril at the beginning of the queue.
65+
/// Get the buffer at the beginning of the queue.
6666
pub fn pop_front(&mut self) -> Option<StrTendril> {
6767
self.buffers.pop_front()
6868
}
6969

7070
/// Add a buffer to the beginning of the queue.
71+
///
72+
/// If the buffer is empty, it will be skipped.
7173
pub fn push_front(&mut self, buf: StrTendril) {
7274
if buf.len32() == 0 {
7375
return;
@@ -76,20 +78,25 @@ impl BufferQueue {
7678
}
7779

7880
/// Add a buffer to the end of the queue.
81+
///
82+
/// If the buffer is empty, it will be skipped.
7983
pub fn push_back(&mut self, buf: StrTendril) {
8084
if buf.len32() == 0 {
8185
return;
8286
}
8387
self.buffers.push_back(buf);
8488
}
8589

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.
8791
pub fn peek(&self) -> Option<char> {
8892
// Invariant: all buffers in the queue are non-empty.
93+
debug_assert!(self.buffers.iter().skip_while(|el| el.len32() != 0).next().is_none());
8994
self.buffers.front().map(|b| b.chars().next().unwrap())
9095
}
9196

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.
93100
pub fn next(&mut self) -> Option<char> {
94101
let (result, now_empty) = match self.buffers.front_mut() {
95102
None => (None, false),

0 commit comments

Comments
 (0)