mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
ptx: match GNU default behavior by skipping non-alphabetic index tokens (#10919)
* ptx: skip non-alphabetic tokens in default word matching * Simplify no output operation Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * fix: Keyword must start at first alphabetic char * Simplify find first alphabet --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
+13
-1
@@ -356,7 +356,19 @@ fn create_word_set(config: &Config, filter: &WordFilter, file_map: &FileMap) ->
|
||||
};
|
||||
// match words with given regex
|
||||
for mat in reg.find_iter(line) {
|
||||
let (beg, end) = (mat.start(), mat.end());
|
||||
let (mut beg, end) = (mat.start(), mat.end());
|
||||
|
||||
// GNU-compatible default behavior:
|
||||
// with default regexp, keyword must start at first alphabetic char.
|
||||
if filter.word_regex == Config::default().context_regex {
|
||||
let matched = &line[beg..end];
|
||||
if let Some(pos) = matched.find(|c: char| c.is_alphabetic()) {
|
||||
beg += pos;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if config.input_ref && ((beg, end) == (ref_beg, ref_end)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -300,6 +300,11 @@ fn test_gnu_mode_dumb_format() {
|
||||
new_ucmd!().pipe_in("a b").succeeds().stdout_only(
|
||||
" a b\n a b\n",
|
||||
);
|
||||
|
||||
new_ucmd!()
|
||||
.pipe_in("2a")
|
||||
.succeeds()
|
||||
.stdout_only(format!("{}2 a\n", " ".repeat(35)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -330,6 +335,15 @@ fn test_unicode_padding_alignment() {
|
||||
.stdout_only(" a\n é\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gnu_compat_numeric_token_with_emoji_produces_no_index() {
|
||||
// GNU ptx produces no output for this input in default mode.
|
||||
new_ucmd!()
|
||||
.pipe_in("012345678901234567890123456789🛠\n")
|
||||
.succeeds()
|
||||
.no_output();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unicode_truncation_alignment() {
|
||||
new_ucmd!()
|
||||
|
||||
Reference in New Issue
Block a user