Skip to content

Commit

Permalink
chore: code review feedback.
Browse files Browse the repository at this point in the history
Remove unnecessary `trim_end_matches` calls.
  • Loading branch information
peterhuene committed Nov 19, 2024
1 parent f4e86bb commit d2eac6f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 23 deletions.
14 changes: 7 additions & 7 deletions wdl-engine/src/stdlib/read_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ fn read_lines(context: CallContext<'_>) -> Result<Value, Diagnostic> {
let elements = BufReader::new(file)
.lines()
.map(|line| {
let mut line = line
.with_context(|| format!("failed to read file `{path}`", path = path.display()))
Ok(PrimitiveValue::new_string(
line.with_context(|| {
format!("failed to read file `{path}`", path = path.display())
})
.map_err(|e| {
function_call_failed("read_lines", format!("{e:?}"), context.call_site)
})?;

let trimmed = line.trim_end_matches(['\r', '\n']);
line.truncate(trimmed.len());
Ok(PrimitiveValue::new_string(line).into())
})?,
)
.into())
})
.collect::<Result<Vec<Value>, _>>()?;

Expand Down
2 changes: 1 addition & 1 deletion wdl-engine/src/stdlib/read_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn read_map(context: CallContext<'_>) -> Result<Value, Diagnostic> {
.with_context(|| format!("failed to read file `{path}`", path = path.display()))
.map_err(|e| function_call_failed("read_map", format!("{e:?}"), context.call_site))?;

let (key, value) = match line.trim_end_matches(['\r', '\n']).split_once('\t') {
let (key, value) = match line.split_once('\t') {
Some((key, value)) if !value.contains('\t') => (key, value),
_ => {
return Err(function_call_failed(
Expand Down
6 changes: 1 addition & 5 deletions wdl-engine/src/stdlib/read_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ fn read_object(context: CallContext<'_>) -> Result<Value, Diagnostic> {
}

let mut members = IndexMap::new();
for e in names
.trim_end_matches(['\r', '\n'])
.split('\t')
.zip_longest(values.trim_end_matches(['\r', '\n']).split('\t'))
{
for e in names.split('\t').zip_longest(values.split('\t')) {
match e {
EitherOrBoth::Both(name, value) => {
if !is_ident(name) {
Expand Down
6 changes: 1 addition & 5 deletions wdl-engine/src/stdlib/read_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ fn read_objects(context: CallContext<'_>) -> Result<Value, Diagnostic> {
}
};

let names = names.trim_end_matches(['\r', '\n']);
for name in names.split('\t') {
if !is_ident(name) {
return Err(function_call_failed(
Expand All @@ -96,10 +95,7 @@ fn read_objects(context: CallContext<'_>) -> Result<Value, Diagnostic> {
})?;

let mut members = IndexMap::new();
for e in names
.split('\t')
.zip_longest(line.trim_end_matches(['\r', '\n']).split('\t'))
{
for e in names.split('\t').zip_longest(line.split('\t')) {
match e {
EitherOrBoth::Both(name, value) => {
if members
Expand Down
6 changes: 1 addition & 5 deletions wdl-engine/src/stdlib/read_tsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ fn read_tsv_simple(context: CallContext<'_>) -> Result<Value, Diagnostic> {
.with_context(|| format!("failed to read file `{path}`", path = path.display()))
.map_err(|e| function_call_failed("read_tsv", format!("{e:?}"), context.call_site))?;
let values = line
.trim_end_matches(['\r', '\n'])
.split('\t')
.map(|s| PrimitiveValue::new_string(s).into())
.collect::<Vec<Value>>();
Expand Down Expand Up @@ -190,10 +189,7 @@ fn read_tsv(context: CallContext<'_>) -> Result<Value, Diagnostic> {

let mut members: IndexMap<String, Value> = IndexMap::with_capacity(column_count);

for e in header
.columns()
.zip_longest(line.trim_end_matches(['\r', '\n']).split('\t'))
{
for e in header.columns().zip_longest(line.split('\t')) {
match e {
EitherOrBoth::Both(c, v) => {
if members
Expand Down

0 comments on commit d2eac6f

Please sign in to comment.