From: David Wells Date: Wed, 7 Jan 2015 19:53:50 +0000 (-0500) Subject: Fixed an issue with Utilities::int_to_string. X-Git-Tag: v8.3.0-rc1~565^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9aa8d4f08080ee0afd4c830797b6f7ca7aa37e00;p=dealii.git Fixed an issue with Utilities::int_to_string. It cannot handle more than ten digits in its current form, so I wrote a simple wrapper around boost::lexical_cast. --- diff --git a/source/base/utilities.cc b/source/base/utilities.cc index 5e26979285..083c8df117 100644 --- a/source/base/utilities.cc +++ b/source/base/utilities.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -70,55 +71,18 @@ namespace Utilities << " to the desired type"); std::string - int_to_string (const unsigned int i, - const unsigned int digits) + int_to_string (const unsigned int value, const unsigned int digits) { - // if second argument is invalid, then do - // not pad the resulting string at all + std::string lc_string = boost::lexical_cast(value); + if (digits == numbers::invalid_unsigned_int) - return int_to_string (i, needed_digits(i)); - - - AssertThrow ( ! ((digits==1 && i>=10) || - (digits==2 && i>=100) || - (digits==3 && i>=1000) || - (digits==4 && i>=10000)|| - (digits==5 && i>=100000)|| - (digits==6 && i>=1000000)|| - (digits==7 && i>=10000000)|| - (digits==8 && i>=100000000)|| - (digits==9 && i>=1000000000)|| - (i>=1000000000)), - ExcInvalidNumber2StringConversersion(i, digits)); - - std::string s; - switch (digits) + return lc_string; + else if (lc_string.size() < digits) { - case 10: - s += '0' + i/1000000000; - case 9: - s += '0' + i/100000000; - case 8: - s += '0' + i/10000000; - case 7: - s += '0' + i/1000000; - case 6: - s += '0' + i/100000; - case 5: - s += '0' + (i%100000)/10000; - case 4: - s += '0' + (i%10000)/1000; - case 3: - s += '0' + (i%1000)/100; - case 2: - s += '0' + (i%100)/10; - case 1: - s += '0' + i%10; - break; - default: - s += "invalid digits information"; - }; - return s; + std::string padding(digits - lc_string.size(), '0'); + lc_string.insert(0, padding); + } + return lc_string; }