Shorthand for escaping with default options

Should probably do this on the C++ side too.
This commit is contained in:
Johannes Altmanninger 2023-04-22 00:49:16 +02:00
parent 19fe0f6a91
commit 6c07af9343
3 changed files with 9 additions and 4 deletions

View file

@ -4,7 +4,7 @@ use crate::builtins::shared::{
builtin_unknown_option, io_streams_t, BUILTIN_ERR_TOO_MANY_ARGUMENTS, STATUS_CMD_ERROR,
STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use crate::common::{escape_string, valid_func_name, EscapeStringStyle};
use crate::common::{escape, escape_string, valid_func_name, EscapeStringStyle};
use crate::env::status::{ENV_NOT_FOUND, ENV_OK};
use crate::env::EnvMode;
use crate::ffi::parser_t;
@ -415,7 +415,7 @@ fn abbr_erase(opts: &Options, parser: &mut parser_t) -> Option<c_int> {
result = Some(ENV_NOT_FOUND);
}
// Erase the old uvar - this makes `abbr -e` work.
let esc_src = escape_string(arg, EscapeStringStyle::Script(Default::default()));
let esc_src = escape(arg);
if !esc_src.is_empty() {
let var_name = WString::from_str("_fish_abbr_") + esc_src.as_utfstr();
let ret = parser.remove_var(&var_name, EnvMode::UNIVERSAL.into());

View file

@ -140,6 +140,11 @@ bitflags! {
}
}
/// Replace special characters with backslash escape sequences. Newline is replaced with `\n`, etc.
pub fn escape(s: &wstr) -> WString {
escape_string(s, EscapeStringStyle::Script(EscapeFlags::default()))
}
/// Replace special characters with backslash escape sequences. Newline is replaced with `\n`, etc.
pub fn escape_string(s: &wstr, style: EscapeStringStyle) -> WString {
match style {

View file

@ -1,5 +1,5 @@
use crate::{
common::{escape_string, EscapeStringStyle},
common::escape,
ffi::{self, parser_t, wcharz_t, wcstring_list_ffi_t},
global_safety::RelaxedAtomicBool,
wchar::{self, wstr, L},
@ -61,7 +61,7 @@ pub fn trace_argv(parser: &parser_t, command: &wstr, args: &[&wstr]) {
}
for arg in args {
trace_text.push(' ');
trace_text.push_utfstr(&escape_string(arg, EscapeStringStyle::default()));
trace_text.push_utfstr(&escape(arg));
}
trace_text.push('\n');
ffi::log_extra_to_flog_file(&trace_text.to_ffi());