diff options
author | Jovansonlee Cesar <ivanceras@gmail.com> | 2021-06-29 13:29:03 +0800 |
---|---|---|
committer | Jovansonlee Cesar <ivanceras@gmail.com> | 2021-06-29 13:29:03 +0800 |
commit | d58b79164ac5404639821209151bca8c0c708af4 (patch) | |
tree | aa7f757ecd29e201749f19261abb1a9aee262a2f | |
parent | 3a2fdd784044130909ad992bede02b971e4b8721 (diff) |
Add default implementation for StringBuffer
-rw-r--r-- | svgbob/Cargo.toml | 2 | ||||
-rw-r--r-- | svgbob/src/buffer/string_buffer.rs | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/svgbob/Cargo.toml b/svgbob/Cargo.toml index 694a99d..7b1c0fa 100644 --- a/svgbob/Cargo.toml +++ b/svgbob/Cargo.toml @@ -13,7 +13,7 @@ license = "Apache-2.0" nalgebra = "0.18.0" ncollide2d = "0.19.1" lazy_static = "1.3.0" -sauron = { version = "0.33" } +sauron = { version = "0.34" } unicode-width = "0.1.5" itertools = "0.8.0" pom = { version = "3.1.0" } diff --git a/svgbob/src/buffer/string_buffer.rs b/svgbob/src/buffer/string_buffer.rs index 159e683..9350a90 100644 --- a/svgbob/src/buffer/string_buffer.rs +++ b/svgbob/src/buffer/string_buffer.rs @@ -22,6 +22,12 @@ impl DerefMut for StringBuffer { } } +impl Default for StringBuffer { + fn default() -> Self { + Self(vec![]) + } +} + impl StringBuffer { pub fn new() -> Self { StringBuffer(vec![]) @@ -41,6 +47,8 @@ impl StringBuffer { } } + /// put a character in this x and y location, replacing the old character + /// if there is already /// x and y can also be negative pub fn add_char(&mut self, x: i32, y: i32, ch: char) { if x >= 0 && y >= 0 { @@ -63,6 +71,7 @@ impl StringBuffer { } } + /// replace insert a string on this location pub fn add_str(&mut self, x: i32, y: i32, s: &str) { for (i, ch) in s.chars().enumerate() { self.add_char(x + i as i32, y, ch); |