desktop: made it possible to run Detect() multiple times in EvoSources
[barry/progweb.git] / src / a_codsection.cc
blob411673cdd00d17d11b56412b01d0b391178fc74d
1 ///
2 /// \file a_codsection.cc
3 /// COD structure for the ALX file parser
4 ///
6 /*
7 Copyright (C) 2010, Nicolas VIVIEN
8 Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #include <iostream>
24 #include <fstream>
25 #include <sstream>
27 #include "a_codsection.h"
30 namespace Barry {
32 namespace {
34 std::string trim(const std::string &str) {
35 int i;
36 int start, end;
38 std::string s;
40 const int len = str.size();
42 // ltrim
43 for (i=0; (((str[i]==' ') || (str[i]=='\t') || (str[i]=='\r') || (str[i]=='\n')) && (i<len)); i++);
44 start = i;
46 // rtrim
47 for (i=len-1; (((str[i]==' ') || (str[i]=='\t') || (str[i]=='\r') || (str[i]=='\n')) && (i>=0)); i--);
48 end = i+1;
50 s = str.substr(start, end-start);
52 return s;
58 namespace ALX {
61 CODSection::CODSection(void)
63 isRequired = false;
67 CODSection::CODSection(const xmlpp::SaxParser::AttributeList& attrs)
69 isRequired = false;
71 for (xmlpp::SaxParser::AttributeList::const_iterator iter = attrs.begin(); iter != attrs.end(); ++iter) {
72 std::string attribut(iter->name);
73 std::string value(iter->value);
75 if (attribut == "id")
76 SetID(value);
81 CODSection::~CODSection(void)
83 isRequired = false;
87 void CODSection::SetID(const std::string& id)
89 this->id = id;
93 void CODSection::SetName(const std::string& name)
95 this->name = trim(name);
99 void CODSection::SetDescription(const std::string& description)
101 this->description = trim(description);
105 void CODSection::SetVersion(const std::string& version)
107 this->version = trim(version);
111 void CODSection::SetVendor(const std::string& vendor)
113 this->vendor = trim(vendor);
117 void CODSection::SetCopyright(const std::string& copyright)
119 this->copyright = trim(copyright);
123 void CODSection::SetDirectory(const std::string& directory)
125 this->directory = trim(directory);
129 void CODSection::SetRequired(const std::string& required)
131 std::string s = trim(required);
133 if (s == "true")
134 isRequired = true;
135 else
136 isRequired = false;
140 void CODSection::AddFiles(const std::string& files)
142 std::string file;
143 std::istringstream iss(files);
145 while( std::getline(iss, file) ) {
146 file = trim(file);
148 if (file.length() > 0)
149 AddFile(file);
154 void CODSection::AddFile(const std::string& file)
156 codfiles.push_back(file);
160 } // namespace ALX
162 } // namespace Barry