digitalmars.D.learn - Trying to add automatic radix detection in std.conv.parse
- klb (36/36) Jul 25 2014 hello, I'd like to test if it's possible to add an automatic
hello, I'd like to test if it's possible to add an automatic radix detection in std.conv, parse. I've added... ------------------------ if (s.length >= 2) { if (s[0..2] == "0x" || s[0..2] == "0X") { uint radix = 16; Source nbr = s[2..$]; return .parse!Target(nbr, radix); } else if (s[0..2] == "0b" || s[0..2] == "0B") { uint radix = 2; Source nbr = s[2..$]; return .parse!Target(nbr, radix); } } ------------------------ ...to the first parse version. The (maybe `naive`) idea is to redirect to the right parse version if the prefixes are found. But it seems to break the purity of format() because I get , when compiling phobos, the following errors: ------------------------ std\utf.d(71): Error: pure function 'std.utf.UTFException.this' cannot call impure function 'std.str ing.format!(char, uint).format' std\utf.d(71): Error: safe function 'std.utf.UTFException.this' cannot call system function 'std.str ing.format!(char, uint).format' std\uuid.d(1536): Error: pure function 'std.uuid.UUIDParsingException.this' cannot call impure funct ion 'std.string.format!(char, string, string, uint).format' ------------------------ What's wrong ?
Jul 25 2014