2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Made string literals used in SAX parser static const 
std::string.
	* src/FileMetalinkParserState.cc
	* src/FileMetalinkParserState.h
	* src/FilesMetalinkParserState.cc
	* src/FilesMetalinkParserState.h
	* src/InitialMetalinkParserState.cc
	* src/InitialMetalinkParserState.h
	* src/MetalinkMetalinkParserState.cc
	* src/MetalinkMetalinkParserState.h
	* src/PiecesMetalinkParserState.cc
	* src/PiecesMetalinkParserState.h
	* src/ResourcesMetalinkParserState.cc
	* src/ResourcesMetalinkParserState.h
	* src/VerificationMetalinkParserState.cc
	* src/VerificationMetalinkParserState.h
pull/1/head
Tatsuhiro Tsujikawa 2008-05-14 12:51:05 +00:00
parent 1b874503cf
commit 48c96ac441
15 changed files with 140 additions and 23 deletions

View File

@ -1,3 +1,21 @@
2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made string literals used in SAX parser static const std::string.
* src/FileMetalinkParserState.cc
* src/FileMetalinkParserState.h
* src/FilesMetalinkParserState.cc
* src/FilesMetalinkParserState.h
* src/InitialMetalinkParserState.cc
* src/InitialMetalinkParserState.h
* src/MetalinkMetalinkParserState.cc
* src/MetalinkMetalinkParserState.h
* src/PiecesMetalinkParserState.cc
* src/PiecesMetalinkParserState.h
* src/ResourcesMetalinkParserState.cc
* src/ResourcesMetalinkParserState.h
* src/VerificationMetalinkParserState.cc
* src/VerificationMetalinkParserState.h
2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Use A2STR::SLASH_C, A2STR::DOT_C instead of "/", "." respectively. Use A2STR::SLASH_C, A2STR::DOT_C instead of "/", "." respectively.

View File

@ -39,27 +39,42 @@
namespace aria2 { namespace aria2 {
const std::string FileMetalinkParserState::SIZE("size");
const std::string FileMetalinkParserState::METALINK_VERSION("version");
const std::string FileMetalinkParserState::LANGUAGE("language");
const std::string FileMetalinkParserState::OS("os");
const std::string FileMetalinkParserState::VERIFICATION("verification");
const std::string FileMetalinkParserState::RESOURCES("resources");
const std::string FileMetalinkParserState::MAXCONNECTIONS("maxconnections");
void FileMetalinkParserState::beginElement(MetalinkParserStateMachine* stm, void FileMetalinkParserState::beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::string& name,
const std::map<std::string, std::string>& attrs) const std::map<std::string, std::string>& attrs)
{ {
if(name == "size") { if(name == FileMetalinkParserState::SIZE) {
stm->setSizeState(); stm->setSizeState();
} else if(name == "version") { } else if(name == FileMetalinkParserState::METALINK_VERSION) {
stm->setVersionState(); stm->setVersionState();
} else if(name == "language") { } else if(name == FileMetalinkParserState::LANGUAGE) {
stm->setLanguageState(); stm->setLanguageState();
} else if(name == "os") { } else if(name == FileMetalinkParserState::OS) {
stm->setOSState(); stm->setOSState();
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
} else if(name == "verification") { } else if(name == FileMetalinkParserState::VERIFICATION) {
stm->setVerificationState(); stm->setVerificationState();
#endif // ENABLE_MESSAGE_DIGEST #endif // ENABLE_MESSAGE_DIGEST
} else if(name == "resources") { } else if(name == FileMetalinkParserState::RESOURCES) {
stm->setResourcesState(); stm->setResourcesState();
int maxConnections; int maxConnections;
{ {
std::map<std::string, std::string>::const_iterator itr = attrs.find("maxconnections"); std::map<std::string, std::string>::const_iterator itr =
attrs.find(FileMetalinkParserState::MAXCONNECTIONS);
if(itr == attrs.end()) { if(itr == attrs.end()) {
maxConnections = -1; maxConnections = -1;
} else { } else {

View File

@ -41,6 +41,21 @@ namespace aria2 {
class FileMetalinkParserState:public MetalinkParserState class FileMetalinkParserState:public MetalinkParserState
{ {
private:
static const std::string SIZE;
// VERSION is not allowed here because it is defined in macro.
static const std::string METALINK_VERSION;
static const std::string LANGUAGE;
static const std::string OS;
static const std::string VERIFICATION;
static const std::string RESOURCES;
static const std::string MAXCONNECTIONS;
public: public:
void beginElement(MetalinkParserStateMachine* stm, void beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::map<std::string, std::string>& attrs); const std::string& name, const std::map<std::string, std::string>& attrs);

View File

@ -37,13 +37,18 @@
namespace aria2 { namespace aria2 {
const std::string FilesMetalinkParserState::FILE("file");
const std::string FilesMetalinkParserState::NAME("name");
void FilesMetalinkParserState::beginElement(MetalinkParserStateMachine* stm, void FilesMetalinkParserState::beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::string& name,
const std::map<std::string, std::string>& attrs) const std::map<std::string, std::string>& attrs)
{ {
if(name == "file") { if(name == FilesMetalinkParserState::FILE) {
stm->setFileState(); stm->setFileState();
std::map<std::string, std::string>::const_iterator itr = attrs.find("name"); std::map<std::string, std::string>::const_iterator itr =
attrs.find(FilesMetalinkParserState::NAME);
if(itr != attrs.end()) { if(itr != attrs.end()) {
stm->newEntryTransaction(); stm->newEntryTransaction();
stm->setFileNameOfEntry((*itr).second); stm->setFileNameOfEntry((*itr).second);

View File

@ -41,6 +41,10 @@ namespace aria2 {
class FilesMetalinkParserState:public MetalinkParserState class FilesMetalinkParserState:public MetalinkParserState
{ {
private:
static const std::string FILE;
static const std::string NAME;
public: public:
void beginElement(MetalinkParserStateMachine* stm, void beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::map<std::string, std::string>& attrs); const std::string& name, const std::map<std::string, std::string>& attrs);

View File

@ -37,11 +37,13 @@
namespace aria2 { namespace aria2 {
const std::string InitialMetalinkParserState::METALINK("metalink");
void InitialMetalinkParserState::beginElement(MetalinkParserStateMachine* stm, void InitialMetalinkParserState::beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::string& name,
const std::map<std::string, std::string>& attrs) const std::map<std::string, std::string>& attrs)
{ {
if(name == "metalink") { if(name == InitialMetalinkParserState::METALINK) {
stm->setMetalinkState(); stm->setMetalinkState();
} else { } else {
stm->setSkipTagState(this); stm->setSkipTagState(this);

View File

@ -41,6 +41,8 @@ namespace aria2 {
class InitialMetalinkParserState:public MetalinkParserState class InitialMetalinkParserState:public MetalinkParserState
{ {
private:
static const std::string METALINK;
public: public:
void beginElement(MetalinkParserStateMachine* stm, void beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::map<std::string, std::string>& attrs); const std::string& name, const std::map<std::string, std::string>& attrs);

View File

@ -37,11 +37,13 @@
namespace aria2 { namespace aria2 {
const std::string MetalinkMetalinkParserState::FILES("files");
void MetalinkMetalinkParserState::beginElement(MetalinkParserStateMachine* stm, void MetalinkMetalinkParserState::beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::string& name,
const std::map<std::string, std::string>& attrs) const std::map<std::string, std::string>& attrs)
{ {
if(name == "files") { if(name == MetalinkMetalinkParserState::FILES) {
stm->setFilesState(); stm->setFilesState();
} else { } else {
stm->setSkipTagState(this); stm->setSkipTagState(this);

View File

@ -41,6 +41,8 @@ namespace aria2 {
class MetalinkMetalinkParserState:public MetalinkParserState class MetalinkMetalinkParserState:public MetalinkParserState
{ {
private:
static const std::string FILES;
public: public:
void beginElement(MetalinkParserStateMachine* stm, void beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::map<std::string, std::string>& attrs); const std::string& name, const std::map<std::string, std::string>& attrs);

View File

@ -39,13 +39,18 @@
namespace aria2 { namespace aria2 {
const std::string PiecesMetalinkParserState::HASH("hash");
const std::string PiecesMetalinkParserState::PIECE("piece");
void PiecesMetalinkParserState::beginElement(MetalinkParserStateMachine* stm, void PiecesMetalinkParserState::beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::string& name,
const std::map<std::string, std::string>& attrs) const std::map<std::string, std::string>& attrs)
{ {
if(name == "hash") { if(name == PiecesMetalinkParserState::HASH) {
stm->setPieceHashState(); stm->setPieceHashState();
std::map<std::string, std::string>::const_iterator itr = attrs.find("piece"); std::map<std::string, std::string>::const_iterator itr =
attrs.find(PiecesMetalinkParserState::PIECE);
if(itr == attrs.end()) { if(itr == attrs.end()) {
stm->cancelChunkChecksumTransaction(); stm->cancelChunkChecksumTransaction();
} else { } else {

View File

@ -41,6 +41,10 @@ namespace aria2 {
class PiecesMetalinkParserState:public MetalinkParserState class PiecesMetalinkParserState:public MetalinkParserState
{ {
private:
static const std::string HASH;
static const std::string PIECE;
public: public:
void beginElement(MetalinkParserStateMachine* stm, void beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::map<std::string, std::string>& attrs); const std::string& name, const std::map<std::string, std::string>& attrs);

View File

@ -39,15 +39,26 @@
namespace aria2 { namespace aria2 {
const std::string ResourcesMetalinkParserState::URL("url");
const std::string ResourcesMetalinkParserState::TYPE("type");
const std::string ResourcesMetalinkParserState::LOCATION("location");
const std::string ResourcesMetalinkParserState::PREFERENCE("preference");
const std::string ResourcesMetalinkParserState::MAXCONNECTIONS("maxconnections");
void ResourcesMetalinkParserState::beginElement(MetalinkParserStateMachine* stm, void ResourcesMetalinkParserState::beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::string& name,
const std::map<std::string, std::string>& attrs) const std::map<std::string, std::string>& attrs)
{ {
if(name == "url") { if(name == ResourcesMetalinkParserState::URL) {
stm->setURLState(); stm->setURLState();
std::string type; std::string type;
{ {
std::map<std::string, std::string>::const_iterator itr = attrs.find("type"); std::map<std::string, std::string>::const_iterator itr =
attrs.find(ResourcesMetalinkParserState::TYPE);
if(itr == attrs.end()) { if(itr == attrs.end()) {
return; return;
} else { } else {
@ -56,14 +67,16 @@ void ResourcesMetalinkParserState::beginElement(MetalinkParserStateMachine* stm,
} }
std::string location; std::string location;
{ {
std::map<std::string, std::string>::const_iterator itr = attrs.find("location"); std::map<std::string, std::string>::const_iterator itr =
attrs.find(ResourcesMetalinkParserState::LOCATION);
if(itr != attrs.end()) { if(itr != attrs.end()) {
location = Util::toUpper((*itr).second); location = Util::toUpper((*itr).second);
} }
} }
int preference; int preference;
{ {
std::map<std::string, std::string>::const_iterator itr = attrs.find("preference"); std::map<std::string, std::string>::const_iterator itr =
attrs.find(ResourcesMetalinkParserState::PREFERENCE);
if(itr == attrs.end()) { if(itr == attrs.end()) {
preference = 0; preference = 0;
} else { } else {
@ -76,7 +89,8 @@ void ResourcesMetalinkParserState::beginElement(MetalinkParserStateMachine* stm,
} }
int maxConnections; int maxConnections;
{ {
std::map<std::string, std::string>::const_iterator itr = attrs.find("maxconnections"); std::map<std::string, std::string>::const_iterator itr =
attrs.find(ResourcesMetalinkParserState::MAXCONNECTIONS);
if(itr == attrs.end()) { if(itr == attrs.end()) {
maxConnections = -1; maxConnections = -1;
} else { } else {

View File

@ -41,6 +41,16 @@ namespace aria2 {
class ResourcesMetalinkParserState:public MetalinkParserState class ResourcesMetalinkParserState:public MetalinkParserState
{ {
private:
static const std::string URL;
static const std::string TYPE;
static const std::string LOCATION;
static const std::string PREFERENCE;
static const std::string MAXCONNECTIONS;
public: public:
void beginElement(MetalinkParserStateMachine* stm, void beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::map<std::string, std::string>& attrs); const std::string& name, const std::map<std::string, std::string>& attrs);

View File

@ -39,13 +39,22 @@
namespace aria2 { namespace aria2 {
const std::string VerificationMetalinkParserState::HASH("hash");
const std::string VerificationMetalinkParserState::TYPE("type");
const std::string VerificationMetalinkParserState::PIECES("pieces");
const std::string VerificationMetalinkParserState::LENGTH("length");
void VerificationMetalinkParserState::beginElement(MetalinkParserStateMachine* stm, void VerificationMetalinkParserState::beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::string& name,
const std::map<std::string, std::string>& attrs) const std::map<std::string, std::string>& attrs)
{ {
if(name == "hash") { if(name == VerificationMetalinkParserState::HASH) {
stm->setHashState(); stm->setHashState();
std::map<std::string, std::string>::const_iterator itr = attrs.find("type"); std::map<std::string, std::string>::const_iterator itr =
attrs.find(VerificationMetalinkParserState::TYPE);
if(itr == attrs.end()) { if(itr == attrs.end()) {
return; return;
} else { } else {
@ -53,12 +62,13 @@ void VerificationMetalinkParserState::beginElement(MetalinkParserStateMachine* s
stm->newChecksumTransaction(); stm->newChecksumTransaction();
stm->setTypeOfChecksum(type); stm->setTypeOfChecksum(type);
} }
} else if(name == "pieces") { } else if(name == VerificationMetalinkParserState::PIECES) {
stm->setPiecesState(); stm->setPiecesState();
try { try {
size_t length; size_t length;
{ {
std::map<std::string, std::string>::const_iterator itr = attrs.find("length"); std::map<std::string, std::string>::const_iterator itr =
attrs.find(VerificationMetalinkParserState::LENGTH);
if(itr == attrs.end()) { if(itr == attrs.end()) {
return; return;
} else { } else {
@ -67,7 +77,8 @@ void VerificationMetalinkParserState::beginElement(MetalinkParserStateMachine* s
} }
std::string type; std::string type;
{ {
std::map<std::string, std::string>::const_iterator itr = attrs.find("type"); std::map<std::string, std::string>::const_iterator itr =
attrs.find(VerificationMetalinkParserState::TYPE);
if(itr == attrs.end()) { if(itr == attrs.end()) {
return; return;
} else { } else {

View File

@ -41,6 +41,14 @@ namespace aria2 {
class VerificationMetalinkParserState:public MetalinkParserState class VerificationMetalinkParserState:public MetalinkParserState
{ {
private:
static const std::string HASH;
static const std::string TYPE;
static const std::string PIECES;
static const std::string LENGTH;
public: public:
void beginElement(MetalinkParserStateMachine* stm, void beginElement(MetalinkParserStateMachine* stm,
const std::string& name, const std::map<std::string, std::string>& attrs); const std::string& name, const std::map<std::string, std::string>& attrs);