+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/cspell.dictionaries/jargon.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,8 @@ nofield
# * clippy
uninlined
nonminimal

# * locale and typography
CTYPE
Guillemets
guillemets
1 change: 1 addition & 0 deletions src/uu/ls/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ls-help-set-quoting-style = Set quoting style.
ls-help-literal-quoting-style = Use literal quoting style. Equivalent to `--quoting-style=literal`
ls-help-escape-quoting-style = Use escape quoting style. Equivalent to `--quoting-style=escape`
ls-help-c-quoting-style = Use C quoting style. Equivalent to `--quoting-style=c`
ls-help-locale-quoting-style = Use locale-aware quoting style. Uses quotation marks appropriate for the current locale (e.g., « » for French, „ " for German, 「 」 for Japanese). Equivalent to `--quoting-style=locale`
ls-help-replace-control-chars = Replace control characters with '?' if they are not escaped.
ls-help-show-control-chars = Show control characters 'as is' if they are not escaped.
ls-help-show-time-field = Show time in <field>:
Expand Down
1 change: 1 addition & 0 deletions src/uu/ls/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ls-help-set-quoting-style = Définir le style de citation.
ls-help-literal-quoting-style = Utiliser le style de citation littéral. Équivalent à `--quoting-style=literal`
ls-help-escape-quoting-style = Utiliser le style de citation d'échappement. Équivalent à `--quoting-style=escape`
ls-help-c-quoting-style = Utiliser le style de citation C. Équivalent à `--quoting-style=c`
ls-help-locale-quoting-style = Utiliser le style de citation adapté à la locale. Utilise les guillemets appropriés à la locale actuelle (par ex., « » pour le français, „ " pour l'allemand, 「 」 pour le japonais). Équivalent à `--quoting-style=locale`
ls-help-replace-control-chars = Remplacer les caractères de contrôle par '?' s'ils ne sont pas échappés.
ls-help-show-control-chars = Afficher les caractères de contrôle 'tels quels' s'ils ne sont pas échappés.
ls-help-show-time-field = Afficher l'heure dans <champ> :
Expand Down
4 changes: 4 additions & 0 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,9 @@ fn match_quoting_style_name(style: &str, show_control: bool) -> Option<QuotingSt
"shell-escape-always" => Some(QuotingStyle::SHELL_ESCAPE_QUOTE),
"c" => Some(QuotingStyle::C_DOUBLE),
"escape" => Some(QuotingStyle::C_NO_QUOTES),
"locale" => Some(QuotingStyle::C {
quotes: uucore::quoting_style::Quotes::Locale,
}),
_ => None,
}
.map(|qs| qs.show_control(show_control))
Expand Down Expand Up @@ -1294,6 +1297,7 @@ pub fn uu_app() -> Command {
PossibleValue::new("shell-escape-always"),
PossibleValue::new("c").alias("c-maybe"),
PossibleValue::new("escape"),
PossibleValue::new("locale"),
]))
.overrides_with_all([
QUOTING_STYLE,
Expand Down
40 changes: 35 additions & 5 deletions src/uucore/src/lib/features/quoting_style/c_quoter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use super::{EscapedChar, Quoter, Quotes};
use super::{EscapedChar, Quoter, Quotes, locale_quotes};

pub(super) struct CQuoter {
/// The type of quotes to use.
quotes: Quotes,

/// Opening quote character (for Locale variant).
#[allow(dead_code)] // Used in new() to initialize buffer
open_quote: char,

/// Closing quote character (for Locale variant).
close_quote: char,

dirname: bool,

buffer: Vec<u8>,
Expand All @@ -17,14 +24,31 @@ pub(super) struct CQuoter {
impl CQuoter {
pub fn new(quotes: Quotes, dirname: bool, size_hint: usize) -> Self {
let mut buffer = Vec::with_capacity(size_hint);

// Determine quote characters based on quote type
let (open_quote, close_quote) = match quotes {
Quotes::None => ('\0', '\0'),
Quotes::Single => ('\'', '\''),
Quotes::Double => ('"', '"'),
Quotes::Locale => locale_quotes::get_locale_quote_chars(),
};

// Add opening quote to buffer
match quotes {
Quotes::None => (),
Quotes::Single => buffer.push(b'\''),
Quotes::Double => buffer.push(b'"'),
Quotes::Single | Quotes::Double => buffer.push(open_quote as u8),
Quotes::Locale => {
// Push UTF-8 encoded quote character
let mut buf = [0; 4];
let quote_str = open_quote.encode_utf8(&mut buf);
buffer.extend_from_slice(quote_str.as_bytes());
}
}

Self {
quotes,
open_quote,
close_quote,
dirname,
buffer,
}
Expand All @@ -47,10 +71,16 @@ impl Quoter for CQuoter {
}

fn finalize(mut self: Box<Self>) -> Vec<u8> {
// Add closing quote to buffer
match self.quotes {
Quotes::None => (),
Quotes::Single => self.buffer.push(b'\''),
Quotes::Double => self.buffer.push(b'"'),
Quotes::Single | Quotes::Double => self.buffer.push(self.close_quote as u8),
Quotes::Locale => {
// Push UTF-8 encoded closing quote character
let mut buf = [0; 4];
let quote_str = self.close_quote.encode_utf8(&mut buf);
self.buffer.extend_from_slice(quote_str.as_bytes());
}
}
self.buffer
}
Expand Down
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载