2008-03-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

* src/ParameterizedStringParser.cc (createLoop):
	Removed unused variable sstep.

	* src/AlphaNumberDecorator.h (decode): Rewritten.
pull/1/head
Tatsuhiro Tsujikawa 2008-03-09 15:19:35 +00:00
parent 68b84574ae
commit 3349c7625c
3 changed files with 24 additions and 13 deletions

View File

@ -1,3 +1,10 @@
2008-03-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/ParameterizedStringParser.cc (createLoop):
Removed unused variable sstep.
* src/AlphaNumberDecorator.h (decode): Rewritten.
2008-03-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2008-03-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/Util.{h, cc} * src/Util.{h, cc}

View File

@ -46,37 +46,42 @@ private:
size_t _width; size_t _width;
std::string _zero; char _zero;
std::string widen(const std::string& s, size_t width) std::string widen(const std::string& s, size_t width)
{ {
std::string t = s; std::string t = s;
std::string zero(1, _zero);
while(t.size() < width) { while(t.size() < width) {
t.insert(0, _zero); t.insert(0, zero);
} }
return t; return t;
} }
public: public:
AlphaNumberDecorator(size_t width, bool uppercase = false): AlphaNumberDecorator(size_t width, bool uppercase = false):
_width(width), _zero(uppercase?"A":"a") {} _width(width), _zero(uppercase?'A':'a') {}
virtual ~AlphaNumberDecorator() {} virtual ~AlphaNumberDecorator() {}
virtual std::string decorate(unsigned int number) virtual std::string decorate(unsigned int number)
{ {
if(number == 0) { if(number == 0) {
return widen(_zero, _width); return widen(std::string(1, _zero), _width);
} }
int base = 26; int base = 26;
std::string x; char u[14]; // because if unsigned int is 64bit, which is the biggest integer for the time being and number is UINT64_MAX, you get "HLHXCZMXSYUMQP"
while(number > 0) { size_t index = 0;
int r = number%base; do {
char alpha = _zero[0]+r; unsigned int quot = number/base;
x.insert(0, std::string(1, alpha)); unsigned int rem = number%base;
number /= base; u[index++] = _zero+rem;
} number = quot;
return widen(x, _width); } while(number);
std::reverse(&u[0], &u[index]);
return widen(std::string(&u[0], &u[index]), _width);
} }
}; };

View File

@ -113,7 +113,6 @@ PStringDatumHandle ParameterizedStringParser::createLoop(const std::string& src,
std::string::size_type colonIndex = loopStr.find(":"); std::string::size_type colonIndex = loopStr.find(":");
if(colonIndex != std::string::npos) { if(colonIndex != std::string::npos) {
std::string stepStr = loopStr.substr(colonIndex+1); std::string stepStr = loopStr.substr(colonIndex+1);
int sstep;
if(Util::isNumber(stepStr)) { if(Util::isNumber(stepStr)) {
step = Util::parseUInt(stepStr); step = Util::parseUInt(stepStr);
} else { } else {