Rename byte encoding helper

Existing C++ code didn't use a function for this but simply added
ENCODE_DIRECT_BASE. In Rust that's more verbose because char won't do
arithmetics, hence the function.

We'll add a dual function for decoding, so let's rename this.

BTW we should get rid of the "wchar" naming, it's just "char" in Rust.
This commit is contained in:
Johannes Altmanninger 2023-03-29 20:57:47 +02:00
parent 0b6605b026
commit 4f14b8dc7b
2 changed files with 3 additions and 3 deletions

View File

@ -4,7 +4,7 @@ use libc::c_int;
use super::shared::{builtin_missing_argument, io_streams_t, STATUS_CMD_OK, STATUS_INVALID_ARGS}; use super::shared::{builtin_missing_argument, io_streams_t, STATUS_CMD_OK, STATUS_INVALID_ARGS};
use crate::ffi::parser_t; use crate::ffi::parser_t;
use crate::wchar::{wchar_literal_byte, wstr, WString, L}; use crate::wchar::{encode_byte_to_char, wstr, WString, L};
use crate::wgetopt::{wgetopter_t, woption}; use crate::wgetopt::{wgetopter_t, woption};
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
@ -201,7 +201,7 @@ pub fn echo(
{ {
consumed = digits_consumed; consumed = digits_consumed;
// The narrow_val is a literal byte that we want to output (#1894). // The narrow_val is a literal byte that we want to output (#1894).
wchar_literal_byte(narrow_val) encode_byte_to_char(narrow_val)
} else { } else {
consumed = 0; consumed = 0;
'\\' '\\'

View File

@ -74,7 +74,7 @@ pub const ENCODE_DIRECT_END: char = match char::from_u32(ENCODE_DIRECT_BASE as u
/// character. /// character.
/// ///
/// See https://github.com/fish-shell/fish-shell/issues/1894. /// See https://github.com/fish-shell/fish-shell/issues/1894.
pub fn wchar_literal_byte(byte: u8) -> char { pub fn encode_byte_to_char(byte: u8) -> char {
char::from_u32(u32::from(ENCODE_DIRECT_BASE) + u32::from(byte)) char::from_u32(u32::from(ENCODE_DIRECT_BASE) + u32::from(byte))
.expect("private-use codepoint should be valid char") .expect("private-use codepoint should be valid char")
} }