Struct scribe::buffer::GapBuffer [−][src]
pub struct GapBuffer { /* fields omitted */ }
A UTF-8 string buffer designed to minimize reallocations, maintaining performance amid frequent modifications.
Methods
impl GapBuffer
[src]
impl GapBuffer
pub fn new(data: String) -> GapBuffer
[src]
pub fn new(data: String) -> GapBuffer
Initializes a gap buffer with the specified data as its contents.
Examples
use scribe::buffer::GapBuffer; let buffer = GapBuffer::new("scribe".to_string()); assert_eq!(buffer.to_string(), "scribe");
pub fn insert(&mut self, data: &str, position: &Position)
[src]
pub fn insert(&mut self, data: &str, position: &Position)
Inserts the specified data into the buffer at the specified position. The buffer will reallocate if there is insufficient space. If the position is out of bounds, the buffer contents will remain unchanged.
Examples
use scribe::buffer::GapBuffer; let mut buffer = GapBuffer::new("my buffer data".to_string()); buffer.insert(" changed", &scribe::buffer::Position{ line: 0, offset: 2}); assert_eq!("my changed buffer data", buffer.to_string());
pub fn read(&self, range: &Range) -> Option<String>
[src]
pub fn read(&self, range: &Range) -> Option<String>
Returns the specified range of data from the buffer. If any part of the range does not exist, a none value will be returned.
Examples
use scribe::buffer::{GapBuffer, Range}; let buffer = GapBuffer::new("my data".to_string()); let range = Range::new( scribe::buffer::Position{ line: 0, offset: 3 }, scribe::buffer::Position{ line: 0, offset: 7} ); assert_eq!(buffer.read(&range).unwrap(), "data");
pub fn to_string(&self) -> String
[src]
pub fn to_string(&self) -> String
Returns a string representation of the buffer data (without gap).
Examples
use scribe::buffer::GapBuffer; let mut buffer = GapBuffer::new("my data".to_string()); assert_eq!(buffer.to_string(), "my data");
pub fn delete(&mut self, range: &Range)
[src]
pub fn delete(&mut self, range: &Range)
Removes the specified range of data from the buffer.
Examples
use scribe::buffer::{GapBuffer, Range}; let mut buffer = GapBuffer::new("my data".to_string()); let range = Range::new( scribe::buffer::Position{ line: 0, offset: 0 }, scribe::buffer::Position{ line: 0, offset: 3} ); buffer.delete(&range); assert_eq!(buffer.to_string(), "data");
pub fn in_bounds(&self, position: &Position) -> bool
[src]
pub fn in_bounds(&self, position: &Position) -> bool
Checks whether or not the specified position is in bounds of the buffer data.
Examples
use scribe::buffer::GapBuffer; let buffer = GapBuffer::new("scribe".to_string()); let in_bounds = scribe::buffer::Position{ line: 0, offset: 0 }; let out_of_bounds = scribe::buffer::Position{ line: 1, offset: 3 }; assert_eq!(buffer.in_bounds(&in_bounds), true); assert_eq!(buffer.in_bounds(&out_of_bounds), false);