Decompose into two functions

This commit is contained in:
Clémentine Urquizar 2021-06-16 17:13:21 +02:00
parent dc5a3d4a62
commit 9538790b33
No known key found for this signature in database
GPG Key ID: D8E7CC7422E77E1A

View File

@ -220,6 +220,30 @@ fn compute_formatted_options(
let mut formatted_options = HashMap::new(); let mut formatted_options = HashMap::new();
formatted_options = add_highlight_to_formatted_options(
formatted_options,
attr_to_highlight,
fields_ids_map,
displayed_ids,
);
formatted_options = add_crop_to_formatted_options(
formatted_options,
attr_to_crop,
query_crop_length,
fields_ids_map,
displayed_ids,
);
formatted_options
}
fn add_highlight_to_formatted_options(
mut formatted_options: HashMap<FieldId, FormatOptions>,
attr_to_highlight: &HashSet<String>,
fields_ids_map: &FieldsIdsMap,
displayed_ids: &BTreeSet<u8>,
) -> HashMap<FieldId, FormatOptions> {
for attr in attr_to_highlight { for attr in attr_to_highlight {
let new_format = FormatOptions { let new_format = FormatOptions {
highlight: true, highlight: true,
@ -237,15 +261,24 @@ fn compute_formatted_options(
formatted_options.insert(id, new_format); formatted_options.insert(id, new_format);
} }
} }
formatted_options
}
fn add_crop_to_formatted_options(
mut formatted_options: HashMap<FieldId, FormatOptions>,
attr_to_crop: &[String],
crop_length: usize,
fields_ids_map: &FieldsIdsMap,
displayed_ids: &BTreeSet<u8>,
) -> HashMap<FieldId, FormatOptions> {
for attr in attr_to_crop { for attr in attr_to_crop {
let mut attr_name = attr.clone(); let mut attr_name = attr.clone();
let mut attr_len = query_crop_length; let mut attr_len = crop_length;
let mut split = attr_name.rsplitn(2, ':'); let mut split = attr_name.rsplitn(2, ':');
attr_name = match split.next().zip(split.next()) { attr_name = match split.next().zip(split.next()) {
Some((len, name)) => { Some((len, name)) => {
attr_len = len.parse().unwrap_or(query_crop_length); attr_len = len.parse().unwrap_or(crop_length);
name.to_string() name.to_string()
}, },
None => attr_name, None => attr_name,