From 4f74ad9470789819f480b76c4ae7fdaa126ac280 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 10 Mar 2021 04:19:25 +0800 Subject: [PATCH] add string appending feature --- xous-rs/src/string.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xous-rs/src/string.rs b/xous-rs/src/string.rs index b9dd10667..10dec993e 100644 --- a/xous-rs/src/string.rs +++ b/xous-rs/src/string.rs @@ -158,6 +158,18 @@ impl String { } } + pub fn append(&mut self, s: &str) -> core::result::Result { + let mut bytes_added = 0; + for ch in s.chars() { + if let Ok(bytes) = self.push(ch) { + bytes_added += bytes; + } else { + return Err(Error::OutOfMemory) + } + } + Ok(bytes_added) + } + pub fn push_byte(&mut self, b: u8) -> core::result::Result<(), Error> { if self.len() < self.bytes.len() { self.bytes[self.len()] = b;