Skip to content

Commit

Permalink
Merge pull request #254 from agentjill/master
Browse files Browse the repository at this point in the history
small changes
  • Loading branch information
MathNya authored Jan 20, 2025
2 parents b58e16e + 25b5672 commit 159764a
Show file tree
Hide file tree
Showing 43 changed files with 151 additions and 258 deletions.
1 change: 1 addition & 0 deletions src/helper/coordinate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ where

alpha
.as_ref()
.to_uppercase()
.chars()
.rev()
.enumerate()
Expand Down
36 changes: 18 additions & 18 deletions src/helper/formula.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
let mut next_token: Option<FormulaToken> = None;

let mut index = 1;
let mut value = String::from("");
let mut value = String::new();

while index < formula_length {
// double-quoted strings
Expand All @@ -158,7 +158,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_token_type(FormulaTokenTypes::Operand);
obj.set_token_sub_type(FormulaTokenSubTypes::Text);
tokens1.push(obj);
value = String::from("");
value = String::new();
}
} else {
value = format!("{}{}", value, formula.chars().nth(index).unwrap());
Expand Down Expand Up @@ -214,7 +214,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_token_type(FormulaTokenTypes::Operand);
obj.set_token_sub_type(FormulaTokenSubTypes::Error);
tokens1.push(obj);
value = String::from("");
value = String::new();
}

continue;
Expand Down Expand Up @@ -245,7 +245,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Unknown);
tokens1.push(obj);
value = String::from("");
value = String::new();
}
in_string = true;
index += 1;
Expand All @@ -260,7 +260,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Unknown);
tokens1.push(obj);
value = String::from("");
value = String::new();
}
in_string = true;
index += 1;
Expand All @@ -283,7 +283,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Unknown);
tokens1.push(obj);
value = String::from("");
value = String::new();
}
in_error = true;
value = format!("{}{}", value, self::ERROR_START);
Expand All @@ -300,7 +300,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Unknown);
tokens1.push(obj);
value = String::from("");
value = String::new();
}

let mut obj = FormulaToken::default();
Expand Down Expand Up @@ -328,7 +328,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Operand);
tokens1.push(obj);
value = String::from("");
value = String::new();
}

let mut obj = stack.pop().unwrap();
Expand Down Expand Up @@ -359,7 +359,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Operand);
tokens1.push(obj);
value = String::from("");
value = String::new();
}

let mut obj = stack.pop().unwrap().clone();
Expand All @@ -384,7 +384,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Operand);
tokens1.push(obj);
value = String::from("");
value = String::new();
}
let mut obj = FormulaToken::default();
obj.set_value("");
Expand All @@ -411,7 +411,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Operand);
tokens1.push(obj);
value = String::from("");
value = String::new();
}
let mut obj = FormulaToken::default();
obj.set_value(formula.chars().skip(index).take(2).collect::<String>());
Expand All @@ -431,7 +431,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Operand);
tokens1.push(obj);
value = String::from("");
value = String::new();
}
let mut obj = FormulaToken::default();
obj.set_value(formula.chars().nth(index).unwrap());
Expand All @@ -449,7 +449,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Operand);
tokens1.push(obj);
value = String::from("");
value = String::new();
}
let mut obj = FormulaToken::default();
obj.set_value(formula.chars().nth(index).unwrap());
Expand All @@ -469,7 +469,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_token_sub_type(FormulaTokenSubTypes::Start);
tokens1.push(obj.clone());
stack.push(obj);
value = String::from("");
value = String::new();
} else {
let mut obj = FormulaToken::default();
obj.set_value("");
Expand All @@ -490,7 +490,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Operand);
tokens1.push(obj);
value = String::from("");
value = String::new();
}

let mut obj = stack.pop().unwrap();
Expand Down Expand Up @@ -522,7 +522,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_value(value);
obj.set_token_type(FormulaTokenTypes::Operand);
tokens1.push(obj);
value = String::from("");
value = String::new();
}

let mut obj = stack.pop().unwrap();
Expand Down Expand Up @@ -618,7 +618,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
obj.set_token_type(FormulaTokenTypes::OperatorInfix);
obj.set_token_sub_type(FormulaTokenSubTypes::Intersection);
tokens2.push(obj);
value = String::from("");
value = String::new();
}

