Skip to content

Commit

Permalink
Simplification suggested by @nickelc
Browse files Browse the repository at this point in the history
in e169da7#r109077300

This also restores an unrelated change in the order of imports in a test
that did not need to be reverted.

Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
  • Loading branch information
daira committed Jun 26, 2023
1 parent 0836cd5 commit 9e64083
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/xdg_user_dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn parse_user_dirs(home_dir: &Path, user_dir: Option<&str>, bytes: &[u8]) -> Has
let key = if key.starts_with(b"XDG_") && key.ends_with(b"_DIR") {
match str::from_utf8(&key[4..key.len()-4]) {
Ok(key) =>
if user_dir.is_some() && option_contains(user_dir, key) {
if user_dir == Some(key) {
single_dir_found = true;
key
} else if user_dir.is_none() {
Expand Down Expand Up @@ -137,18 +137,12 @@ fn shell_unescape(escaped: &[u8]) -> Vec<u8> {
unescaped
}

fn option_contains<T : PartialEq>(option: Option<T>, value: T) -> bool {
match option {
Some(val) => val == value,
None => false
}
}

#[cfg(test)]
mod tests {
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use super::{trim_blank, shell_unescape, split_once, parse_user_dirs};

use super::{parse_user_dirs, shell_unescape, split_once, trim_blank};

#[test]
fn test_trim_blank() {
Expand Down

0 comments on commit 9e64083

Please sign in to comment.