From 4f14b8dc7b049b78b5e11d7792cc57d23dff8c8e Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 29 Mar 2023 20:57:47 +0200 Subject: [PATCH] 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. --- fish-rust/src/builtins/echo.rs | 4 ++-- fish-rust/src/wchar.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fish-rust/src/builtins/echo.rs b/fish-rust/src/builtins/echo.rs index 9b251cd87..f8b206481 100644 --- a/fish-rust/src/builtins/echo.rs +++ b/fish-rust/src/builtins/echo.rs @@ -4,7 +4,7 @@ use libc::c_int; use super::shared::{builtin_missing_argument, io_streams_t, STATUS_CMD_OK, STATUS_INVALID_ARGS}; 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}; #[derive(Debug, Clone, Copy)] @@ -201,7 +201,7 @@ pub fn echo( { consumed = digits_consumed; // 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 { consumed = 0; '\\' diff --git a/fish-rust/src/wchar.rs b/fish-rust/src/wchar.rs index 4e2f9f75f..7f723e4f0 100644 --- a/fish-rust/src/wchar.rs +++ b/fish-rust/src/wchar.rs @@ -74,7 +74,7 @@ pub const ENCODE_DIRECT_END: char = match char::from_u32(ENCODE_DIRECT_BASE as u /// character. /// /// 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)) .expect("private-use codepoint should be valid char") }