Skip to content
Snippets Groups Projects
Commit acfe885f authored by Jan Trávníček's avatar Jan Trávníček
Browse files

std: avoid need for casting in hexavigesimal

plus use constexpr to define the compile time constant
parent 21c8de30
No related branches found
No related tags found
1 merge request!179C casts to C++ casts redesign
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
namespace ext { namespace ext {
   
namespace { namespace {
static const int BASE26 = 26; static constexpr int BASE26 = 26;
} }
   
unsigned fromBase26( const std::string & rep ) { unsigned fromBase26( const std::string & rep ) {
...@@ -22,8 +22,8 @@ unsigned fromBase26( const std::string & rep ) { ...@@ -22,8 +22,8 @@ unsigned fromBase26( const std::string & rep ) {
std::string toBase26( unsigned n ) { std::string toBase26( unsigned n ) {
std::string name; std::string name;
do { do {
name += ( char )( n % BASE26 + 'A' ); name.push_back ( n % BASE26 + 'A' );
n = n / BASE26; n /= BASE26;
} while (n > 0); } while (n > 0);
   
return std::string( name.rbegin( ), name.rend( ) ); return std::string( name.rbegin( ), name.rend( ) );
...@@ -44,7 +44,7 @@ std::string bijectiveToBase26(unsigned n) { ...@@ -44,7 +44,7 @@ std::string bijectiveToBase26(unsigned n) {
std::string name; std::string name;
while(n > 0) { while(n > 0) {
--n; --n;
name += (char) (n % BASE26 + 'A'); name.push_back ( n % BASE26 + 'A' );
n /= BASE26; n /= BASE26;
} }
return std::string(name.rbegin(), name.rend()); return std::string(name.rbegin(), name.rend());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment