Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Oct 21, 2024
1 parent bbda370 commit 625f420
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
48 changes: 27 additions & 21 deletions src/elements/subword/braced_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,7 @@ impl Subword for BracedParam {
}

if self.has_offset {
match self.offset.clone() {
None => {
eprintln!("sush: {}: bad substitution", &self.text);
return false;
},
Some(mut offset) => {
if offset.text == "" {
eprintln!("sush: {}: bad substitution", &self.text);
return false;
}
match offset.eval(core) {
None => return false,
Some(s) => match s.parse::<usize>() {
Ok(n) => {
self.text = self.text.chars().enumerate().filter(|(i, _)| i >= &n).map(|(_, c)| c).collect();
},
_ => return false,
}
}
},
}
return self.offset(core);
}

match self.alternative_symbol.as_deref() {
Expand Down Expand Up @@ -138,6 +118,32 @@ impl BracedParam {
}
}

fn offset(&mut self, core: &mut ShellCore) -> bool {
let mut offset = match self.offset.clone() {
None => {
eprintln!("sush: {}: bad substitution", &self.text);
return false;
},
Some(ofs) => ofs,
};

if offset.text == "" {
eprintln!("sush: {}: bad substitution", &self.text);
return false;
}

match offset.eval(core) {
None => return false,
Some(s) => match s.parse::<usize>() {
Ok(n) => {
self.text = self.text.chars().enumerate().filter(|(i, _)| i >= &n).map(|(_, c)| c).collect();
},
_ => return false,
}
}
true
}

fn replace_to_alternative(&mut self, core: &mut ShellCore) -> bool {
let symbol = match self.alternative_symbol.as_ref() {
Some(s) => s,
Expand Down
1 change: 0 additions & 1 deletion test/ok
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
./test_compound.bash
./test_others.bash
./test_job.bash
../../../test/test_others.bash
3 changes: 3 additions & 0 deletions test/test_others.bash
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ res=$($com <<< 'A=あいうえお; echo ${A:}' )
[ "$?" = 1 ] || err $LINENO
[ "$res" = "" ] || err $LINENO

res=$($com <<< 'A=あ; echo ${A: }' )
[ "$res" = "" ] || err $LINENO

res=$($com <<< 'A=あいうえお; echo ${A:6}' )
[ "$res" = "" ] || err $LINENO

Expand Down

0 comments on commit 625f420

Please sign in to comment.