// move tokens to final list, switching infix "-" operators to prefix when appropriate, switching infix "+" operators
Expand Down Expand Up @@ -742,7 +742,7 @@ pub(crate) fn parse_to_tokens<S: Into<String>>(formula: S) -> Vec<FormulaToken>
}

pub(crate) fn render(formula_token_list: &[FormulaToken]) -> String {
let mut result = String::from("");
let mut result = String::new();
for token in formula_token_list {
if token.get_token_type() == &FormulaTokenTypes::Function
&& token.get_token_sub_type() == &FormulaTokenSubTypes::Start
Expand Down
17 changes: 3 additions & 14 deletions src/helper/number_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,9 @@ fn split_format(sections: Vec<&str>, value: &f64) -> (String, String, String) {
let color_re = Regex::new(&color_regex).unwrap();
let cond_re = Regex::new(cond_regex).unwrap();

let mut colors = [
String::from(""),
String::from(""),
String::from(""),
String::from(""),
String::from(""),
];
let mut condops = [
String::from(""),
String::from(""),
String::from(""),
String::from(""),
String::from(""),
];
let mut colors = [const { String::new() }; 5];
let mut condops = [const { String::new() }; 5];

let mut condvals = [
String::from("0"),
String::from("0"),
Expand Down
2 changes: 1 addition & 1 deletion src/helper/number_format/fraction_formater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) fn format_as_fraction(value: &f64, format: &str) -> String {
if check_format == "? ?" {
let mut integer_part_str = integer_part.to_string();
if integer_part == 0f64 {
integer_part_str = String::from("");
integer_part_str = String::new();
}
result = format!(
"{}{} {}/{}",
Expand Down
3 changes: 2 additions & 1 deletion src/helper/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pub fn get_coordinate_list(range_str: &str) -> Vec<BasicCellIndex> {
}

pub fn get_start_and_end_point(range_str: &str) -> (u32, u32, u32, u32) {
let coordinate_collection: Vec<&str> = range_str.split(':').collect();
let upper_rng_str = range_str.to_uppercase();
let coordinate_collection: Vec<&str> = upper_rng_str.split(':').collect();

assert!(
matches!(coordinate_collection.len(), 1 | 2),
Expand Down
2 changes: 1 addition & 1 deletion src/helper/string_helper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[inline]
pub(crate) fn _get_currency_code() -> String {
String::from("")
String::new()
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/reader/xlsx/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ pub(crate) fn read(
reader.config_mut().trim_text(false);

let mut authors: Vec<String> = Vec::new();
let mut value: String = String::from("");
let mut value: String = String::new();
xml_read_loop!(
reader,
Event::Empty(ref e) => {
if e.name().into_inner() == b"author" {
authors.push(String::from(""));
authors.push(String::new());
}
},
Event::Start(ref e) => {
Expand Down
4 changes: 2 additions & 2 deletions src/reader/xlsx/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) fn read(
let mut buf = Vec::new();
let mut table = Table::default();
let mut table_column = TableColumn::default();
let mut string_value = String::from("");
let mut string_value = String::new();
loop {
match reader.read_event_into(&mut buf) {
Ok(Event::Empty(ref e)) => match e.name().into_inner() {
Expand Down Expand Up @@ -155,7 +155,7 @@ pub(crate) fn read(
Ok(Event::End(ref e)) => match e.name().into_inner() {
b"calculatedColumnFormula" => {
table_column.set_calculated_column_formula(string_value);
string_value = String::from("");
string_value = String::new();
}
b"tableColumn" => {
// add column to table (if it has a name)
Expand Down
2 changes: 1 addition & 1 deletion src/reader/xlsx/workbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) fn read<R: io::Read + io::Seek>(
b"pivotCache" => {
let cache_id = get_attribute(e, b"cacheId").unwrap();
let r_id = get_attribute(e, b"r:id").unwrap();
spreadsheet.add_pivot_caches((r_id, cache_id, String::from("")));
spreadsheet.add_pivot_caches((r_id, cache_id, String::new()));
}
_ => (),
}
Expand Down
2 changes: 1 addition & 1 deletion src/reader/xlsx/worksheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fn get_hyperlink(
raw_relationships: Option<&RawRelationships>,
) -> (String, Hyperlink) {
let mut hyperlink = Hyperlink::default();
let mut rid = String::from("");
let mut rid = String::new();

let coordition = get_attribute(e, b"ref").unwrap_or_default();
if let Some(v) = get_attribute(e, b"location") {
Expand Down
6 changes: 3 additions & 3 deletions src/structs/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ impl Cell {
empty_flag: bool,
formula_shared_list: &mut HashMap<u32, (String, Vec<FormulaToken>)>,
) {
let mut type_value: String = String::from("");
let mut cell_reference: String = String::from("");
let mut type_value: String = String::new();
let mut cell_reference: String = String::new();

if let Some(v) = get_attribute(e, b"r") {
cell_reference = v;
Expand All @@ -374,7 +374,7 @@ impl Cell {
return;
}

let mut string_value: String = String::from("");
let mut string_value: String = String::new();
let mut buf = Vec::new();
loop {
match reader.read_event_into(&mut buf) {
Expand Down
2 changes: 1 addition & 1 deletion src/structs/cell_formula.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl CellFormula {
attributes.push(("r2", self.r2.get_value_str()));
}

let mut reference_str = String::from("");
let mut reference_str = String::new();
match formula_shared_list.get(self.shared_index.get_value()) {
Some((start_col, end_col)) => {
if coordinate == start_col {
Expand Down
22 changes: 7 additions & 15 deletions src/structs/cells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,11 @@ impl Cells {
}

pub fn get_highest_column_and_row(&self) -> (u32, u32) {
let mut col_max: u32 = 0;
let mut row_max: u32 = 0;
for key in self.map.keys() {
if key.1 > col_max {
col_max = key.1;
}
if key.0 > row_max {
row_max = key.0;
}
}
(col_max, row_max)
self.map
.keys()
.fold((0, 0), |(row_max, col_max), &(row, col)| {
(row.max(row_max), col.max(col_max))
})
}

/// Has Hyperlink
Expand Down Expand Up @@ -205,8 +199,7 @@ impl Cells {

pub fn get_cell_by_range(&self, range: &str) -> Vec<Option<&Cell>> {
let mut result: Vec<Option<&Cell>> = Vec::new();
let range_upper = range.to_uppercase();
let coordinate_list = get_coordinate_list(&range_upper);
let coordinate_list = get_coordinate_list(&range);
for (col_num, row_num) in coordinate_list {
result.push(self.get((&col_num, &row_num)));
}
Expand All @@ -215,8 +208,7 @@ impl Cells {

pub fn get_cell_value_by_range(&self, range: &str) -> Vec<&CellValue> {
let mut result: Vec<&CellValue> = Vec::new();
let range_upper = range.to_uppercase();
let coordinate_list = get_coordinate_list(&range_upper);
let coordinate_list = get_coordinate_list(&range);
for (col_num, row_num) in coordinate_list {
result.push(self.get_cell_value((&col_num, &row_num)));
}
Expand Down
31 changes: 12 additions & 19 deletions src/structs/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,28 +277,21 @@ impl Chart {
}

pub fn get_chart_space(&self) -> &ChartSpace {
match self.two_cell_anchor.get_graphic_frame() {
Some(v) => {
return v.get_graphic().get_graphic_data().get_chart_space();
}
None => {
panic!("Non-ChartSpace.");
}
}
self.two_cell_anchor
.get_graphic_frame()
.expect("Non-ChartSpace.")
.get_graphic()
.get_graphic_data()
.get_chart_space()
}

pub fn get_chart_space_mut(&mut self) -> &mut ChartSpace {
match self.two_cell_anchor.get_graphic_frame_mut() {
Some(v) => {
return v
.get_graphic_mut()
.get_graphic_data_mut()
.get_chart_space_mut();
}
None => {
panic!("Non-ChartSpace.");
}
}
self.two_cell_anchor
.get_graphic_frame_mut()
.expect("Non-ChartSpace.")
.get_graphic_mut()
.get_graphic_data_mut()
.get_chart_space_mut()
}

pub fn new_chart(
Expand Down
2 changes: 1 addition & 1 deletion src/structs/custom_properties/custom_document_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl CustomDocumentProperty {
return;
}

let mut value: String = String::from("");
let mut value: String = String::new();
xml_read_loop!(
reader,
Event::Text(e) => {
Expand Down
Loading

0 comments on commit 159764a

Please sign in to comment.