// ASE base library // Copyright (C) 2001-2012 David Capello // // This source file is ditributed under a BSD-like license, please // read LICENSE.txt for more information. #include "config.h" #include "base/convert_to.h" #include "base/sha1.h" #include "base/version.h" #include #include namespace base { template<> int convert_to(const string& from) { return std::strtol(from.c_str(), NULL, 10); } template<> string convert_to(const int& from) { char buf[32]; std::sprintf(buf, "%d", from); return buf; } template<> Sha1 convert_to(const string& from) { std::vector digest(Sha1::HashSize); for (size_t i=0; i= from.size()) break; digest[i] = convert_to(from.substr(i*2, 2)); } return Sha1(digest); } template<> string convert_to(const Sha1& from) { char buf[3]; string res; res.reserve(2*Sha1::HashSize); for(int c=0; c Version convert_to(const string& from) { Version result; int i = 0; int j = 0; while (j != string::npos) { j = from.find('.', i); string digitString = from.substr(i, j - i); int digit = convert_to(digitString); result.addDigit(digit); i = j+1; } return result; } template<> string convert_to(const Version& from) { string result; result.reserve(3*from.size()); for (size_t i=0; i(from[i]); if (i < from.size()-1) result += "."; } return result; } } // namespace base