mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
add string appending feature
This commit is contained in:
parent
e829c0bd06
commit
4f74ad9470
1 changed files with 12 additions and 0 deletions
|
|
@ -158,6 +158,18 @@ impl<const N: usize> String<N> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn append(&mut self, s: &str) -> core::result::Result<usize, Error> {
|
||||||
|
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> {
|
pub fn push_byte(&mut self, b: u8) -> core::result::Result<(), Error> {
|
||||||
if self.len() < self.bytes.len() {
|
if self.len() < self.bytes.len() {
|
||||||
self.bytes[self.len()] = b;
|
self.bytes[self.len()] = b;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue