about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2013-08-04 16:09:04 -0400
committerSteven Fackler <sfackler@gmail.com>2013-08-06 09:58:36 -0700
commit463e2416e98238e294d332397048b106d85fd474 (patch)
tree141436fb8ec892cf753ec7611308d439d06b84bf
parent2266df51aa07eabd2f7745d410d3ddc4572ade21 (diff)
downloadrust-463e2416e98238e294d332397048b106d85fd474.tar.gz
rust-463e2416e98238e294d332397048b106d85fd474.zip
Some minor hex changes
-rw-r--r--src/libextra/hex.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libextra/hex.rs b/src/libextra/hex.rs
index 7a1417e72d8..5609c566d92 100644
--- a/src/libextra/hex.rs
+++ b/src/libextra/hex.rs
@@ -57,7 +57,7 @@ impl<'self> ToHex for &'self str {
      * # Example
      *
      * ~~~ {.rust}
-         * extern mod extra;
+     * extern mod extra;
      * use extra::ToHex;
      *
      * fn main () {
@@ -74,8 +74,8 @@ impl<'self> ToHex for &'self str {
 
 /// A trait for converting hexadecimal encoded values
 pub trait FromHex {
-    /// Converts the value of `self`, interpreted as base64 encoded data, into
-    /// an owned vector of bytes, returning the vector.
+    /// Converts the value of `self`, interpreted as hexadecimal encoded data,
+    /// into an owned vector of bytes, returning the vector.
     fn from_hex(&self) -> Result<~[u8], ~str>;
 }
 
@@ -83,6 +83,7 @@ impl<'self> FromHex for &'self [u8] {
     /**
      * Convert hexadecimal `u8` vector into u8 byte values.
      * Every 2 encoded characters is converted into 1 octet.
+     * Whitespace is ignored.
      *
      * # Example
      *
@@ -104,18 +105,19 @@ impl<'self> FromHex for &'self [u8] {
         let mut modulus = 0;
         let mut buf = 0u8;
 
-        for &byte in self.iter() {
+        for (idx, &byte) in self.iter().enumerate() {
             buf <<= 4;
 
             match byte as char {
                 'A'..'F' => buf |= byte - ('A' as u8) + 10,
                 'a'..'f' => buf |= byte - ('a' as u8) + 10,
                 '0'..'9' => buf |= byte - ('0' as u8),
-                ' '|'\r'|'\n' => {
+                ' '|'\r'|'\n'|'\t' => {
                     buf >>= 4;
                     loop
                 }
-                _ => return Err(~"Invalid hex char")
+                _ => return Err(fmt!("Invalid byte '%c' found at position %u",
+                                     byte as char, idx))
             }
 
             modulus += 1;