From 82f303f06479035f6b9bf9ae38f4300593344405 Mon Sep 17 00:00:00 2001 From: scoobybejesus Date: Sun, 25 Aug 2019 23:29:22 -0400 Subject: [PATCH] string_utils and decimal_utils; resolves #23 and resolves #22 --- src/cli_user_choices.rs | 6 +++--- src/create_lots_mvmts.rs | 2 +- src/{utils.rs => decimal_utils.rs} | 9 --------- src/import_accts_txns.rs | 2 +- src/import_cost_proceeds_etc.rs | 2 +- src/main.rs | 3 ++- src/string_utils.rs | 11 +++++++++++ src/tests/test.rs | 2 +- 8 files changed, 20 insertions(+), 17 deletions(-) rename src/{utils.rs => decimal_utils.rs} (91%) create mode 100644 src/string_utils.rs diff --git a/src/cli_user_choices.rs b/src/cli_user_choices.rs index aaccfb1..5a71177 100644 --- a/src/cli_user_choices.rs +++ b/src/cli_user_choices.rs @@ -15,7 +15,7 @@ use rustyline::error::ReadlineError; use rustyline::highlight::{Highlighter}; use crate::core_functions::InventoryCostingMethod; -use crate::utils; +use crate::string_utils; pub fn choose_file_for_import() -> PathBuf { @@ -194,7 +194,7 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option) -> (bool, Str let mut input = String::new(); let stdin = io::stdin(); stdin.lock().read_line(&mut input)?; - utils::trim_newline(&mut input); + string_utils::trim_newline(&mut input); let newly_chosen_date = NaiveDate::parse_from_str(&input, "%y-%m-%d") .unwrap_or(NaiveDate::parse_from_str(&input, "%Y-%m-%d") .expect("Date entered has an incorrect format. Program must abort.")); @@ -236,7 +236,7 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option) -> (bool, Str let mut input = String::new(); let stdin = io::stdin(); stdin.lock().read_line(&mut input)?; - utils::trim_newline(&mut input); + string_utils::trim_newline(&mut input); let newly_chosen_date = NaiveDate::parse_from_str(&input, "%y-%m-%d") .unwrap_or(NaiveDate::parse_from_str(&input, "%Y-%m-%d") diff --git a/src/create_lots_mvmts.rs b/src/create_lots_mvmts.rs index 41b50d8..474e973 100644 --- a/src/create_lots_mvmts.rs +++ b/src/create_lots_mvmts.rs @@ -11,7 +11,7 @@ use chrono::NaiveDate; use crate::transaction::{Transaction, ActionRecord, TxType, Polarity, TxHasMargin}; use crate::account::{Account, RawAccount, Lot, Movement}; use crate::core_functions::{InventoryCostingMethod, LikeKindSettings, ImportProcessParameters}; -use crate::utils::{round_d128_1e8}; +use crate::decimal_utils::{round_d128_1e8}; pub fn create_lots_and_movements( txns_map: HashMap, diff --git a/src/utils.rs b/src/decimal_utils.rs similarity index 91% rename from src/utils.rs rename to src/decimal_utils.rs index c7aace1..4b7a6ce 100644 --- a/src/utils.rs +++ b/src/decimal_utils.rs @@ -23,12 +23,3 @@ pub fn round_d128_1e8(to_round: &d128) -> d128 { // As you can see, the quantize is off by one. Quantizing to 10 rounds off the nearest one. Quantizing to 100 rounds off to nearest 10, etc. } - -pub fn trim_newline(s: &mut String) { - if s.ends_with('\n') { - s.pop(); - if s.ends_with('\r') { - s.pop(); - } - } -} diff --git a/src/import_accts_txns.rs b/src/import_accts_txns.rs index e7232f5..ddf1391 100644 --- a/src/import_accts_txns.rs +++ b/src/import_accts_txns.rs @@ -12,7 +12,7 @@ use decimal::d128; use crate::transaction::{Transaction, ActionRecord}; use crate::account::{Account, RawAccount}; -use crate::utils::{round_d128_1e8}; +use crate::decimal_utils::{round_d128_1e8}; pub fn import_accounts( diff --git a/src/import_cost_proceeds_etc.rs b/src/import_cost_proceeds_etc.rs index 9a0365e..5cf44cb 100644 --- a/src/import_cost_proceeds_etc.rs +++ b/src/import_cost_proceeds_etc.rs @@ -8,7 +8,7 @@ use decimal::d128; use crate::transaction::{Transaction, TxType, ActionRecord, Polarity}; use crate::account::{Account, RawAccount}; -use crate::utils::{round_d128_1e2}; +use crate::decimal_utils::{round_d128_1e2}; use crate::core_functions::{ImportProcessParameters}; pub fn add_cost_basis_to_movements( diff --git a/src/main.rs b/src/main.rs index 2f23bd5..7051981 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,8 @@ mod create_lots_mvmts; mod import_cost_proceeds_etc; mod cli_user_choices; mod csv_export; -mod utils; +mod string_utils; +mod decimal_utils; mod tests; use crate::core_functions::ImportProcessParameters; diff --git a/src/string_utils.rs b/src/string_utils.rs new file mode 100644 index 0000000..87b4a7c --- /dev/null +++ b/src/string_utils.rs @@ -0,0 +1,11 @@ +// Copyright (c) 2017-2019, scoobybejesus +// Redistributions must include the license: https://github.com/scoobybejesus/cryptools-rs/LEGAL.txt + +pub fn trim_newline(s: &mut String) { + if s.ends_with('\n') { + s.pop(); + if s.ends_with('\r') { + s.pop(); + } + } +} diff --git a/src/tests/test.rs b/src/tests/test.rs index 3c61e88..6f00883 100644 --- a/src/tests/test.rs +++ b/src/tests/test.rs @@ -8,7 +8,7 @@ use decimal::d128; use crate::account::{Account}; use crate::transaction::{Transaction, ActionRecord}; -use crate::utils::*; +use crate::decimal_utils::*; pub fn run_tests( transactions_map: &HashMap,