Skip to content

Commit cf7d7bb

Browse files
committed
Fix clippy
1 parent be07e8a commit cf7d7bb

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

dsc_lib/locales/en-us.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,11 @@ description = "Converts a value to a string"
483483
description = "Returns a substring that starts at the specified character position and contains the specified number of characters"
484484
invoked = "substring function"
485485
startIndexNegative = "Start index cannot be negative"
486-
lengthNegative = "Length cannot be negative"
487486
startIndexTooLarge = "Start index is beyond the end of the string"
487+
startIndexValueTooLarge = "Start index value too large"
488+
lengthNegative = "Length cannot be negative"
488489
lengthTooLarge = "Length extends beyond the end of the string"
490+
lengthValueTooLarge = "Length value too large"
489491

490492
[functions.sub]
491493
description = "Subtracts the second number from the first"

dsc_lib/src/functions/substring.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ impl Function for Substring {
4343
));
4444
}
4545

46-
let start_index = start_index_value as usize;
46+
let start_index = usize::try_from(start_index_value).map_err(|_| {
47+
DscError::FunctionArg(
48+
"substring".to_string(),
49+
t!("functions.substring.startIndexValueTooLarge").to_string(),
50+
)
51+
})?;
4752
let string_length = string_to_parse.chars().count();
4853

4954
if start_index > string_length {
@@ -65,7 +70,12 @@ impl Function for Substring {
6570
));
6671
}
6772

68-
let length = length_value as usize;
73+
let length = usize::try_from(length_value).map_err(|_| {
74+
DscError::FunctionArg(
75+
"substring".to_string(),
76+
t!("functions.substring.lengthValueTooLarge").to_string(),
77+
)
78+
})?;
6979

7080
if start_index + length > string_length {
7181
return Err(DscError::FunctionArg(
@@ -220,3 +230,4 @@ mod tests {
220230
assert_eq!(result, Value::String("".to_string()));
221231
}
222232
}
233+

0 commit comments

Comments
 (0)