Skip to content

Commit

Permalink
Remove L! from sprintf calls
Browse files Browse the repository at this point in the history
Remove unnecessary L!
  • Loading branch information
faho committed Jan 13, 2024
1 parent 4bee08a commit 92c35fc
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 75 deletions.
6 changes: 3 additions & 3 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2570,7 +2570,7 @@ impl<'a> TokenStream<'a> {
result.keyword = keyword_for_token(token.type_, text);
result.has_dash_prefix = text.starts_with('-');
result.is_help_argument = [L!("-h"), L!("--help")].contains(&text);
result.is_newline = result.typ == ParseTokenType::end && text == L!("\n");
result.is_newline = result.typ == ParseTokenType::end && text == "\n";
result.may_be_variable_assignment = variable_assignment_equals_pos(text).is_some();
result.tok_error = token.error;

Expand Down Expand Up @@ -2920,14 +2920,14 @@ impl<'s> NodeVisitorMut for Populator<'s> {
fn keywords_user_presentable_description(kws: &'static [ParseKeyword]) -> WString {
assert!(!kws.is_empty(), "Should not be empty list");
if kws.len() == 1 {
return sprintf!(L!("keyword '%ls'"), kws[0]);
return sprintf!("keyword '%ls'", kws[0]);
}
let mut res = L!("keywords ").to_owned();
for (i, kw) in kws.iter().enumerate() {
if i != 0 {
res += L!(" or ");
}
res += &sprintf!(L!("'%ls'"), *kw)[..];
res += &sprintf!("'%ls'", *kw)[..];
}
res
}
Expand Down
12 changes: 5 additions & 7 deletions src/builtins/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ fn evaluate_expression(

streams
.err
.append(sprintf!(L!("%ls: Error: %ls\n"), cmd, error_message));
streams.err.append(sprintf!(L!("'%ls'\n"), expression));
.append(sprintf!("%ls: Error: %ls\n", cmd, error_message));
streams.err.append(sprintf!("'%ls'\n", expression));

STATUS_CMD_ERROR
}
Expand All @@ -198,15 +198,13 @@ fn evaluate_expression(
cmd,
err.kind.describe_wstr()
));
streams.err.append(sprintf!(L!("'%ls'\n"), expression));
streams.err.append(sprintf!("'%ls'\n", expression));
let padding = WString::from_chars(vec![' '; err.position + 1]);
if err.len >= 2 {
let tildes = WString::from_chars(vec!['~'; err.len - 2]);
streams
.err
.append(sprintf!(L!("%ls^%ls^\n"), padding, tildes));
streams.err.append(sprintf!("%ls^%ls^\n", padding, tildes));
} else {
streams.err.append(sprintf!(L!("%ls^\n"), padding));
streams.err.append(sprintf!("%ls^\n", padding));
}

STATUS_CMD_ERROR
Expand Down
4 changes: 2 additions & 2 deletions src/builtins/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ fn builtin_generic(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr])

// Hackish - if we have no arguments other than the command, we are a "naked invocation" and we
// just print help.
if argc == 1 || argv[0] == L!("time") {
if argc == 1 || argv[0] == "time" {
builtin_print_help(parser, streams, argv[0]);
return STATUS_INVALID_ARGS;
}
Expand All @@ -857,7 +857,7 @@ fn builtin_break_continue(
streams: &mut IoStreams,
argv: &mut [&wstr],
) -> Option<c_int> {
let is_break = argv[0] == L!("break");
let is_break = argv[0] == "break";
let argc = argv.len();

if argc != 1 {
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn source(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O
let func_filename;
let optind = opts.optind;

if argc == optind || args[optind] == L!("-") {
if argc == optind || args[optind] == "-" {
if streams.stdin_fd < 0 {
streams
.err
Expand Down
4 changes: 2 additions & 2 deletions src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn r#type(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> O

if path.is_empty() {
comment.push_utfstr(&wgettext!("Defined interactively"));
} else if path == L!("-") {
} else if path == "-" {
comment.push_utfstr(&wgettext!("Defined via `source`"));
} else {
let lineno: i32 = props.definition_lineno();
Expand All @@ -103,7 +103,7 @@ pub fn r#type(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> O
let path = props.copy_definition_file().unwrap_or(L!(""));
if path.is_empty() {
comment.push_utfstr(&wgettext!(", copied interactively"));
} else if path == L!("-") {
} else if path == "-" {
comment.push_utfstr(&wgettext!(", copied via `source`"));
} else {
let lineno = props.copy_definition_lineno();
Expand Down
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ pub fn reformat_for_screen(msg: &wstr, termsize: &Termsize) -> WString {
if line_width != 0 {
buff.push('\n');
}
buff += &sprintf!(L!("%ls-\n"), token)[..];
buff += &sprintf!("%ls-\n", token)[..];
line_width = 0;
} else {
// Print the token.
Expand Down
6 changes: 3 additions & 3 deletions src/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ impl<'ctx> Completer<'ctx> {

// Check to see if we have a preceding double-dash.
for tok in &tokens[..tokens.len() - 1] {
if tok.get_source(&cmdline) == L!("--") {
if tok.get_source(&cmdline) == "--" {
had_ddash = true;
break;
}
Expand Down Expand Up @@ -816,7 +816,7 @@ impl<'ctx> Completer<'ctx> {

// Hack. If we're cd, handle it specially (issue #1059, others).
handle_as_special_cd =
exp_command == L!("cd") || arg_data.visited_wrapped_commands.contains(L!("cd"));
exp_command == "cd" || arg_data.visited_wrapped_commands.contains(L!("cd"));
}

// Maybe apply variable assignments.
Expand Down Expand Up @@ -1607,7 +1607,7 @@ impl<'ctx> Completer<'ctx> {
if self.flags.descriptions && self.flags.autosuggestion {
// $history can be huge, don't put all of it in the completion description; see
// #6288.
if env_name == L!("history") {
if env_name == "history" {
let history = History::with_name(&history_session_id(self.ctx.vars()));
for i in 1..std::cmp::min(history.size(), 64) {
if i > 1 {
Expand Down
16 changes: 8 additions & 8 deletions src/env/environment_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,12 @@ impl EnvScopedImpl {
return None;
}

if key == L!("PWD") {
if key == "PWD" {
Some(EnvVar::new(
self.perproc_data.pwd.clone(),
EnvVarFlags::EXPORT,
))
} else if key == L!("history") {
} else if key == "history" {
// Big hack. We only allow getting the history on the main thread. Note that history_t
// may ask for an environment variable, so don't take the lock here (we don't need it).
if !is_main_thread() {
Expand All @@ -362,35 +362,35 @@ impl EnvScopedImpl {
L!("history"),
history.get_history(),
));
} else if key == L!("fish_killring") {
} else if key == "fish_killring" {
Some(EnvVar::new_from_name_vec(
L!("fish_killring"),
kill_entries(),
))
} else if key == L!("pipestatus") {
} else if key == "pipestatus" {
let js = &self.perproc_data.statuses;
let mut result = Vec::with_capacity(js.pipestatus.len());
for i in &js.pipestatus {
result.push(i.to_wstring());
}
Some(EnvVar::new_from_name_vec(L!("pipestatus"), result))
} else if key == L!("status") {
} else if key == "status" {
let js = &self.perproc_data.statuses;
Some(EnvVar::new_from_name(L!("status"), js.status.to_wstring()))
} else if key == L!("status_generation") {
} else if key == "status_generation" {
let status_generation = reader_status_count();
Some(EnvVar::new_from_name(
L!("status_generation"),
status_generation.to_wstring(),
))
} else if key == L!("fish_kill_signal") {
} else if key == "fish_kill_signal" {
let js = &self.perproc_data.statuses;
let signal = js.kill_signal.map_or(0, |ks| ks.code());
Some(EnvVar::new_from_name(
L!("fish_kill_signal"),
signal.to_wstring(),
))
} else if key == L!("umask") {
} else if key == "umask" {
// note umask() is an absurd API: you call it to set the value and it returns the old
// value. Thus we have to call it twice, to reset the value. The env_lock protects
// against races. Guess what the umask is; if we guess right we don't need to reset it.
Expand Down
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl EventDescription {
EventDescription::ProcessExit { .. }
| EventDescription::JobExit { .. }
| EventDescription::CallerExit { .. }
if filter == L!("exit") =>
if filter == "exit" =>
{
true
}
Expand Down
2 changes: 1 addition & 1 deletion src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ fn expand_variables(
// this way (it cannot be shadowed, etc).
let mut history = None;
let mut var = None;
if var_name == L!("history") {
if var_name == "history" {
history = Some(History::with_name(&history_session_id(vars)));
} else if var_name.as_char_slice() != [VARIABLE_EXPAND_EMPTY] {
var = vars.get(var_name);
Expand Down
12 changes: 6 additions & 6 deletions src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub fn autosuggest_validate_from_history(
};

// We handle cd specially.
if parsed_command == L!("cd") && !cd_dir.is_empty() {
if parsed_command == "cd" && !cd_dir.is_empty() {
if expand_one(&mut cd_dir, ExpandFlags::SKIP_CMDSUBST, ctx, None) {
if string_prefixes_string(&cd_dir, L!("--help"))
|| string_prefixes_string(&cd_dir, L!("-h"))
Expand Down Expand Up @@ -809,7 +809,7 @@ pub fn is_potential_path(
// We do not end with a slash; it does not have to be a directory.
let dir_name = wdirname(&abs_path);
let filename_fragment = wbasename(&abs_path);
if dir_name == L!("/") && filename_fragment == L!("/") {
if dir_name == "/" && filename_fragment == "/" {
// cd ///.... No autosuggestion.
return true;
}
Expand Down Expand Up @@ -1231,7 +1231,7 @@ impl<'s> Highlighter<'s> {
let target_path = path_apply_working_directory(&target, &self.working_directory);
match oper.mode {
RedirectionMode::fd => {
if target == L!("-") {
if target == "-" {
target_is_valid = true;
} else {
target_is_valid = match fish_wcstoi(&target) {
Expand Down Expand Up @@ -1373,8 +1373,8 @@ impl<'s> Highlighter<'s> {

// Color arguments and redirections.
// Except if our command is 'cd' we have special logic for how arguments are colored.
let is_cd = expanded_cmd == L!("cd");
let mut is_set = expanded_cmd == L!("set");
let is_cd = expanded_cmd == "cd";
let mut is_set = expanded_cmd == "set";
// If we have seen a "--" argument, color all options from then on as normal arguments.
let mut have_dashdash = false;
for v in &stmt.args_or_redirs {
Expand All @@ -1387,7 +1387,7 @@ impl<'s> Highlighter<'s> {
}
}
self.visit_argument(v.argument(), is_cd, !have_dashdash);
if v.argument().source(self.buff) == L!("--") {
if v.argument().source(self.buff) == "--" {
have_dashdash = true;
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ fn test_killring() {

assert!(kr.entries() == [L!("c"), L!("b"), L!("a")]);

assert!(kr.yank_rotate() == L!("b"));
assert!(kr.yank_rotate() == "b");
assert!(kr.entries() == [L!("b"), L!("a"), L!("c")]);

assert!(kr.yank_rotate() == L!("a"));
assert!(kr.yank_rotate() == "a");
assert!(kr.entries() == [L!("a"), L!("c"), L!("b")]);

kr.add(WString::from_str("d"));

assert!((kr.entries() == [L!("d"), L!("a"), L!("c"), L!("b")]));

assert!(kr.yank_rotate() == L!("a"));
assert!(kr.yank_rotate() == "a");
assert!((kr.entries() == [L!("a"), L!("c"), L!("b"), L!("d")]));
}
2 changes: 1 addition & 1 deletion src/pager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ impl Pager {
self.unfiltered_completion_infos = process_completions_into_infos(raw_completions);

// Maybe join them.
if self.prefix == L!("-") {
if self.prefix == "-" {
join_completions(&mut self.unfiltered_completion_infos);
}

Expand Down
40 changes: 20 additions & 20 deletions src/parse_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,24 +244,24 @@ impl printf_compat::args::ToArg<'static> for ParseKeyword {
impl From<&wstr> for ParseKeyword {
fn from(s: &wstr) -> Self {
match s {
_ if s == L!("!") => ParseKeyword::kw_exclam,
_ if s == L!("and") => ParseKeyword::kw_and,
_ if s == L!("begin") => ParseKeyword::kw_begin,
_ if s == L!("builtin") => ParseKeyword::kw_builtin,
_ if s == L!("case") => ParseKeyword::kw_case,
_ if s == L!("command") => ParseKeyword::kw_command,
_ if s == L!("else") => ParseKeyword::kw_else,
_ if s == L!("end") => ParseKeyword::kw_end,
_ if s == L!("exec") => ParseKeyword::kw_exec,
_ if s == L!("for") => ParseKeyword::kw_for,
_ if s == L!("function") => ParseKeyword::kw_function,
_ if s == L!("if") => ParseKeyword::kw_if,
_ if s == L!("in") => ParseKeyword::kw_in,
_ if s == L!("not") => ParseKeyword::kw_not,
_ if s == L!("or") => ParseKeyword::kw_or,
_ if s == L!("switch") => ParseKeyword::kw_switch,
_ if s == L!("time") => ParseKeyword::kw_time,
_ if s == L!("while") => ParseKeyword::kw_while,
_ if s == "!" => ParseKeyword::kw_exclam,
_ if s == "and" => ParseKeyword::kw_and,
_ if s == "begin" => ParseKeyword::kw_begin,
_ if s == "builtin" => ParseKeyword::kw_builtin,
_ if s == "case" => ParseKeyword::kw_case,
_ if s == "command" => ParseKeyword::kw_command,
_ if s == "else" => ParseKeyword::kw_else,
_ if s == "end" => ParseKeyword::kw_end,
_ if s == "exec" => ParseKeyword::kw_exec,
_ if s == "for" => ParseKeyword::kw_for,
_ if s == "function" => ParseKeyword::kw_function,
_ if s == "if" => ParseKeyword::kw_if,
_ if s == "in" => ParseKeyword::kw_in,
_ if s == "not" => ParseKeyword::kw_not,
_ if s == "or" => ParseKeyword::kw_or,
_ if s == "switch" => ParseKeyword::kw_switch,
_ if s == "time" => ParseKeyword::kw_time,
_ if s == "while" => ParseKeyword::kw_while,
_ => ParseKeyword::none,
}
}
Expand Down Expand Up @@ -404,7 +404,7 @@ pub fn token_type_user_presentable_description(
keyword: ParseKeyword,
) -> WString {
if keyword != ParseKeyword::none {
return sprintf!(L!("keyword: '%ls'"), keyword.to_wstr());
return sprintf!("keyword: '%ls'", keyword.to_wstr());
}
match type_ {
ParseTokenType::string => L!("a string").to_owned(),
Expand All @@ -418,7 +418,7 @@ pub fn token_type_user_presentable_description(
ParseTokenType::error => L!("a parse error").to_owned(),
ParseTokenType::tokenizer_error => L!("an incomplete token").to_owned(),
ParseTokenType::comment => L!("a comment").to_owned(),
_ => sprintf!(L!("a %ls"), type_.to_wstr()),
_ => sprintf!("a %ls", type_.to_wstr()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/parse_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ impl<'a> NodeVisitor<'a> for IndentVisitor<'a> {
{
// The newline after "begin" is optional, so it is part of the header.
// The header is not in the indented block, so indent the newline here.
if node.source(self.src) == L!("\n") {
if node.source(self.src) == "\n" {
inc = 1;
dec = 1;
}
Expand Down Expand Up @@ -1534,7 +1534,7 @@ fn detect_errors_in_decorated_statement(
}

// Similarly for time (#8841).
if command == L!("time") {
if command == "time" {
errored = append_syntax_error!(
parse_errors,
source_start,
Expand All @@ -1549,7 +1549,7 @@ fn detect_errors_in_decorated_statement(
// to avoid people trying `if $status`.
// We see this surprisingly regularly.
let com = dst.command.source(buff_src);
if com == L!("$status") {
if com == "$status" {
errored = append_syntax_error!(
parse_errors,
source_start,
Expand Down Expand Up @@ -1615,7 +1615,7 @@ fn detect_errors_in_decorated_statement(
}

if !found_loop {
errored = if command == L!("break") {
errored = if command == "break" {
append_syntax_error!(
parse_errors,
source_start,
Expand Down
2 changes: 1 addition & 1 deletion src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ pub fn path_as_implicit_cd(path: &wstr, wd: &wstr, vars: &dyn Environment) -> Op
|| exp_path.starts_with(L!("./"))
|| exp_path.starts_with(L!("../"))
|| exp_path.ends_with(L!("/"))
|| exp_path == L!("..")
|| exp_path == ".."
{
// These paths can be implicit cd, so see if you cd to the path. Note that a single period
// cannot (that's used for sourcing files anyways).
Expand Down
Loading

0 comments on commit 92c35fc

Please sign in to comment.