Bugfix/nicolas more fixes (#36)

* FIX: Remove the serde_json depndendency

* UPDATE: Use binary representation also for languages and locales
This commit is contained in:
Nicolás Hatcher Andrés
2024-04-15 19:25:38 +02:00
committed by GitHub
parent 49ef846ebd
commit f9cf86a17c
8 changed files with 23 additions and 61 deletions

12
Cargo.lock generated
View File

@@ -370,7 +370,6 @@ dependencies = [
"ryu", "ryu",
"serde", "serde",
"serde_json", "serde_json",
"serde_repr",
] ]
[[package]] [[package]]
@@ -679,17 +678,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_repr"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "sha1" name = "sha1"
version = "0.10.6" version = "0.10.6"

View File

@@ -12,8 +12,6 @@ readme = "README.md"
[dependencies] [dependencies]
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
ryu = "1.0" ryu = "1.0"
chrono = "0.4" chrono = "0.4"
chrono-tz = "0.9" chrono-tz = "0.9"
@@ -21,6 +19,9 @@ regex = "1.0"
once_cell = "1.16.0" once_cell = "1.16.0"
bitcode = "0.6.0" bitcode = "0.6.0"
[dev-dependencies]
serde_json = "1.0"
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = { version = "0.3.69" } js-sys = { version = "0.3.69" }

View File

