FIX: Fixes case with unicode characters

This is an ugly bug in ugly code. Pretty much technical deb in here
This commit is contained in:
Nicolás Hatcher
2025-09-28 12:27:03 +02:00
committed by Nicolás Hatcher Andrés
parent fdeae2c771
commit 61cecb7af5

View File

@@ -264,30 +264,29 @@ enum ParseReferenceError {
// There is a similar named function in ironcalc_base. We probably should fix both at the same time. // There is a similar named function in ironcalc_base. We probably should fix both at the same time.
// NB: Maybe use regexes for this? // NB: Maybe use regexes for this?
fn parse_reference(s: &str) -> Result<CellReferenceRC, ParseReferenceError> { fn parse_reference(s: &str) -> Result<CellReferenceRC, ParseReferenceError> {
let bytes = s.as_bytes();
let mut sheet_name = "".to_string(); let mut sheet_name = "".to_string();
let mut column = "".to_string(); let mut column = "".to_string();
let mut row = "".to_string(); let mut row = "".to_string();
let mut state = "sheet"; // "sheet", "col", "row" let mut state = "sheet"; // "sheet", "col", "row"
for &byte in bytes { for ch in s.chars() {
match state { match state {
"sheet" => { "sheet" => {
if byte == b'!' { if ch == '!' {
state = "col" state = "col"
} else { } else {
sheet_name.push(byte as char); sheet_name.push(ch);
} }
} }
"col" => { "col" => {
if byte.is_ascii_alphabetic() { if ch.is_ascii_alphabetic() {
column.push(byte as char); column.push(ch);
} else { } else {
state = "row"; state = "row";
row.push(byte as char); row.push(ch);
} }
} }
_ => { _ => {
row.push(byte as char); row.push(ch);
} }
} }
} }
@@ -1122,3 +1121,16 @@ pub(super) fn load_sheets<R: Read + std::io::Seek>(
} }
Ok((sheets, selected_sheet)) Ok((sheets, selected_sheet))
} }
#[cfg(test)]
mod tests {
use crate::import::worksheets::parse_reference;
#[test]
fn parse_reference_works() {
let cell_reference = parse_reference("📈 Overview!B2");
assert!(cell_reference.is_ok());
let cell_reference = cell_reference.unwrap();
assert_eq!(cell_reference.sheet, "📈 Overview");
}
}