Skip to content

Commit

Permalink
less cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
sftse committed Aug 16, 2024
1 parent 6a5f287 commit 6e5ad60
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
12 changes: 6 additions & 6 deletions src/ods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ fn parse_content<RS: Read + Seek>(mut zip: ZipArchive<RS>) -> Result<Content, Od
.map(|x| x.to_string())
}
Ok(Event::Start(ref e))
if style_name.clone().is_some() && e.name() == QName(b"style:table-properties") =>
if style_name.is_some() && e.name() == QName(b"style:table-properties") =>
{
let visible = match e.try_get_attribute(b"table:display")? {
Some(a) => match a
Expand Down Expand Up @@ -699,20 +699,20 @@ fn read_pictures<RS: Read + Seek>(
let mut pics = Vec::new();
for i in 0..zip.len() {
let mut zfile = zip.by_index(i)?;
let zname = zfile.name().to_owned();
let zname = zfile.name();
// no Thumbnails
if zname.starts_with("Pictures") {
let name_ext: Vec<&str> = zname.split(".").collect();
if let Some(ext) = name_ext.last() {
if let Some(ext) = zname.split('.').last() {
if [
"emf", "wmf", "pict", "jpeg", "jpg", "png", "dib", "gif", "tiff", "eps", "bmp",
"wpg",
]
.contains(ext)
.contains(&ext)
{
let ext = ext.to_string();
let mut buf: Vec<u8> = Vec::new();
zfile.read_to_end(&mut buf)?;
pics.push((ext.to_string(), buf));
pics.push((ext, buf));
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/xls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,8 @@ fn parse_sheet_metadata(
}
};
r.data = &r.data[6..];
let name = parse_short_string(r, encoding, biff)?;
let sheet_name = name
.as_bytes()
.iter()
.cloned()
.filter(|b| *b != 0)
.collect::<Vec<_>>();
let name = String::from_utf8(sheet_name).unwrap();
let mut name = parse_short_string(r, encoding, biff)?;
name.retain(|c| c != '\0');
Ok((pos, Sheet { name, visible, typ }))
}

Expand Down
10 changes: 5 additions & 5 deletions src/xlsb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,19 @@ impl<RS: Read + Seek> Xlsb<RS> {
let mut pics = Vec::new();
for i in 0..self.zip.len() {
let mut zfile = self.zip.by_index(i)?;
let zname = zfile.name().to_owned();
let zname = zfile.name();
if zname.starts_with("xl/media") {
let name_ext: Vec<&str> = zname.split('.').collect();
if let Some(ext) = name_ext.last() {
if let Some(ext) = zname.split('.').last() {
if [
"emf", "wmf", "pict", "jpeg", "jpg", "png", "dib", "gif", "tiff", "eps",
"bmp", "wpg",
]
.contains(ext)
.contains(&ext)
{
let ext = ext.to_string();
let mut buf: Vec<u8> = Vec::new();
zfile.read_to_end(&mut buf)?;
pics.push((ext.to_string(), buf));
pics.push((ext, buf));
}
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/xlsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,8 @@ impl<RS: Read + Seek> Xlsx<RS> {
// this is an incomplete implementation, but should be good enough for excel
let new_index =
base_folder.rfind('/').expect("Must be a parent folder");
let full_path = format!(
"{}{}",
base_folder[..new_index].to_owned(),
target[2..].to_owned()
);
let full_path =
format!("{}{}", &base_folder[..new_index], &target[2..]);
table_locations.push(full_path);
} else if target.is_empty() { // do nothing
} else {
Expand Down Expand Up @@ -622,19 +619,19 @@ impl<RS: Read + Seek> Xlsx<RS> {
let mut pics = Vec::new();
for i in 0..self.zip.len() {
let mut zfile = self.zip.by_index(i)?;
let zname = zfile.name().to_owned();
let zname = zfile.name();
if zname.starts_with("xl/media") {
let name_ext: Vec<&str> = zname.split('.').collect();
if let Some(ext) = name_ext.last() {
if let Some(ext) = zname.split('.').last() {
if [
"emf", "wmf", "pict", "jpeg", "jpg", "png", "dib", "gif", "tiff", "eps",
"bmp", "wpg",
]
.contains(ext)
.contains(&ext)
{
let ext = ext.to_string();
let mut buf: Vec<u8> = Vec::new();
zfile.read_to_end(&mut buf)?;
pics.push((ext.to_string(), buf));
pics.push((ext, buf));
}
}
}
Expand Down

0 comments on commit 6e5ad60

Please sign in to comment.