-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pt
committed
Apr 17, 2024
1 parent
fbf8574
commit e65a456
Showing
5 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod cell_ref; | ||
pub(crate) mod cell; | ||
|
||
extern crate proc_macro; | ||
use std::hash::Hash; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub(crate) mod cell_address; | ||
pub(crate) mod cell_address_range; | ||
pub(crate) mod cell_reference; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::utils::col_helper; | ||
|
||
#[derive(Default, Debug, Copy, Clone)] | ||
pub(crate) struct CellAddress { | ||
row: u32, | ||
col: u32, | ||
} | ||
|
||
impl CellAddress { | ||
fn new(row: u32, col: u32) -> CellAddress { | ||
CellAddress { | ||
row, | ||
col, | ||
} | ||
} | ||
fn from_str(refer: &str) -> CellAddress { | ||
let mut coord = CellAddress::default(); | ||
let mut row = String::new(); | ||
let mut col = String::new(); | ||
for c in refer.chars() { | ||
match c { | ||
'A'..='Z' | 'a'..='z' => { | ||
col.push(c); | ||
}, | ||
'0'..='9' => { | ||
row.push(c); | ||
}, | ||
_ => {}, | ||
} | ||
} | ||
coord.row = row.parse().unwrap_or_default(); | ||
coord.col = col_helper::to_col(&col); | ||
coord | ||
} | ||
fn to_string(&self) -> String { | ||
let mut refer = String::new(); | ||
refer.push_str(&col_helper::to_col_name(self.col)); | ||
refer.push_str(&self.row.to_string()); | ||
refer | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::utils::col_helper; | ||
|
||
#[derive(Default, Debug, Copy, Clone)] | ||
struct CellAddressRange { | ||
first_row: u32, | ||
first_col: u32, | ||
last_row: u32, | ||
last_col: u32, | ||
} | ||
|
||
impl CellAddressRange { | ||
fn new(first_row: u32, first_col: u32, last_row: u32, last_col: u32) -> CellAddressRange { | ||
CellAddressRange { | ||
first_row, | ||
first_col, | ||
last_row, | ||
last_col, | ||
} | ||
} | ||
|
||
fn from_str(refer: &str) -> CellAddressRange { | ||
let mut cell_address_range = CellAddressRange::default(); | ||
let cell_addresses: Vec<&str> = refer.split(":").collect(); | ||
match cell_addresses.len() { | ||
1 => { | ||
(cell_address_range.first_row, cell_address_range.first_col) = | ||
col_helper::to_loc(cell_addresses[0]); | ||
(cell_address_range.last_row, cell_address_range.last_col) = | ||
(cell_address_range.first_row, cell_address_range.first_col) | ||
}, | ||
2 => { | ||
(cell_address_range.first_row, cell_address_range.first_col) = | ||
col_helper::to_loc(cell_addresses[0]); | ||
(cell_address_range.last_row, cell_address_range.last_col) = | ||
col_helper::to_loc(cell_addresses[1]); | ||
}, | ||
_ => {} | ||
} | ||
cell_address_range | ||
} | ||
|
||
fn to_string(&self) -> String { | ||
todo!() | ||
// return the string like A1:B2 format | ||
} | ||
|
||
fn to_cell_address_string(&self) -> String { | ||
todo!() | ||
// just return the start address string like A1 format | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters