Skip to content

Commit daf432e

Browse files
committed
Use byte literals in libterm
1 parent 30cfce3 commit daf432e

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/libterm/terminfo/parm.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
301301
SetVar => {
302302
if cur >= 'A' && cur <= 'Z' {
303303
if stack.len() > 0 {
304-
let idx = (cur as u8) - ('A' as u8);
304+
let idx = (cur as u8) - b'A';
305305
vars.sta[idx as uint] = stack.pop().unwrap();
306306
} else { return Err("stack is empty".to_string()) }
307307
} else if cur >= 'a' && cur <= 'z' {
308308
if stack.len() > 0 {
309-
let idx = (cur as u8) - ('a' as u8);
309+
let idx = (cur as u8) - b'a';
310310
vars.dyn[idx as uint] = stack.pop().unwrap();
311311
} else { return Err("stack is empty".to_string()) }
312312
} else {
@@ -315,10 +315,10 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
315315
},
316316
GetVar => {
317317
if cur >= 'A' && cur <= 'Z' {
318-
let idx = (cur as u8) - ('A' as u8);
318+
let idx = (cur as u8) - b'A';
319319
stack.push(vars.sta[idx as uint].clone());
320320
} else if cur >= 'a' && cur <= 'z' {
321-
let idx = (cur as u8) - ('a' as u8);
321+
let idx = (cur as u8) - b'a';
322322
stack.push(vars.dyn[idx as uint].clone());
323323
} else {
324324
return Err("bad variable name in %g".to_string());
@@ -505,26 +505,25 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,String> {
505505
if flags.precision > s.len() {
506506
let mut s_ = Vec::with_capacity(flags.precision);
507507
let n = flags.precision - s.len();
508-
s_.grow(n, &('0' as u8));
508+
s_.grow(n, &b'0');
509509
s_.push_all_move(s);
510510
s = s_;
511511
}
512512
assert!(!s.is_empty(), "string conversion produced empty result");
513513
match op {
514514
FormatDigit => {
515-
if flags.space && !(s[0] == '-' as u8 ||
516-
s[0] == '+' as u8) {
517-
s.insert(0, ' ' as u8);
515+
if flags.space && !(s[0] == b'-' || s[0] == b'+' ) {
516+
s.insert(0, b' ');
518517
}
519518
}
520519
FormatOctal => {
521-
if flags.alternate && s[0] != '0' as u8 {
522-
s.insert(0, '0' as u8);
520+
if flags.alternate && s[0] != b'0' {
521+
s.insert(0, b'0');
523522
}
524523
}
525524
FormatHex => {
526525
if flags.alternate {
527-
let s_ = replace(&mut s, vec!('0' as u8, 'x' as u8));
526+
let s_ = replace(&mut s, vec!(b'0', b'x'));
528527
s.push_all_move(s_);
529528
}
530529
}
@@ -536,7 +535,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,String> {
536535
.move_iter()
537536
.collect();
538537
if flags.alternate {
539-
let s_ = replace(&mut s, vec!('0' as u8, 'X' as u8));
538+
let s_ = replace(&mut s, vec!(b'0', b'X'));
540539
s.push_all_move(s_);
541540
}
542541
}
@@ -563,10 +562,10 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,String> {
563562
if flags.width > s.len() {
564563
let n = flags.width - s.len();
565564
if flags.left {
566-
s.grow(n, &(' ' as u8));
565+
s.grow(n, &b' ');
567566
} else {
568567
let mut s_ = Vec::with_capacity(flags.width);
569-
s_.grow(n, &(' ' as u8));
568+
s_.grow(n, &b' ');
570569
s_.push_all_move(s);
571570
s = s_;
572571
}
@@ -655,15 +654,15 @@ mod test {
655654
let s = format!("%{{1}}%{{2}}%{}%d", op);
656655
let res = expand(s.as_bytes(), [], &mut Variables::new());
657656
assert!(res.is_ok(), res.unwrap_err());
658-
assert_eq!(res.unwrap(), vec!('0' as u8 + bs[0]));
657+
assert_eq!(res.unwrap(), vec!(b'0' + bs[0]));
659658
let s = format!("%{{1}}%{{1}}%{}%d", op);
660659
let res = expand(s.as_bytes(), [], &mut Variables::new());
661660
assert!(res.is_ok(), res.unwrap_err());
662-
assert_eq!(res.unwrap(), vec!('0' as u8 + bs[1]));
661+
assert_eq!(res.unwrap(), vec!(b'0' + bs[1]));
663662
let s = format!("%{{2}}%{{1}}%{}%d", op);
664663
let res = expand(s.as_bytes(), [], &mut Variables::new());
665664
assert!(res.is_ok(), res.unwrap_err());
666-
assert_eq!(res.unwrap(), vec!('0' as u8 + bs[2]));
665+
assert_eq!(res.unwrap(), vec!(b'0' + bs[2]));
667666
}
668667
}
669668

0 commit comments

Comments
 (0)