mirror of https://github.com/aria2/aria2
Removed unused functions
parent
89f18dde85
commit
8fc5cdea02
64
src/util.cc
64
src/util.cc
|
@ -515,24 +515,6 @@ unsigned int hexCharToUInt(unsigned char ch)
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* openFile(const std::string& filename, const std::string& mode) {
|
|
||||||
FILE* file = fopen(filename.c_str(), mode.c_str());
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isPowerOf(int num, int base) {
|
|
||||||
if(base <= 0) { return false; }
|
|
||||||
if(base == 1) { return true; }
|
|
||||||
|
|
||||||
while(num%base == 0) {
|
|
||||||
num /= base;
|
|
||||||
if(num == 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string secfmt(time_t sec) {
|
std::string secfmt(time_t sec) {
|
||||||
time_t tsec = sec;
|
time_t tsec = sec;
|
||||||
std::string str;
|
std::string str;
|
||||||
|
@ -550,15 +532,6 @@ std::string secfmt(time_t sec) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNum(const char* buf, int offset, size_t length) {
|
|
||||||
char* temp = new char[length+1];
|
|
||||||
memcpy(temp, buf+offset, length);
|
|
||||||
temp[length] = '\0';
|
|
||||||
int x = strtol(temp, 0, 10);
|
|
||||||
delete [] temp;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template<typename T, typename F>
|
template<typename T, typename F>
|
||||||
bool parseLong(T& res, F f, const std::string& s, int base)
|
bool parseLong(T& res, F f, const std::string& s, int base)
|
||||||
|
@ -913,26 +886,15 @@ std::string getContentDispositionFilename(const std::string& header)
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string randomAlpha(size_t length, const RandomizerHandle& randomizer) {
|
|
||||||
static const char randomChars[] =
|
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
||||||
std::string str;
|
|
||||||
for(size_t i = 0; i < length; ++i) {
|
|
||||||
size_t index = randomizer->getRandomNumber(sizeof(randomChars)-1);
|
|
||||||
str += randomChars[index];
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string toUpper(const std::string& src) {
|
std::string toUpper(const std::string& src) {
|
||||||
std::string temp = src;
|
std::string temp = src;
|
||||||
std::transform(temp.begin(), temp.end(), temp.begin(), toUpperChar);
|
uppercase(temp);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string toLower(const std::string& src) {
|
std::string toLower(const std::string& src) {
|
||||||
std::string temp = src;
|
std::string temp = src;
|
||||||
std::transform(temp.begin(), temp.end(), temp.begin(), toLowerChar);
|
lowercase(temp);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1110,28 +1072,6 @@ void usleep(long microseconds) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int alphaToNum(const std::string& alphabets)
|
|
||||||
{
|
|
||||||
if(alphabets.empty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
char base;
|
|
||||||
if(islower(alphabets[0])) {
|
|
||||||
base = 'a';
|
|
||||||
} else {
|
|
||||||
base = 'A';
|
|
||||||
}
|
|
||||||
uint64_t num = 0;
|
|
||||||
for(size_t i = 0, eoi = alphabets.size(); i < eoi; ++i) {
|
|
||||||
unsigned int v = alphabets[i]-base;
|
|
||||||
num = num*26+v;
|
|
||||||
if(num > UINT32_MAX) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mkdirs(const std::string& dirpath)
|
void mkdirs(const std::string& dirpath)
|
||||||
{
|
{
|
||||||
File dir(dirpath);
|
File dir(dirpath);
|
||||||
|
|
16
src/util.h
16
src/util.h
|
@ -255,10 +255,6 @@ std::string fromHex(InputIterator first, InputIterator last)
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* openFile(const std::string& filename, const std::string& mode);
|
|
||||||
|
|
||||||
bool isPowerOf(int num, int base);
|
|
||||||
|
|
||||||
std::string secfmt(time_t sec);
|
std::string secfmt(time_t sec);
|
||||||
|
|
||||||
bool parseIntNoThrow(int32_t& res, const std::string& s, int base = 10);
|
bool parseIntNoThrow(int32_t& res, const std::string& s, int base = 10);
|
||||||
|
@ -293,9 +289,6 @@ std::string iso8859ToUtf8(const std::string& src);
|
||||||
|
|
||||||
std::string getContentDispositionFilename(const std::string& header);
|
std::string getContentDispositionFilename(const std::string& header);
|
||||||
|
|
||||||
std::string randomAlpha(size_t length,
|
|
||||||
const SharedHandle<Randomizer>& randomizer);
|
|
||||||
|
|
||||||
std::string toUpper(const std::string& src);
|
std::string toUpper(const std::string& src);
|
||||||
|
|
||||||
std::string toLower(const std::string& src);
|
std::string toLower(const std::string& src);
|
||||||
|
@ -395,15 +388,6 @@ bool isUppercase(InputIterator first, InputIterator last)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts alphabets to unsigned int, assuming alphabets as a base 26
|
|
||||||
* integer and 'a' or 'A' is 0.
|
|
||||||
* This function assumes alphabets includes only a-z.
|
|
||||||
* Upper case are allowed but all letters must be upper case.
|
|
||||||
* If overflow occurs, returns 0.
|
|
||||||
*/
|
|
||||||
unsigned int alphaToNum(const std::string& alphabets);
|
|
||||||
|
|
||||||
void mkdirs(const std::string& dirpath);
|
void mkdirs(const std::string& dirpath);
|
||||||
|
|
||||||
void convertBitfield(BitfieldMan* dest, const BitfieldMan* src);
|
void convertBitfield(BitfieldMan* dest, const BitfieldMan* src);
|
||||||
|
|
|
@ -40,7 +40,6 @@ class UtilTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testIstartsWith);
|
CPPUNIT_TEST(testIstartsWith);
|
||||||
// may be moved to other helper class in the future.
|
// may be moved to other helper class in the future.
|
||||||
CPPUNIT_TEST(testGetContentDispositionFilename);
|
CPPUNIT_TEST(testGetContentDispositionFilename);
|
||||||
CPPUNIT_TEST(testRandomAlpha);
|
|
||||||
CPPUNIT_TEST(testToUpper);
|
CPPUNIT_TEST(testToUpper);
|
||||||
CPPUNIT_TEST(testToLower);
|
CPPUNIT_TEST(testToLower);
|
||||||
CPPUNIT_TEST(testUppercase);
|
CPPUNIT_TEST(testUppercase);
|
||||||
|
@ -52,7 +51,6 @@ class UtilTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testIsNumber);
|
CPPUNIT_TEST(testIsNumber);
|
||||||
CPPUNIT_TEST(testIsLowercase);
|
CPPUNIT_TEST(testIsLowercase);
|
||||||
CPPUNIT_TEST(testIsUppercase);
|
CPPUNIT_TEST(testIsUppercase);
|
||||||
CPPUNIT_TEST(testAlphaToNum);
|
|
||||||
CPPUNIT_TEST(testMkdirs);
|
CPPUNIT_TEST(testMkdirs);
|
||||||
CPPUNIT_TEST(testConvertBitfield);
|
CPPUNIT_TEST(testConvertBitfield);
|
||||||
CPPUNIT_TEST(testParseIntSegments);
|
CPPUNIT_TEST(testParseIntSegments);
|
||||||
|
@ -109,7 +107,6 @@ public:
|
||||||
void testIstartsWith();
|
void testIstartsWith();
|
||||||
// may be moved to other helper class in the future.
|
// may be moved to other helper class in the future.
|
||||||
void testGetContentDispositionFilename();
|
void testGetContentDispositionFilename();
|
||||||
void testRandomAlpha();
|
|
||||||
void testToUpper();
|
void testToUpper();
|
||||||
void testToLower();
|
void testToLower();
|
||||||
void testUppercase();
|
void testUppercase();
|
||||||
|
@ -121,7 +118,6 @@ public:
|
||||||
void testIsNumber();
|
void testIsNumber();
|
||||||
void testIsLowercase();
|
void testIsLowercase();
|
||||||
void testIsUppercase();
|
void testIsUppercase();
|
||||||
void testAlphaToNum();
|
|
||||||
void testMkdirs();
|
void testMkdirs();
|
||||||
void testConvertBitfield();
|
void testConvertBitfield();
|
||||||
void testParseIntSegments();
|
void testParseIntSegments();
|
||||||
|
@ -960,12 +956,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void UtilTest::testRandomAlpha() {
|
|
||||||
SharedHandle<Randomizer> rand(new FixedNumberRandomizer());
|
|
||||||
std::string s = util::randomAlpha(8, rand);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("AAAAAAAA"), s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UtilTest::testToUpper() {
|
void UtilTest::testToUpper() {
|
||||||
std::string src = "608cabc0f2fa18c260cafd974516865c772363d5";
|
std::string src = "608cabc0f2fa18c260cafd974516865c772363d5";
|
||||||
std::string upp = "608CABC0F2FA18C260CAFD974516865C772363D5";
|
std::string upp = "608CABC0F2FA18C260CAFD974516865C772363D5";
|
||||||
|
@ -1134,18 +1124,6 @@ void UtilTest::testIsUppercase()
|
||||||
CPPUNIT_ASSERT_EQUAL(false, util::isUppercase(s.begin(), s.end()));
|
CPPUNIT_ASSERT_EQUAL(false, util::isUppercase(s.begin(), s.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UtilTest::testAlphaToNum()
|
|
||||||
{
|
|
||||||
CPPUNIT_ASSERT_EQUAL(0U, util::alphaToNum("a"));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(0U, util::alphaToNum("aa"));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(1U, util::alphaToNum("b"));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(675U, util::alphaToNum("zz")); // 25*26+25
|
|
||||||
CPPUNIT_ASSERT_EQUAL(675U, util::alphaToNum("ZZ")); // 25*26+25
|
|
||||||
CPPUNIT_ASSERT_EQUAL(0U, util::alphaToNum(""));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(4294967295U, util::alphaToNum("NXMRLXV"));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(0U, util::alphaToNum("NXMRLXW")); // uint32_t overflow
|
|
||||||
}
|
|
||||||
|
|
||||||
void UtilTest::testMkdirs()
|
void UtilTest::testMkdirs()
|
||||||
{
|
{
|
||||||
std::string dir = A2_TEST_OUT_DIR"/aria2-UtilTest-testMkdirs";
|
std::string dir = A2_TEST_OUT_DIR"/aria2-UtilTest-testMkdirs";
|
||||||
|
|
Loading…
Reference in New Issue