mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
expr: Use chars().count() as we can have some multibytes chars
Partially fixes #3132 Fixes one of the test of tests/misc/expr-multibyte
This commit is contained in:
parent
f9e04ae5ef
commit
7225fb6c24
2 changed files with 27 additions and 2 deletions
|
@ -10,7 +10,7 @@
|
||||||
//! * `<https://en.wikipedia.org/wiki/Shunting-yard_algorithm>`
|
//! * `<https://en.wikipedia.org/wiki/Shunting-yard_algorithm>`
|
||||||
//!
|
//!
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) binop binops ints paren prec
|
// spell-checker:ignore (ToDO) binop binops ints paren prec multibytes
|
||||||
|
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
use num_traits::{One, Zero};
|
use num_traits::{One, Zero};
|
||||||
|
@ -465,7 +465,9 @@ fn operator_match(values: &[String]) -> Result<String, String> {
|
||||||
|
|
||||||
fn prefix_operator_length(values: &[String]) -> String {
|
fn prefix_operator_length(values: &[String]) -> String {
|
||||||
assert!(values.len() == 1);
|
assert!(values.len() == 1);
|
||||||
values[0].len().to_string()
|
// Use chars().count() as we can have some multibytes chars
|
||||||
|
// See https://github.com/uutils/coreutils/issues/3132
|
||||||
|
values[0].chars().count().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prefix_operator_index(values: &[String]) -> String {
|
fn prefix_operator_index(values: &[String]) -> String {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// spell-checker:ignore αbcdef
|
||||||
|
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -95,6 +97,27 @@ fn test_and() {
|
||||||
new_ucmd!().args(&["", "&", "1"]).run().stdout_is("0\n");
|
new_ucmd!().args(&["", "&", "1"]).run().stdout_is("0\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_length_fail() {
|
||||||
|
new_ucmd!().args(&["length", "αbcdef", "1"]).fails();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_length() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["length", "abcdef"])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only("6\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_length_mb() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["length", "αbcdef"])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only("6\n");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_substr() {
|
fn test_substr() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue