summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-03-09 15:19:35 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-03-09 15:19:35 +0000
commit3349c7625c3bbd99ea5c46b0b08074c1ce62f52c (patch)
tree5e5c008a5891bb2d347e4f8a246dcb7839e3d779 /src
parent68b84574ae5f3a46b0157799783cf51b1a8f4676 (diff)
2008-03-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/ParameterizedStringParser.cc (createLoop): Removed unused variable sstep. * src/AlphaNumberDecorator.h (decode): Rewritten.
Diffstat (limited to 'src')
-rw-r--r--src/AlphaNumberDecorator.h29
-rw-r--r--src/ParameterizedStringParser.cc1
2 files changed, 17 insertions, 13 deletions
diff --git a/src/AlphaNumberDecorator.h b/src/AlphaNumberDecorator.h
index a533b9bc..4e9c04a8 100644
--- a/src/AlphaNumberDecorator.h
+++ b/src/AlphaNumberDecorator.h
@@ -46,37 +46,42 @@ private:
size_t _width;
- std::string _zero;
+ char _zero;
std::string widen(const std::string& s, size_t width)
{
std::string t = s;
+ std::string zero(1, _zero);
while(t.size() < width) {
- t.insert(0, _zero);
+ t.insert(0, zero);
}
return t;
}
public:
AlphaNumberDecorator(size_t width, bool uppercase = false):
- _width(width), _zero(uppercase?"A":"a") {}
+ _width(width), _zero(uppercase?'A':'a') {}
virtual ~AlphaNumberDecorator() {}
virtual std::string decorate(unsigned int number)
{
if(number == 0) {
- return widen(_zero, _width);
+ return widen(std::string(1, _zero), _width);
}
+
int base = 26;
- std::string x;
- while(number > 0) {
- int r = number%base;
- char alpha = _zero[0]+r;
- x.insert(0, std::string(1, alpha));
- number /= base;
- }
- return widen(x, _width);
+ 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"
+ size_t index = 0;
+ do {
+ unsigned int quot = number/base;
+ unsigned int rem = number%base;
+ u[index++] = _zero+rem;
+ number = quot;
+ } while(number);
+ std::reverse(&u[0], &u[index]);
+
+ return widen(std::string(&u[0], &u[index]), _width);
}
};
diff --git a/src/ParameterizedStringParser.cc b/src/ParameterizedStringParser.cc
index d203383e..902d64ba 100644
--- a/src/ParameterizedStringParser.cc
+++ b/src/ParameterizedStringParser.cc
@@ -113,7 +113,6 @@ PStringDatumHandle ParameterizedStringParser::createLoop(const std::string& src,
std::string::size_type colonIndex = loopStr.find(":");
if(colonIndex != std::string::npos) {
std::string stepStr = loopStr.substr(colonIndex+1);
- int sstep;
if(Util::isNumber(stepStr)) {
step = Util::parseUInt(stepStr);
} else {