Browse Source

improve slightly parser when user edits already formatted cell

master
Paul Lesur 2 years ago
parent
commit
7c6a8569a1
5 changed files with 15 additions and 3 deletions
  1. 1
    0
      build.rs
  2. 8
    1
      src/data.rs
  3. 2
    0
      src/main_window.rs
  4. 2
    1
      translations/en_GB.json
  5. 2
    1
      translations/fr_FR.json

+ 1
- 0
build.rs View File

@@ -40,6 +40,7 @@ generate_translation! {

format_money(sign: &str, whole: &str, cents: &str),
whole_balance(sign: &str, whole: &str, cents: &str),
currency_symbol,
}

fn main() {

+ 8
- 1
src/data.rs View File

@@ -118,7 +118,14 @@ pub struct MoneyAmount {
}

impl MoneyAmount {
pub fn from_string(amount_str: &str, decimal_separator: &str) -> Option<Self> {
pub fn from_string(
amount_str: &str,
decimal_separator: &str,
currency_symbol: &str,
) -> Option<Self> {
// TODO: to be completely generic over the possible formatting, one would need to use the
// matching what the input should be
let amount_str = amount_str.replace(currency_symbol, "");
let split_val: Vec<_> = amount_str.split(decimal_separator).collect();
let (whole, cents) = match split_val.len() {
1 => {

+ 2
- 0
src/main_window.rs View File

@@ -259,6 +259,7 @@ impl Widget for MainWindow {
let amount = if let Some(amount) = MoneyAmount::from_string(
&value,
self.model.translation_provider.decimal_separator(),
self.model.translation_provider.currency_symbol(),
) {
amount
} else {
@@ -373,6 +374,7 @@ impl Widget for MainWindow {
let amount = if let Some(amount) = MoneyAmount::from_string(
&value,
self.model.translation_provider.decimal_separator(),
self.model.translation_provider.currency_symbol(),
) {
amount
} else {

+ 2
- 1
translations/en_GB.json View File

@@ -33,5 +33,6 @@
"spending_category_name_placeholder": "No category",

"format_money": "{sign}£{whole}.{cents}",
"whole_balance": "Your monthly balance is: {sign}£{whole}.{cents}"
"whole_balance": "Your monthly balance is: {sign}£{whole}.{cents}",
"currency_symbol": "£"
}

+ 2
- 1
translations/fr_FR.json View File

@@ -33,5 +33,6 @@
"spending_category_name_placeholder": "Pas de catégorie",

"format_money": "{sign}{whole},{cents} €",
"whole_balance": "Votre solde mensuel est de: {sign}{whole},{cents} €"
"whole_balance": "Votre solde mensuel est de: {sign}{whole},{cents} €",
"currency_symbol": "€"
}

Loading…
Cancel
Save