Upstream sharkdp/numbat state of the touched files before c69ba1b277
This commit is contained in:
1 parent
8d093a24a9
commit
62dfa47710
2 files changed
+3
-18
No files matched your search
@@ -1,19 +1,11 @@
|
|||||||
assert_eq(str_length(""), 0)
|
assert_eq(str_length(""), 0)
|
||||||
assert_eq(str_length("foo"), 3)
|
assert_eq(str_length("foo"), 3)
|
||||||
|
|
||||||
# Length and slicing operate on Unicode code points, not on UTF-8 bytes
|
|
||||||
assert_eq(str_length("café"), 4)
|
|
||||||
assert_eq(str_length("❤"), 1)
|
|
||||||
|
|
||||||
assert_eq(str_slice(0, 5, "hello world"), "hello")
|
assert_eq(str_slice(0, 5, "hello world"), "hello")
|
||||||
assert_eq(str_slice(6, 11, "hello world"), "world")
|
assert_eq(str_slice(6, 11, "hello world"), "world")
|
||||||
assert_eq(str_slice(0, 0, "hello world"), "")
|
assert_eq(str_slice(0, 0, "hello world"), "")
|
||||||
assert_eq(str_slice(0, 100, "hello world"), "")
|
assert_eq(str_slice(0, 100, "hello world"), "")
|
||||||
|
|
||||||
assert_eq(str_slice(0, 4, "café"), "café")
|
|
||||||
assert_eq(str_slice(3, 4, "café"), "é")
|
|
||||||
assert_eq(str_slice(0, 3, "café"), "caf")
|
|
||||||
|
|
||||||
assert_eq(chr(65), "A")
|
assert_eq(chr(65), "A")
|
||||||
assert_eq(chr(97), "a")
|
assert_eq(chr(97), "a")
|
||||||
assert_eq(chr(0x2764), "❤")
|
assert_eq(chr(0x2764), "❤")
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ pub fn str_length(
|
|||||||
mut args: Args,
|
mut args: Args,
|
||||||
_return_type: &TypeScheme,
|
_return_type: &TypeScheme,
|
||||||
) -> Result<Value, Box<RuntimeErrorKind>> {
|
) -> Result<Value, Box<RuntimeErrorKind>> {
|
||||||
let len = string_arg!(args).chars().count();
|
let len = string_arg!(args).len();
|
||||||
return_scalar!(len as f64)
|
return_scalar!(len as f64)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,16 +41,9 @@ pub fn str_slice(
|
|||||||
let end = quantity_arg!(args).unsafe_value().to_f64() as usize;
|
let end = quantity_arg!(args).unsafe_value().to_f64() as usize;
|
||||||
let input = string_arg!(args);
|
let input = string_arg!(args);
|
||||||
|
|
||||||
// Indices refer to code points, not bytes; out-of-range requests yield an
|
let output = input.get(start..end).unwrap_or_default();
|
||||||
// empty string as before.
|
|
||||||
let characters = input.chars().collect::<Vec<char>>();
|
|
||||||
let output = if start <= end && end <= characters.len() {
|
|
||||||
characters[start..end].iter().collect::<String>()
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
return_string!(from = &output)
|
return_string!(borrowed = output)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn chr(
|
pub fn chr(
|
||||||
|
|||||||
Reference in new issue
Block a user