Skip to content

Commit

Permalink
Apply clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jan 29, 2024
1 parent 8f9c10f commit 366c63a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
26 changes: 12 additions & 14 deletions generate-api/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ impl CodeGenerator {
let mut normalized_langs = BTreeMap::<Lang, String>::new();

for (lang, objects) in objects.iter() {
normalized_langs.insert(lang.to_string(), lang.replace("@", "_"));
normalized_langs.insert(lang.to_string(), lang.replace('@', "_"));

let lang_categories = by_language
.entry(lang.to_string())
.or_insert(BTreeMap::new());
.or_default();

for object in objects.iter() {
if object.name == "LC_COLLATE"
Expand All @@ -278,7 +278,7 @@ impl CodeGenerator {
parser::Value::String(x) => {
lang_categories.insert(
object.name.clone(),
Category::Link(x.replace("@", "_"), object.name.clone()),
Category::Link(x.replace('@', "_"), object.name.clone()),
);
}
x => panic!("unexpected value for key {}: {:?}", key, x),
Expand All @@ -293,7 +293,7 @@ impl CodeGenerator {

let cat_field_meta = field_metadata
.entry(object.name.clone())
.or_insert(BTreeMap::new());
.or_default();

for (key, group) in &object
.values
Expand All @@ -303,13 +303,12 @@ impl CodeGenerator {
.group_by(|x| x.0.clone())
{
let key = key
.replace("'", "")
.replace("\"", "")
.replace("-", "_")
.replace("=", "eq")
.replace("<", "lt")
.replace(['\'', '\"'], "")
.replace('-', "_")
.replace('=', "eq")
.replace('<', "lt")
.replace("..", "dotdot")
.replace("2", "two")
.replace('2', "two")
.to_uppercase();
let group: Vec<_> = group.map(|x| &x.1).collect();

Expand Down Expand Up @@ -341,8 +340,7 @@ impl CodeGenerator {
fields.insert(key, Value::Array(vec));
} else if group
.iter()
.map(|x| x.iter().map(u8::from))
.flatten()
.flat_map(|x| x.iter().map(u8::from))
.all_equal()
{
meta.mark_array_2d();
Expand Down Expand Up @@ -384,7 +382,7 @@ impl CodeGenerator {
Category::Link(_, _) => {}
Category::Fields(fields) => {
for (field, meta) in all_fields {
if let None = fields.get(field) {
if fields.get(field).is_none() {
fields.insert(field.clone(), Value::Empty);
meta.make_optional();
}
Expand Down Expand Up @@ -529,7 +527,7 @@ impl CodeGenerator {
_ => "".to_string(),
};
write!(f, "\n/// `{}`: {}\n", lang, desc)?;
if lang == &"POSIX" {
if lang == "POSIX" {
writeln!(f, "\n#[default]\n")?;
}
writeln!(f, "\n{},\n", norm)?;
Expand Down
8 changes: 4 additions & 4 deletions generate-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() -> Result<()> {
let file_name = entry.file_name();
let lang = file_name.to_str().unwrap();

if parser::parse_lang(&lang).is_err() {
if parser::parse_lang(lang).is_err() {
// parse only files for which the name matches a language
// example: wa_BE@euro
continue;
Expand All @@ -41,7 +41,7 @@ fn main() -> Result<()> {

let lib_file = metadata.workspace_root.join("src").join("lib.rs");

if matches!(env::var("CHECK"), Ok(_)) {
if env::var("CHECK").is_ok() {
eprintln!("Calculating checksum...");
let mut f = Sha256::default();

Expand Down Expand Up @@ -80,7 +80,7 @@ fn validate_and_fix(objects: &mut Vec<Object>) {
/// for POSIX: `%l:%M:%S %p`.
/// If the locale has empty values for `AM_PM` we set `T_FMT_AMPM` to an empty value, similar to
/// other locales that don't have a 12-hour clock format.
fn validate_and_fix_t_fmt_ampm(objects: &mut Vec<Object>) {
fn validate_and_fix_t_fmt_ampm(objects: &mut [Object]) {
for object in objects.iter_mut() {
if object.name != "LC_TIME" {
continue;
Expand Down Expand Up @@ -109,7 +109,7 @@ fn validate_and_fix_t_fmt_ampm(objects: &mut Vec<Object>) {
/// In some locales `D_T_FMT` refers to other items:
/// to `D_FMT` with `%x`, `T_FMT` with `%X`, and/or `T_FMT_AMPM` with `%r`.
/// Inlining these strings simplifies the implementation of the strftime parser in chrono.
fn validate_and_fix_d_t_fmt(objects: &mut Vec<Object>) {
fn validate_and_fix_d_t_fmt(objects: &mut [Object]) {
for object in objects.iter_mut() {
if object.name != "LC_TIME" {
continue;
Expand Down
4 changes: 2 additions & 2 deletions generate-api/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn value<'a, E: ParseError<&'a str>>(
preceded(
|x| sp(x, escape_char, comment_char),
alt((
map_res(integer, |s| i64::from_str_radix(s, 10).map(Value::Integer)),
map_res(integer, |s| s.parse().map(Value::Integer)),
map(|x| string(x, escape_char), Value::String),
map(|x| parse_raw(x, escape_char, comment_char), Value::Raw),
)),
Expand Down Expand Up @@ -248,7 +248,7 @@ fn object<'a, E: ParseError<&'a str>>(
name: name.to_string(),
values: values
.into_iter()
.map(|(k, v)| (k, v.into_iter().filter_map(|x| x).collect()))
.map(|(k, v)| (k, v.into_iter().flatten().collect()))
.collect(),
},
))
Expand Down

0 comments on commit 366c63a

Please sign in to comment.