about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authornham <hamann.nick@gmail.com>2014-08-06 02:02:50 -0400
committernham <hamann.nick@gmail.com>2014-08-06 02:02:50 -0400
commit3fb78e29f4ae9b3e5bb19bf5a740375e90b01ceb (patch)
treeb4dcb4ce0e5f25a5f92c5a99f44d6ade5243144a /src/libstd
parentdfdea3f116ea028b347ca5b73dc462a6d48d9940 (diff)
downloadrust-3fb78e29f4ae9b3e5bb19bf5a740375e90b01ceb.tar.gz
rust-3fb78e29f4ae9b3e5bb19bf5a740375e90b01ceb.zip
Use byte literals in libstd
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/ascii.rs12
-rw-r--r--src/libstd/dynamic_lib.rs2
-rw-r--r--src/libstd/io/buffered.rs14
-rw-r--r--src/libstd/io/fs.rs4
-rw-r--r--src/libstd/io/mod.rs4
-rw-r--r--src/libstd/io/net/ip.rs12
-rw-r--r--src/libstd/io/stdio.rs2
-rw-r--r--src/libstd/macros.rs2
-rw-r--r--src/libstd/num/strconv.rs36
-rw-r--r--src/libstd/os.rs2
-rw-r--r--src/libstd/path/mod.rs6
-rw-r--r--src/libstd/path/posix.rs2
-rw-r--r--src/libstd/path/windows.rs8
13 files changed, 52 insertions, 54 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs
index 7731cd12ec2..e8352dcd40c 100644
--- a/src/libstd/ascii.rs
+++ b/src/libstd/ascii.rs
@@ -119,7 +119,7 @@ impl Ascii {
     /// Check if the character is a space or horizontal tab
     #[inline]
     pub fn is_blank(&self) -> bool {
-        self.chr == ' ' as u8 || self.chr == '\t' as u8
+        self.chr == b' ' || self.chr == b'\t'
     }
 
     /// Check if the character is a control character
@@ -150,7 +150,7 @@ impl Ascii {
     /// Checks if the character is lowercase
     #[inline]
     pub fn is_lowercase(&self) -> bool {
-        (self.chr - 'a' as u8) < 26
+        (self.chr - b'a') < 26
     }
 
     #[inline]
@@ -163,7 +163,7 @@ impl Ascii {
     /// Checks if the character is uppercase
     #[inline]
     pub fn is_uppercase(&self) -> bool {
-        (self.chr - 'A' as u8) < 26
+        (self.chr - b'A') < 26
     }
 
     /// Checks if the character is punctuation
@@ -175,7 +175,7 @@ impl Ascii {
     /// Checks if the character is a valid hex digit
     #[inline]
     pub fn is_hex(&self) -> bool {
-        self.is_digit() || ((self.chr | 32u8) - 'a' as u8) < 6
+        self.is_digit() || ((self.chr | 32u8) - b'a') < 6
     }
 }
 
@@ -792,13 +792,13 @@ mod tests {
 
     #[test]
     fn test_to_string() {
-        let s = Ascii{ chr: 't' as u8 }.to_string();
+        let s = Ascii{ chr: b't' }.to_string();
         assert_eq!(s, "t".to_string());
     }
 
     #[test]
     fn test_show() {
-        let c = Ascii { chr: 't' as u8 };
+        let c = Ascii { chr: b't' };
         assert_eq!(format!("{}", c), "t".to_string());
     }
 }
diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs
index 2c4e0ea6701..1ac37458e24 100644
--- a/src/libstd/dynamic_lib.rs
+++ b/src/libstd/dynamic_lib.rs
@@ -114,7 +114,7 @@ impl DynamicLibrary {
     }
 
     fn separator() -> u8 {
-        if cfg!(windows) {';' as u8} else {':' as u8}
+        if cfg!(windows) {b';'} else {b':'}
     }
 
     /// Returns the current search path for dynamic libraries being used by this
diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs
index e25006a7b39..71ec5242118 100644
--- a/src/libstd/io/buffered.rs
+++ b/src/libstd/io/buffered.rs
@@ -248,7 +248,7 @@ impl<W: Writer> LineBufferedWriter<W> {
 
 impl<W: Writer> Writer for LineBufferedWriter<W> {
     fn write(&mut self, buf: &[u8]) -> IoResult<()> {
-        match buf.iter().rposition(|&b| b == '\n' as u8) {
+        match buf.iter().rposition(|&b| b == b'\n') {
             Some(i) => {
                 try!(self.inner.write(buf.slice_to(i + 1)));
                 try!(self.inner.flush());
@@ -524,15 +524,15 @@ mod test {
         assert_eq!(writer.get_ref().get_ref(), &[]);
         writer.flush().unwrap();
         assert_eq!(writer.get_ref().get_ref(), &[0, 1]);
-        writer.write([0, '\n' as u8, 1, '\n' as u8, 2]).unwrap();
+        writer.write([0, b'\n', 1, b'\n', 2]).unwrap();
         assert_eq!(writer.get_ref().get_ref(),
-                   &[0, 1, 0, '\n' as u8, 1, '\n' as u8]);
+                   &[0, 1, 0, b'\n', 1, b'\n']);
         writer.flush().unwrap();
         assert_eq!(writer.get_ref().get_ref(),
-                   &[0, 1, 0, '\n' as u8, 1, '\n' as u8, 2]);
-        writer.write([3, '\n' as u8]).unwrap();
+                   &[0, 1, 0, b'\n', 1, b'\n', 2]);
+        writer.write([3, b'\n']).unwrap();
         assert_eq!(writer.get_ref().get_ref(),
-            &[0, 1, 0, '\n' as u8, 1, '\n' as u8, 2, 3, '\n' as u8]);
+            &[0, 1, 0, b'\n', 1, b'\n', 2, 3, b'\n']);
     }
 
     #[test]
@@ -579,7 +579,7 @@ mod test {
 
     #[test]
     fn test_chars() {
-        let buf = [195u8, 159u8, 'a' as u8];
+        let buf = [195u8, 159u8, b'a'];
         let mut reader = BufferedReader::with_capacity(1, BufReader::new(buf));
         let mut it = reader.chars();
         assert_eq!(it.next(), Some(Ok('ß')));
diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs
index 246ff901f5c..6a4172d5c35 100644
--- a/src/libstd/io/fs.rs
+++ b/src/libstd/io/fs.rs
@@ -1241,8 +1241,8 @@ mod test {
         let mut cur = [0u8, .. 2];
         for f in files {
             let stem = f.filestem_str().unwrap();
-            let root = stem.as_bytes()[0] - ('0' as u8);
-            let name = stem.as_bytes()[1] - ('0' as u8);
+            let root = stem.as_bytes()[0] - b'0';
+            let name = stem.as_bytes()[1] - b'0';
             assert!(cur[root as uint] < name);
             cur[root as uint] = name;
         }
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index f1b92b973c8..d098f9a6479 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -1103,7 +1103,7 @@ pub trait Writer {
     /// that the `write` method is used specifically instead.
     #[inline]
     fn write_line(&mut self, s: &str) -> IoResult<()> {
-        self.write_str(s).and_then(|()| self.write(['\n' as u8]))
+        self.write_str(s).and_then(|()| self.write([b'\n']))
     }
 
     /// Write a single char, encoded as UTF-8.
@@ -1442,7 +1442,7 @@ pub trait Buffer: Reader {
     /// Additionally, this function can fail if the line of input read is not a
     /// valid UTF-8 sequence of bytes.
     fn read_line(&mut self) -> IoResult<String> {
-        self.read_until('\n' as u8).and_then(|line|
+        self.read_until(b'\n').and_then(|line|
             match String::from_utf8(line) {
                 Ok(s)  => Ok(s),
                 Err(_) => Err(standard_error(InvalidInput)),
diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs
index 79caded6711..0f864c7be5e 100644
--- a/src/libstd/io/net/ip.rs
+++ b/src/libstd/io/net/ip.rs
@@ -161,12 +161,12 @@ impl<'a> Parser<'a> {
         fn parse_digit(c: char, radix: u8) -> Option<u8> {
             let c = c as u8;
             // assuming radix is either 10 or 16
-            if c >= '0' as u8 && c <= '9' as u8 {
-                Some(c - '0' as u8)
-            } else if radix > 10 && c >= 'a' as u8 && c < 'a' as u8 + (radix - 10) {
-                Some(c - 'a' as u8 + 10)
-            } else if radix > 10 && c >= 'A' as u8 && c < 'A' as u8 + (radix - 10) {
-                Some(c - 'A' as u8 + 10)
+            if c >= b'0' && c <= b'9' {
+                Some(c - b'0')
+            } else if radix > 10 && c >= b'a' && c < b'a' + (radix - 10) {
+                Some(c - b'a' + 10)
+            } else if radix > 10 && c >= b'A' && c < b'A' + (radix - 10) {
+                Some(c - b'A' + 10)
             } else {
                 None
             }
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs
index 45c084b3459..e0201b65071 100644
--- a/src/libstd/io/stdio.rs
+++ b/src/libstd/io/stdio.rs
@@ -239,7 +239,7 @@ pub fn print(s: &str) {
 /// `\n` character is printed to the console after the string.
 pub fn println(s: &str) {
     with_task_stdout(|io| {
-        io.write(s.as_bytes()).and_then(|()| io.write(['\n' as u8]))
+        io.write(s.as_bytes()).and_then(|()| io.write([b'\n']))
     })
 }
 
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index e67329df7ae..3184c151bd2 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -502,7 +502,7 @@ pub mod builtin {
     ///
     /// ```
     /// let rust = bytes!("r", 'u', "st", 255);
-    /// assert_eq!(rust[1], 'u' as u8);
+    /// assert_eq!(rust[1], b'u');
     /// assert_eq!(rust[4], 255);
     /// ```
     #[macro_export]
diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs
index c8528e752e8..37378518dc8 100644
--- a/src/libstd/num/strconv.rs
+++ b/src/libstd/num/strconv.rs
@@ -138,12 +138,10 @@ impl_NumStrConv_Integer!(u64)
 
 
 // Special value strings as [u8] consts.
-static INF_BUF:          [u8, ..3] = ['i' as u8, 'n' as u8, 'f' as u8];
-static POS_INF_BUF: [u8, ..4] = ['+' as u8, 'i' as u8, 'n' as u8,
-                                      'f' as u8];
-static NEG_INF_BUF: [u8, ..4] = ['-' as u8, 'i' as u8, 'n' as u8,
-                                      'f' as u8];
-static NAN_BUF:          [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8];
+static INF_BUF:     [u8, ..3] = [b'i', b'n', b'f'];
+static POS_INF_BUF: [u8, ..4] = [b'+', b'i', b'n', b'f'];
+static NEG_INF_BUF: [u8, ..4] = [b'-', b'i', b'n', b'f'];
+static NAN_BUF:     [u8, ..3] = [b'N', b'a', b'N'];
 
 /**
  * Converts an integral number to its string representation as a byte vector.
@@ -201,8 +199,8 @@ pub fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f:
             current_digit_signed
         };
         buf[cur] = match current_digit.to_u8().unwrap() {
-            i @ 0..9 => '0' as u8 + i,
-            i        => 'a' as u8 + (i - 10),
+            i @ 0..9 => b'0' + i,
+            i        => b'a' + (i - 10),
         };
         cur += 1;
 
@@ -213,8 +211,8 @@ pub fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f:
 
     // Decide what sign to put in front
     match sign {
-        SignNeg | SignAll if neg => { f('-' as u8); }
-        SignAll => { f('+' as u8); }
+        SignNeg | SignAll if neg => { f(b'-'); }
+        SignAll => { f(b'+'); }
         _ => ()
     }
 
@@ -350,10 +348,10 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+
     // Decide what sign to put in front
     match sign {
         SignNeg | SignAll if neg => {
-            buf.push('-' as u8);
+            buf.push(b'-');
         }
         SignAll => {
-            buf.push('+' as u8);
+            buf.push(b'+');
         }
         _ => ()
     }
@@ -368,7 +366,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+
     // Now emit the fractional part, if any
     deccum = num.fract();
     if deccum != _0 || (limit_digits && exact && digit_count > 0) {
-        buf.push('.' as u8);
+        buf.push(b'.');
         let mut dig = 0u;
 
         // calculate new digits while
@@ -415,14 +413,14 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+
                     // If reached left end of number, have to
                     // insert additional digit:
                     if i < 0
-                    || *buf.get(i as uint) == '-' as u8
-                    || *buf.get(i as uint) == '+' as u8 {
+                    || *buf.get(i as uint) == b'-'
+                    || *buf.get(i as uint) == b'+' {
                         buf.insert((i + 1) as uint, value2ascii(1));
                         break;
                     }
 
                     // Skip the '.'
-                    if *buf.get(i as uint) == '.' as u8 { i -= 1; continue; }
+                    if *buf.get(i as uint) == b'.' { i -= 1; continue; }
 
                     // Either increment the digit,
                     // or set to 0 if max and carry the 1.
@@ -448,14 +446,14 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+
         let mut i = buf_max_i;
 
         // discover trailing zeros of fractional part
-        while i > start_fractional_digits && *buf.get(i) == '0' as u8 {
+        while i > start_fractional_digits && *buf.get(i) == b'0' {
             i -= 1;
         }
 
         // Only attempt to truncate digits if buf has fractional digits
         if i >= start_fractional_digits {
             // If buf ends with '.', cut that too.
-            if *buf.get(i) == '.' as u8 { i -= 1 }
+            if *buf.get(i) == b'.' { i -= 1 }
 
             // only resize buf if we actually remove digits
             if i < buf_max_i {
@@ -465,7 +463,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+
     } // If exact and trailing '.', just cut that
     else {
         let max_i = buf.len() - 1;
-        if *buf.get(max_i) == '.' as u8 {
+        if *buf.get(max_i) == b'.' {
             buf = Vec::from_slice(buf.slice(0, max_i));
         }
     }
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index dfa691d1823..a28d2ba9d5c 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -293,7 +293,7 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> {
         fn env_convert(input: Vec<Vec<u8>>) -> Vec<(Vec<u8>, Vec<u8>)> {
             let mut pairs = Vec::new();
             for p in input.iter() {
-                let mut it = p.as_slice().splitn(1, |b| *b == '=' as u8);
+                let mut it = p.as_slice().splitn(1, |b| *b == b'=');
                 let key = Vec::from_slice(it.next().unwrap());
                 let val = Vec::from_slice(it.next().unwrap_or(&[]));
                 pairs.push((key, val));
diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs
index a22db7292fa..d290a5f8c63 100644
--- a/src/libstd/path/mod.rs
+++ b/src/libstd/path/mod.rs
@@ -351,7 +351,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
         match self.filename() {
             None => None,
             Some(name) => Some({
-                let dot = '.' as u8;
+                let dot = b'.';
                 match name.rposition_elem(&dot) {
                     None | Some(0) => name,
                     Some(1) if name == b".." => name,
@@ -398,7 +398,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
         match self.filename() {
             None => None,
             Some(name) => {
-                let dot = '.' as u8;
+                let dot = b'.';
                 match name.rposition_elem(&dot) {
                     None | Some(0) => None,
                     Some(1) if name == b".." => None,
@@ -474,7 +474,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
         assert!(!contains_nul(&extension));
 
         let val = self.filename().and_then(|name| {
-            let dot = '.' as u8;
+            let dot = b'.';
             let extlen = extension.container_as_bytes().len();
             match (name.rposition_elem(&dot), extlen) {
                 (None, 0) | (Some(0), 0) => None,
diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs
index 877ca2c7e01..9a4bc11f5c0 100644
--- a/src/libstd/path/posix.rs
+++ b/src/libstd/path/posix.rs
@@ -237,7 +237,7 @@ impl GenericPath for Path {
         match self.sepidx {
             None if b"." == self.repr.as_slice() => false,
             None => {
-                self.repr = vec!['.' as u8];
+                self.repr = vec![b'.'];
                 self.sepidx = None;
                 true
             }
diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs
index d9b802b38fd..c3a217bf940 100644
--- a/src/libstd/path/windows.rs
+++ b/src/libstd/path/windows.rs
@@ -737,12 +737,12 @@ impl Path {
             let mut comps = comps;
             match (comps.is_some(),prefix) {
                 (false, Some(DiskPrefix)) => {
-                    if s.as_bytes()[0] >= 'a' as u8 && s.as_bytes()[0] <= 'z' as u8 {
+                    if s.as_bytes()[0] >= b'a' && s.as_bytes()[0] <= b'z' {
                         comps = Some(vec![]);
                     }
                 }
                 (false, Some(VerbatimDiskPrefix)) => {
-                    if s.as_bytes()[4] >= 'a' as u8 && s.as_bytes()[0] <= 'z' as u8 {
+                    if s.as_bytes()[4] >= b'a' && s.as_bytes()[0] <= b'z' {
                         comps = Some(vec![]);
                     }
                 }
@@ -1010,7 +1010,7 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option<PathPrefix> {
             } else {
                 // \\?\path
                 let idx = path.find('\\');
-                if idx == Some(2) && path.as_bytes()[1] == ':' as u8 {
+                if idx == Some(2) && path.as_bytes()[1] == b':' {
                     let c = path.as_bytes()[0];
                     if c.is_ascii() && (c as char).is_alphabetic() {
                         // \\?\C:\ path
@@ -1033,7 +1033,7 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option<PathPrefix> {
             }
             _ => ()
         }
-    } else if path.len() > 1 && path.as_bytes()[1] == ':' as u8 {
+    } else if path.len() > 1 && path.as_bytes()[1] == b':' {
         // C:
         let c = path.as_bytes()[0];
         if c.is_ascii() && (c as char).is_alphabetic() {