@@ -1,12 +1,9 @@
use crate::{ use crate::{
expressions::token::Error, language::Language, number_format::to_excel_precision_str, types::*, expressions::token::Error, language::Language, number_format::to_excel_precision_str, types::*,
}; };
use serde::{Deserialize, Serialize};
use serde_json::json;
/// A CellValue is the representation of the cell content. /// A CellValue is the representation of the cell content.
#[derive(Serialize, Deserialize, Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[serde(untagged)]
pub enum CellValue { pub enum CellValue {
None, None,
String(String), String(String),
@@ -14,17 +11,6 @@ pub enum CellValue {
Boolean(bool), Boolean(bool),
} }
impl CellValue {
pub fn to_json_str(&self) -> String {
match &self {
CellValue::None => "null".to_string(),
CellValue::String(s) => json!(s).to_string(),
CellValue::Number(f) => json!(f).to_string(),
CellValue::Boolean(b) => json!(b).to_string(),
}
}
}
impl From<f64> for CellValue { impl From<f64> for CellValue {
fn from(value: f64) -> Self { fn from(value: f64) -> Self {
Self::Number(value) Self::Number(value)

View File

@@ -2,7 +2,6 @@ use std::fmt;
use bitcode::{Decode, Encode}; use bitcode::{Decode, Encode};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::language::Language; use crate::language::Language;
@@ -81,8 +80,7 @@ impl fmt::Display for OpProduct {
/// * "#ERROR!" means there was an error processing the formula (for instance "=A1+") /// * "#ERROR!" means there was an error processing the formula (for instance "=A1+")
/// * "#N/IMPL!" means the formula or feature in Excel but has not been implemented in IronCalc /// * "#N/IMPL!" means the formula or feature in Excel but has not been implemented in IronCalc
/// Note that they are serialized/deserialized by index /// Note that they are serialized/deserialized by index
#[derive(Serialize_repr, Deserialize_repr, Encode, Decode, Debug, PartialEq, Eq, Clone)] #[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[repr(u8)]
pub enum Error { pub enum Error {
REF, REF,
NAME, NAME,

View File

@@ -0,0 +1 @@
PfrendeesD<>VRAITRUEWAHRVERDADEROTVFAUXFALSEFALSCHFALSOUw#REF!#REF!#BEZUG!#¡REF!e<>#NOM?#NAME?#NAME?#¿NOMBRE?x<>#VALEUR!#VALUE!#WERT!#¡VALOR!w<>#DIV/0!#DIV/0!#DIV/0!#¡DIV/0!<04>#N/A#N/A#NV#N/AXv#NOMBRE!#NUM!#ZAHL!#¡NUM!<02><>#N/IMPL!#N/IMPL!#N/IMPL!#N/IMPL!w{#SPILL!#SPILL!#ÜBERLAUF!#SPILL!ff#CALC!#CALC!#CALC!#CALC!ff#CIRC!#CIRC!#CIRC!#CIRC!ww#ERROR!#ERROR!#ERROR!#ERROR!ff#NULL!#NULL!#NULL!#NULL!

View File

@@ -1,15 +1,15 @@
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
#[derive(Serialize, Deserialize, Clone)] use bitcode::{Decode, Encode};
use once_cell::sync::Lazy;
#[derive(Encode, Decode, Clone)]
pub struct Booleans { pub struct Booleans {
pub r#true: String, pub r#true: String,
pub r#false: String, pub r#false: String,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Encode, Decode, Clone)]
pub struct Errors { pub struct Errors {
pub r#ref: String, pub r#ref: String,
pub name: String, pub name: String,
@@ -25,14 +25,14 @@ pub struct Errors {
pub null: String, pub null: String,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Encode, Decode, Clone)]
pub struct Language { pub struct Language {
pub booleans: Booleans, pub booleans: Booleans,
pub errors: Errors, pub errors: Errors,
} }
static LANGUAGES: Lazy<HashMap<String, Language>> = Lazy::new(|| { static LANGUAGES: Lazy<HashMap<String, Language>> = Lazy::new(|| {
serde_json::from_str(include_str!("language.json")).expect("Failed parsing language file") bitcode::decode(include_bytes!("language.bin")).expect("Failed parsing language file")
}); });
pub fn get_language(id: &str) -> Result<&Language, String> { pub fn get_language(id: &str) -> Result<&Language, String> {

BIN
base/src/locale/locales.bin Normal file

Binary file not shown.

View File

@@ -1,32 +1,29 @@
use bitcode::{Decode, Encode};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
#[derive(Serialize, Deserialize, Clone)] #[derive(Encode, Decode, Clone)]
pub struct Locale { pub struct Locale {
pub dates: Dates, pub dates: Dates,
pub numbers: NumbersProperties, pub numbers: NumbersProperties,
pub currency: Currency, pub currency: Currency,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Encode, Decode, Clone)]
pub struct Currency { pub struct Currency {
pub iso: String, pub iso: String,
pub symbol: String, pub symbol: String,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Encode, Decode, Clone)]
pub struct NumbersProperties { pub struct NumbersProperties {
#[serde(rename = "symbols-numberSystem-latn")]
pub symbols: NumbersSymbols, pub symbols: NumbersSymbols,
#[serde(rename = "decimalFormats-numberSystem-latn")]
pub decimal_formats: DecimalFormats, pub decimal_formats: DecimalFormats,
#[serde(rename = "currencyFormats-numberSystem-latn")]
pub currency_formats: CurrencyFormats, pub currency_formats: CurrencyFormats,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Encode, Decode, Clone)]
pub struct Dates { pub struct Dates {
pub day_names: Vec<String>, pub day_names: Vec<String>,
pub day_names_short: Vec<String>, pub day_names_short: Vec<String>,
@@ -35,8 +32,7 @@ pub struct Dates {
pub months_letter: Vec<String>, pub months_letter: Vec<String>,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Encode, Decode, Clone)]
#[serde(rename_all = "camelCase")]
pub struct NumbersSymbols { pub struct NumbersSymbols {
pub decimal: String, pub decimal: String,
pub group: String, pub group: String,
@@ -54,31 +50,23 @@ pub struct NumbersSymbols {
} }
// See: https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns // See: https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns
#[derive(Serialize, Deserialize, Clone)] #[derive(Encode, Decode, Clone)]
pub struct CurrencyFormats { pub struct CurrencyFormats {
pub standard: String, pub standard: String,
#[serde(rename = "standard-alphaNextToNumber")]
#[serde(skip_serializing_if = "Option::is_none")]
pub standard_alpha_next_to_number: Option<String>, pub standard_alpha_next_to_number: Option<String>,
#[serde(rename = "standard-noCurrency")]
pub standard_no_currency: String, pub standard_no_currency: String,
pub accounting: String, pub accounting: String,
#[serde(rename = "accounting-alphaNextToNumber")]
#[serde(skip_serializing_if = "Option::is_none")]
pub accounting_alpha_next_to_number: Option<String>, pub accounting_alpha_next_to_number: Option<String>,
#[serde(rename = "accounting-noCurrency")]
pub accounting_no_currency: String, pub accounting_no_currency: String,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Encode, Decode, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DecimalFormats { pub struct DecimalFormats {
pub standard: String, pub standard: String,
} }
static LOCALES: Lazy<HashMap<String, Locale>> = Lazy::new(|| { static LOCALES: Lazy<HashMap<String, Locale>> =
serde_json::from_str(include_str!("locales.json")).expect("Failed parsing locale") Lazy::new(|| bitcode::decode(include_bytes!("locales.bin")).expect("Failed parsing locale"));
});
pub fn get_locale(id: &str) -> Result<&Locale, String> { pub fn get_locale(id: &str) -> Result<&Locale, String> {
// TODO: pass the locale once we implement locales in Rust // TODO: pass the locale once we implement locales in Rust