mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-22 13:58:28 -06:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
623c30efa9 |
Generated
+24
@@ -932,6 +932,17 @@ dependencies = [
|
|||||||
"thiserror 2.0.21",
|
"thiserror 2.0.21",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "craft-drawingml"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/storytold/craft-libs?rev=bb57d422d0bc842cbde430955825553ab7b976f4#bb57d422d0bc842cbde430955825553ab7b976f4"
|
||||||
|
dependencies = [
|
||||||
|
"craft-xml",
|
||||||
|
"kurbo",
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "craft-fonts-build"
|
name = "craft-fonts-build"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -1127,6 +1138,18 @@ dependencies = [
|
|||||||
"thiserror 2.0.21",
|
"thiserror 2.0.21",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "craft-xlsx"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/storytold/craft-libs?rev=bb57d422d0bc842cbde430955825553ab7b976f4#bb57d422d0bc842cbde430955825553ab7b976f4"
|
||||||
|
dependencies = [
|
||||||
|
"craft-drawingml",
|
||||||
|
"craft-opc",
|
||||||
|
"craft-sheet",
|
||||||
|
"craft-xml",
|
||||||
|
"thiserror 2.0.21",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "craft-xml"
|
name = "craft-xml"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -2379,6 +2402,7 @@ dependencies = [
|
|||||||
"craft-offcrypto",
|
"craft-offcrypto",
|
||||||
"craft-opc",
|
"craft-opc",
|
||||||
"craft-xls",
|
"craft-xls",
|
||||||
|
"craft-xlsx",
|
||||||
"craft-xml",
|
"craft-xml",
|
||||||
"gridcraft-core",
|
"gridcraft-core",
|
||||||
"gridcraft-formula",
|
"gridcraft-formula",
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ craft-csv = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0
|
|||||||
craft-gridcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "9a6d894200221fcfedc274870c30394d404f859d", version = "0.1.0" }
|
craft-gridcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "9a6d894200221fcfedc274870c30394d404f859d", version = "0.1.0" }
|
||||||
# Excel 97-2003 (.xls, BIFF8) workbooks; `crates/xlsx/src/xls.rs` maps them onto the model.
|
# Excel 97-2003 (.xls, BIFF8) workbooks; `crates/xlsx/src/xls.rs` maps them onto the model.
|
||||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0bc842cbde430955825553ab7b976f4", version = "0.1.0" }
|
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0bc842cbde430955825553ab7b976f4", version = "0.1.0" }
|
||||||
|
craft-xlsx = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0bc842cbde430955825553ab7b976f4", version = "0.1.0" }
|
||||||
craft-xls = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0bc842cbde430955825553ab7b976f4", version = "0.1.0" }
|
craft-xls = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0bc842cbde430955825553ab7b976f4", version = "0.1.0" }
|
||||||
|
|
||||||
# foundation
|
# foundation
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ workspace = true
|
|||||||
test-support = []
|
test-support = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
craft-xlsx.workspace = true
|
||||||
gridcraft-core = { workspace = true }
|
gridcraft-core = { workspace = true }
|
||||||
gridcraft-formula = { workspace = true }
|
gridcraft-formula = { workspace = true }
|
||||||
gridcraft-math = { workspace = true }
|
gridcraft-math = { workspace = true }
|
||||||
|
|||||||
+3
-64
@@ -360,6 +360,7 @@ pub fn parse_streaming(xml: &[u8], split: &[&str], cb: &mut dyn FnMut(El) -> Res
|
|||||||
// ---------------------------------------------------------------- writing helpers
|
// ---------------------------------------------------------------- writing helpers
|
||||||
|
|
||||||
// XML 1.0 byte escaping is shared; spreadsheet string and phonetic policy stays here.
|
// XML 1.0 byte escaping is shared; spreadsheet string and phonetic policy stays here.
|
||||||
|
#[cfg(test)]
|
||||||
use craft_xml::is_xml_char;
|
use craft_xml::is_xml_char;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use craft_xml::push_esc;
|
use craft_xml::push_esc;
|
||||||
@@ -402,70 +403,8 @@ pub fn push_a1(o: &mut String, c: gridcraft_core::CellRef) {
|
|||||||
push_u64(o, u64::from(c.row) + 1);
|
push_u64(o, u64::from(c.row) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ST_Xstring encoding for cell text: characters XML can't carry and carriage returns become
|
/// Shared ST_Xstring encoding/decoding; XML escaping remains a separate operation.
|
||||||
/// `_xHHHH_`, and literal `_xHHHH_` sequences are protected with `_x005F_`. The result still needs
|
pub use craft_xlsx::{decode_xstring, encode_xstring};
|
||||||
/// [`esc`].
|
|
||||||
pub fn encode_xstring(s: &str) -> String {
|
|
||||||
let mut o = String::with_capacity(s.len());
|
|
||||||
let chars: Vec<char> = s.chars().collect();
|
|
||||||
for (i, &c) in chars.iter().enumerate() {
|
|
||||||
if c == '_' && looks_like_escape(&chars, i) {
|
|
||||||
o.push_str("_x005F_");
|
|
||||||
} else if !is_xml_char(c) || (c.is_control() && !matches!(c, '\t' | '\n')) {
|
|
||||||
o.push_str(&format!("_x{:04X}_", c as u32 & 0xFFFF));
|
|
||||||
} else {
|
|
||||||
o.push(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
o
|
|
||||||
}
|
|
||||||
|
|
||||||
fn looks_like_escape(chars: &[char], i: usize) -> bool {
|
|
||||||
chars.get(i + 1) == Some(&'x') && chars.get(i + 6) == Some(&'_') && (i + 2..i + 6).all(|k| chars.get(k).is_some_and(char::is_ascii_hexdigit))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn escape_unit(chars: &[char], i: usize) -> Option<u32> {
|
|
||||||
let hex: String = chars.get(i + 2..i + 6)?.iter().collect();
|
|
||||||
u32::from_str_radix(&hex, 16).ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The character for a high surrogate escape at `i` (value `high`) followed directly by a low surrogate escape.
|
|
||||||
fn surrogate_pair(chars: &[char], i: usize, high: u32) -> Option<char> {
|
|
||||||
if !(0xD800..=0xDBFF).contains(&high) || chars.get(i + 7) != Some(&'_') || !looks_like_escape(chars, i + 7) {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let low = escape_unit(chars, i + 7).filter(|l| (0xDC00..=0xDFFF).contains(l))?;
|
|
||||||
char::from_u32(0x10000 + ((high - 0xD800) << 10) + (low - 0xDC00))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Inverse of [`encode_xstring`].
|
|
||||||
pub fn decode_xstring(s: &str) -> String {
|
|
||||||
if !s.contains("_x") {
|
|
||||||
return s.to_string();
|
|
||||||
}
|
|
||||||
let chars: Vec<char> = s.chars().collect();
|
|
||||||
let mut o = String::with_capacity(s.len());
|
|
||||||
let mut i = 0;
|
|
||||||
while i < chars.len() {
|
|
||||||
if chars[i] == '_' && looks_like_escape(&chars, i) {
|
|
||||||
let unit = escape_unit(&chars, i);
|
|
||||||
if let Some(ch) = unit.and_then(char::from_u32) {
|
|
||||||
o.push(ch);
|
|
||||||
i += 7;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// A high surrogate escape followed by a low surrogate escape is one UTF-16 pair.
|
|
||||||
if let Some(ch) = unit.and_then(|high| surrogate_pair(&chars, i, high)) {
|
|
||||||
o.push(ch);
|
|
||||||
i += 14;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
o.push(chars[i]);
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
o
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `<t>` element with `xml:space="preserve"` when needed.
|
/// `<t>` element with `xml:space="preserve"` when needed.
|
||||||
pub fn t_el(s: &str) -> String {
|
pub fn t_el(s: &str) -> String {
|
||||||
|
|||||||
Reference in New Issue
Block a user