pub struct Buffer(/* private fields */);
Expand description
It is simply a vector of Syllable
(private struct).
See its methods to find examples.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Initialize the buffer with a capacity. Remember the capacity is for
Syllable
(private struct).
It is a capacity for input like u8
and char
.
Sourcepub fn put<T>(&mut self, byte_candidate: T) -> Option<T>
pub fn put<T>(&mut self, byte_candidate: T) -> Option<T>
Put a byte(‘u8’) or a ‘char’ into the buffer. A valid byte_candidate should be
meets all of the following requirements:
1. a valid English letter in ASCII chart.
2. this English letter must has a corresponding valid modern Hangul Jamo as
in a standard Korean 2-set(QWERT) keyboard.
When a byte_candidate is accepted by the buffer, this will return None.
When a byte_candidate can’t be matched with a valid modern Hangul Jamo, this
will return Some(byte_candidate)
.
§Example
use sejong::{Buffer, Byte};
let mut buf = Buffer::default();
assert!(buf.put(Byte::NG as u8).is_none());
assert!(buf.put('k').is_none());
assert_eq!(buf.put('M').unwrap(), 'M');
assert_eq!(buf.to_string(), "아");
Sourcepub fn pop(&mut self) -> Option<()>
pub fn pop(&mut self) -> Option<()>
Removes the last single Jamo put. Returns Some(())
when it succeeds.
Returns None
when it fails. It fails when buffer is empty.
§Example
use sejong::{Buffer, Byte};
let mut buf = Buffer::default();
buf.put(Byte::NG as u8);
buf.put(Byte::A as u8);
buf.put(Byte::N as u8);
assert_eq!(buf.to_string(), "안");
assert_eq!(buf.pop().unwrap(), ());
assert_eq!(buf.to_string(), "아");
assert_eq!(buf.pop().unwrap(), ());
assert_eq!(buf.pop().unwrap(), ());
assert_eq!(buf.to_string(), "");
assert!(buf.pop().is_none());
Sourcepub fn out(&mut self) -> String
pub fn out(&mut self) -> String
Output the buffer as a UTF-32 string. Calling this method clears the buffer.
If buffer needs to be preserved, use Buffer::to_string
.
§Example
use sejong::{Buffer, Byte};
let mut buf = Buffer::default();
buf.put(Byte::NG as u8);
buf.put(Byte::A as u8);
buf.put(Byte::N as u8);
assert_eq!(buf.out(), "안");
assert_eq!(buf.to_string(), "");
Sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Output the buffer as a UTF-32 string. It is very similar with Buffer::out
.
But to_string()
doesn’t clear the buffer. It always reflect the
current state of the buffer.
§Example
use sejong::{Buffer, Byte};
let mut buf = Buffer::default();
buf.put(Byte::NG as u8);
buf.put(Byte::A as u8);
buf.put(Byte::N as u8);
assert_eq!(buf.to_string(), "안");
assert_eq!(buf.to_string(), "안");