Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ pub trait Language {
fn place_unit_before(&self, _: u64) -> bool {
false
}
fn between_chunks(&self) -> &str {
" "
}
fn between_value_and_word(&self) -> &str {
" "
}

/// Make a dynamic copy of this language
fn clone_boxed(&self) -> BoxedLanguage;
Expand Down Expand Up @@ -444,7 +450,11 @@ impl<L: Language> Formatter<L> {
if now != "0" {
return now.to_owned();
} else {
ret = format!("0 {}", self.lang.get_word(self.min_unit, 0));
ret = format!(
"0{}{}",
self.lang.between_value_and_word(),
self.lang.get_word(self.min_unit, 0)
);
}
}

Expand Down Expand Up @@ -483,12 +493,14 @@ impl<L: Language> Formatter<L> {
let recurse_result = self.convert_impl(rem, items_left - 1);

let word = self.lang.get_word(dtu, x);
let between = self.lang.between_value_and_word();
let between_chunk = self.lang.between_chunks();

match (self.lang.place_unit_before(x), recurse_result.is_empty()) {
(true, true) => format!("{word} {x}"),
(true, false) => format!("{word} {x} {recurse_result}"),
(false, true) => format!("{x} {word}"),
(false, false) => format!("{x} {word} {recurse_result}"),
(true, true) => format!("{word}{between}{x}"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are inline format strings supported by the Rust version this crate aims to support?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume so, because they're used in the version on master as well (e.g. in format!("{word} {x} {recurse_result}"), all the variables are captured from the local scope like {between} is in the changed version).

Thanks for the quick review, I saw the repo wasn't very active so I figured I was just shouting into the void :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo +1.63 test passed (on my machine at least), so I think we're good!

(true, false) => format!("{word}{between}{x}{between_chunk}{recurse_result}"),
(false, true) => format!("{x}{between}{word}"),
(false, false) => format!("{x}{between}{word}{between_chunk}{recurse_result}"),
}
}
}
Expand Down