pub const MIN_ROW: u32 = 0;
pub const MIN_COLUMN: u32 = 0;
pub const MAX_COLUMN: u32 = 16384;
pub const MAX_ROW: u32 = 1048576;
pub const MIN_ROW_1: u32 = 1;
pub const PACKAGE_PROPS: &str = "docProps";
pub const PACKAGE_XL: &str = "xl";
pub const PACKAGE_RELS: &str = "_rels";
pub const PACKAGE_THEME: &str = "xl/theme";
pub const PACKAGE_WORKSHEETS: &str = "xl/worksheets";
pub const PACKAGE_DRAWINGS: &str = "xl/drawings";
pub const PACKAGE_CHARTS: &str = "xl/charts";
pub const PACKAGE_IMAGES: &str = "xl/media";
pub const PACKAGE_WORKSHEET_RELS: &str = "xl/worksheets/_rels";
pub const ARC_CONTENT_TYPES: &str = "[Content_Types].xml";
pub const ARC_ROOT_RELS: &str = "_rels/.rels";
pub const ARC_WORKBOOK_RELS: &str = "xl/_rels/workbook.xml.rels";
pub const ARC_CORE: &str = "docProps/core.xml";
pub const ARC_APP: &str = "docProps/app.xml";
pub const ARC_WORKBOOK: &str = "xl/workbook.xml";
pub const ARC_STYLE: &str = "xl/styles.xml";
pub const ARC_THEME: &str = "xl/theme/theme1.xml";
pub const ARC_SHARED_STRINGS: &str = "xl/sharedStrings.xml";
pub const ARC_CUSTOM_UI: &str = "customUI/customUI.xml";
pub const ARC_VBA: [&str; 10] = [
"xl/vba",
"xl/activeX",
"xl/drawings",
"xl/media",
"xl/ctrlProps",
"xl/worksheets/_rels",
"customUI",
"xl/printerSettings",
"xl/charts",
"xl/theme",
];
pub const CHART_NS: &str = "http://schemas.openxmlformats.org/drawingml/2006/chart";
pub const DRAWING_NS: &str = "http://schemas.openxmlformats.org/drawingml/2006/main";
pub const COMMENTS_NS: &str =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
pub const VML_NS: &str =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing";
pub const SHEET_DRAWING_NS: &str =
"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing";
pub const CHART_DRAWING_NS: &str = "http://schemas.openxmlformats.org/drawingml/2006/chartDrawing";
pub const REL_NS: &str = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
pub const PKG_REL_NS: &str = "http://schemas.openxmlformats.org/package/2006/relationships";
pub const VTYPES_NS: &str = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes";
pub const XPROPS_NS: &str =
"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
pub const COREPROPS_NS: &str =
"http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
pub const CONTYPES_NS: &str = "http://schemas.openxmlformats.org/package/2006/content-types";
pub const DCORE_NS: &str = "http://purl.org/dc/elements/1.1/";
pub const DCTERMS_NS: &str = "http://purl.org/dc/terms/";
pub const DCTERMS_PREFIX: &str = "dcterms";
pub const XSI_NS: &str = "http://www.w3.org/2001/XMLSchema-instance";
pub const XML_NS: &str = "http://www.w3.org/XML/1998/namespace";
pub const SHEET_MAIN_NS: &str = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
pub const CUSTOMUI_NS: &str =
"http://schemas.microsoft.com/office/2006/relationships/ui/extensibility";
pub const NAMESPACES: [(&str, &str); 9] = [
("cp", COREPROPS_NS),
("dc", DCORE_NS),
(DCTERMS_PREFIX, DCTERMS_NS),
("dcmitype", "http://purl.org/dc/dcmitype/"),
("xsi", XSI_NS),
("vt", VTYPES_NS),
("xml", XML_NS),
("main", SHEET_MAIN_NS),
("c", CHART_NS),
];
pub const SHEET_MAIN_PREFIX: &str = "s";
pub const REL_PREFIX: &str = "r";
pub fn qname(ns: &str, tag: &str) -> String {
format!("{{{ns}}}{tag}")
}
pub fn local_name(tag: &str) -> &str {
match tag.rfind('}') {
Some(idx) => &tag[idx + 1..],
None => tag,
}
}
pub fn namespace_of(tag: &str) -> Option<&str> {
tag.strip_prefix('{')
.and_then(|rest| rest.split_once('}').map(|(ns, _)| ns))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn qname_round_trip() {
let q = qname(SHEET_MAIN_NS, "sheetData");
assert_eq!(namespace_of(&q), Some(SHEET_MAIN_NS));
assert_eq!(local_name(&q), "sheetData");
assert_eq!(namespace_of("plain"), None);
assert_eq!(local_name("plain"), "plain");
}
#[test]
fn namespace_constants_are_distinct() {
assert_ne!(SHEET_MAIN_NS, DRAWING_NS);
assert_ne!(CHART_NS, CHART_DRAWING_NS);
assert!(ARC_VBA.contains(&"xl/vba"));
}
}