From a404e542614c0848931544eb0281fd546a62a971 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 9 Nov 2010 17:49:20 -0800 Subject: Teach rustc about const tag value, begin work on trans_copy_ty, make uint's to_str routine less clever and thereby resist overflow. --- src/lib/_uint.rs | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'src/lib') diff --git a/src/lib/_uint.rs b/src/lib/_uint.rs index 0930cadc..7fa4ea02 100644 --- a/src/lib/_uint.rs +++ b/src/lib/_uint.rs @@ -59,30 +59,20 @@ fn to_str(mutable uint n, uint radix) -> str if (n == 0u) { ret "0"; } - let uint r = 1u; - if (n > r) { - while ((r*radix) <= n) { - r *= radix; - } - } - let str s = ""; - while (n > 0u) { - - auto i = n/r; - - n -= (i * r); - r /= radix; - - s += digit(i) as u8; + while (n != 0u) { + s += digit(n % radix) as u8; + n /= radix; } - while (r > 0u) { - s += '0' as u8; - r /= radix; + let str s1 = ""; + let uint len = _str.byte_len(s); + while (len != 0u) { + len -= 1u; + s1 += s.(len); } + ret s1; - ret s; } // Local Variables: -- cgit v1.2.3