Commit fdf56235 authored by Arthur Carlsson's avatar Arthur Carlsson

read_ascii_string now returns &str

parent 377286b4
Pipeline #25872905 passed with stage
in 2 minutes and 3 seconds
......@@ -17,7 +17,7 @@ impl mem::ReadOnly for Cart {
type ByteOrder = BigEndian;
}
impl mem::Mem<Cart> {
pub fn title(&self) -> String {
pub fn title(&self) -> &str {
self.read_ascii_string(0x0020, 20)
}
}
use std::str;
use byteorder;
use byteorder::ByteOrder;
use std::marker::PhantomData;
......@@ -17,6 +18,8 @@ pub trait Read {
fn readb(&self, addr: u32) -> u8;
/// Reads a word from the memory at the given address.
///
/// TODO: What happens if there is no room for the word? I.e. the address is just at the end of the memory?
fn readw(&self, addr: u32) -> u32;
}
......@@ -60,10 +63,9 @@ impl<T> Mem<T> {
}
}
pub fn read_ascii_string(&self, addr: u32, count: usize) -> String {
String::from_utf8_lossy(&self.buf[addr as usize..addr as usize + count])
pub fn read_ascii_string(&self, addr: u32, count: usize) -> &str {
str::from_utf8(&self.buf[addr as usize..addr as usize + count]).unwrap()
.trim_right_matches('\0')
.to_string()
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment