about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorBrian Anderson <andersrb@gmail.com>2011-04-13 21:36:32 -0400
committerBrian Anderson <andersrb@gmail.com>2011-04-13 22:14:54 -0400
commit99a697b56abba8e4ab94fc14b5b4769bee9702f0 (patch)
treeae9b3e81e9fbfe294974a0034a35b57b96babf27 /src/lib
parent5c0f4c1939b392e0bd0bcbce86fa83eb7a421992 (diff)
Add support for upper-case hex and binary output to #fmt.
Only works for uints at present. Necessitated the addition of _str.to_upper.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ExtFmt.rs6
-rw-r--r--src/lib/_str.rs18
2 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/ExtFmt.rs b/src/lib/ExtFmt.rs
index da32568af52..e15fa462684 100644
--- a/src/lib/ExtFmt.rs
+++ b/src/lib/ExtFmt.rs
@@ -315,6 +315,12 @@ mod RT {
             case (ty_hex_lower) {
                 ret _uint.to_str(u, 16u);
             }
+            case (ty_hex_upper) {
+                ret _str.to_upper(_uint.to_str(u, 16u));
+            }
+            case (ty_bits) {
+                ret _uint.to_str(u, 2u);
+            }
         }
     }
 
diff --git a/src/lib/_str.rs b/src/lib/_str.rs
index 31d0790d22d..7690fe44a50 100644
--- a/src/lib/_str.rs
+++ b/src/lib/_str.rs
@@ -470,6 +470,24 @@ fn connect(vec[str] v, str sep) -> str {
     ret s;
 }
 
+// FIXME: This only handles ASCII
+fn to_upper(str s) -> str {
+    auto outstr = "";
+    auto ascii_a = 'a' as u8;
+    auto ascii_z = 'z' as u8;
+    auto diff = 32u8;
+    for (u8 byte in s) {
+        auto next;
+        if (ascii_a <= byte && byte <= ascii_z) {
+            next = byte - diff;
+        } else {
+            next = byte;
+        }
+        push_byte(outstr, next);
+    }
+    ret outstr;
+}
+
 
 // Local Variables:
 // mode: rust;