Commit 30aa6321 authored by december0123's avatar december0123

Change tabs to spaces

parent c8b8a4bf
......@@ -12,89 +12,89 @@
namespace Vita {
string string::toLower() const {
string result;
for (size_t i = 0; i < this->length(); i++) {
result += tolower((*this)[i]);
}
return result;
}
string string::toUpper() const {
string result;
for (size_t i = 0; i < this->length(); i++) {
result += toupper((*this)[i]);
}
return result;
}
string string::ucfirst() const {
string result = *this;
result[0] = toupper(result[0]);
return result;
}
string string::lcfirst() const {
string result = *this;
result[0] = tolower(result[0]);
return result;
}
string string::operator+(int operand) const {
return (*this) + string::toStr<int>(operand);
}
string string::operator+(long int operand) const {
return (*this) + string::toStr<long int>(operand);
}
string string::operator+(double operand) const {
return (*this) + string::toStr<double>(operand);
}
string string::operator+(float operand) const {
return (*this) + string::toStr<float>(operand);
}
string string::replace(const string& search, const string& replace, size_t limit) const {
string result;
size_t previous = 0, current;
current = this->find(search);
while (current != npos && limit) {
result += this->substr(previous, current - previous);
result += replace;
previous = current + search.length();
current = this->find(search, previous);
--limit;
}
result += this->substr(previous);
return result;
}
std::vector<string> string::explode(const string& delimiter) const {
std::vector<string> result;
size_t previous = 0, current;
current = this->find(delimiter);
while (current != npos) {
result.push_back(this->substr(previous, current - previous));
previous = current + delimiter.length();
current = this->find(delimiter, previous);
}
result.push_back(this->substr(previous));
return result;
}
string string::trim(const string& what) const {
string result = *this;
size_t pos = result.find_first_not_of(what);
result.erase(0, pos);
pos = result.find_last_not_of(what);
result.erase(pos + 1);
return result;
}
string string::toLower() const {
string result;
for (size_t i = 0; i < this->length(); i++) {
result += tolower((*this)[i]);
}
return result;
}
string string::toUpper() const {
string result;
for (size_t i = 0; i < this->length(); i++) {
result += toupper((*this)[i]);
}
return result;
}
string string::ucfirst() const {
string result = *this;
result[0] = toupper(result[0]);
return result;
}
string string::lcfirst() const {
string result = *this;
result[0] = tolower(result[0]);
return result;
}
string string::operator+(int operand) const {
return (*this) + string::toStr<int>(operand);
}
string string::operator+(long int operand) const {
return (*this) + string::toStr<long int>(operand);
}
string string::operator+(double operand) const {
return (*this) + string::toStr<double>(operand);
}
string string::operator+(float operand) const {
return (*this) + string::toStr<float>(operand);
}
string string::replace(const string& search, const string& replace, size_t limit) const {
string result;
size_t previous = 0, current;
current = this->find(search);
while (current != npos && limit) {
result += this->substr(previous, current - previous);
result += replace;
previous = current + search.length();
current = this->find(search, previous);
--limit;
}
result += this->substr(previous);
return result;
}
std::vector<string> string::explode(const string& delimiter) const {
std::vector<string> result;
size_t previous = 0, current;
current = this->find(delimiter);
while (current != npos) {
result.push_back(this->substr(previous, current - previous));
previous = current + delimiter.length();
current = this->find(delimiter, previous);
}
result.push_back(this->substr(previous));
return result;
}
string string::trim(const string& what) const {
string result = *this;
size_t pos = result.find_first_not_of(what);
result.erase(0, pos);
pos = result.find_last_not_of(what);
result.erase(pos + 1);
return result;
}
} // namespace Vita
......@@ -18,157 +18,157 @@
namespace Vita {
/**
* Slightly enhanced version of std::string.
*/
class string : public std::string {
public:
/**
* Directly call <tt>std::string::string()</tt>.
*/
explicit string():std::string() {};
/**
* Directly call <tt>std::string::string(const char*)</tt>.
*/
string(const char* cstr):std::string(cstr) {};
/**
* Directly call <tt>std::string::string(const char*, size_t)</tt>.
*/
string(const char* cstr, size_t n):std::string(cstr, n) {};
/**
* Directly call <tt>std::string::string(const std::string&)</tt>.
*/
string(const std::string& str):std::string(str) {};
/**
* Directly call <tt>std::string::string(const std::string&, size_t, size_t)</tt>.
*/
string(const std::string& str, size_t pos, size_t n = npos):std::string(str, pos, n) {};
/**
* Directly call <tt>std::string::string(size_t, char)</tt>.
*/
string(size_t n, char c):std::string(n, c) {};
/**
* Convert all characters to lower case.
*/
string toLower() const;
/**
* Convert all characters to upper case.
*/
string toUpper() const;
/**
* Make the first character uppercase.
*/
string ucfirst() const;
/**
* Make the first character lowercase.
*/
string lcfirst() const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(int operand) const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(long int operand) const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(double operand) const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(float operand) const;
/**
* Replace all occurences of a certain substring in the string.
*
* @param search The substring that will be replaced.
* @param replace The replacement.
* @param limit How many replacements should be done. Set to Vita::string::npos to disable the limit.
* @return String with the replacement(s) in place.
*/
string replace(const string& search, const string& replace, size_t limit = npos) const;
/**
* Split the string by another string.
*
* This method is similar to the <tt>explode</tt> function known from PHP.
*
* @param delimiter The boundary string.
* @return A vector of strings, each of which is a substring of the original.
*/
std::vector<string> explode(const string& delimiter) const;
/**
* Trim unwanted characters from the beginning and the end of the string.
*
* @param what The characters to trim. Defaults to whitespace (ASCII #9, #10, #13, #32).
* @return The trimmed string.
*/
string trim(const string& what = "\x9\xa\xd\x20") const;
/**
* Convert a generic data type to string.
*
* The conversion is done via std::ostringstream.
*
* @param source The value to convert.
* @return string
*/
template<class T> static string toStr(const T& source) {
std::ostringstream stream;
stream << source;
return string(stream.str());
}
/**
* Convert the string to a generic data type.
*
* The conversion is done via std::istringstream.
*
* @return The converted string.
*/
template<class T> T convert() const {
std::istringstream stream(*this);
T result;
stream >> result;
return result;
}
};
/**
* Slightly enhanced version of std::string.
*/
class string : public std::string {
public:
/**
* Directly call <tt>std::string::string()</tt>.
*/
explicit string():std::string() {};
/**
* Directly call <tt>std::string::string(const char*)</tt>.
*/
string(const char* cstr):std::string(cstr) {};
/**
* Directly call <tt>std::string::string(const char*, size_t)</tt>.
*/
string(const char* cstr, size_t n):std::string(cstr, n) {};
/**
* Directly call <tt>std::string::string(const std::string&)</tt>.
*/
string(const std::string& str):std::string(str) {};
/**
* Directly call <tt>std::string::string(const std::string&, size_t, size_t)</tt>.
*/
string(const std::string& str, size_t pos, size_t n = npos):std::string(str, pos, n) {};
/**
* Directly call <tt>std::string::string(size_t, char)</tt>.
*/
string(size_t n, char c):std::string(n, c) {};
/**
* Convert all characters to lower case.
*/
string toLower() const;
/**
* Convert all characters to upper case.
*/
string toUpper() const;
/**
* Make the first character uppercase.
*/
string ucfirst() const;
/**
* Make the first character lowercase.
*/
string lcfirst() const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(int operand) const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(long int operand) const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(double operand) const;
/**
* Convert the operand to string and append it.
*
* This overrides the behavior of std::string.
*
* @param operand The number to be appended.
* @return The string with @a operand appended.
*/
string operator+(float operand) const;
/**
* Replace all occurences of a certain substring in the string.
*
* @param search The substring that will be replaced.
* @param replace The replacement.
* @param limit How many replacements should be done. Set to Vita::string::npos to disable the limit.
* @return String with the replacement(s) in place.
*/
string replace(const string& search, const string& replace, size_t limit = npos) const;
/**
* Split the string by another string.
*
* This method is similar to the <tt>explode</tt> function known from PHP.
*
* @param delimiter The boundary string.
* @return A vector of strings, each of which is a substring of the original.
*/
std::vector<string> explode(const string& delimiter) const;
/**
* Trim unwanted characters from the beginning and the end of the string.
*
* @param what The characters to trim. Defaults to whitespace (ASCII #9, #10, #13, #32).
* @return The trimmed string.
*/
string trim(const string& what = "\x9\xa\xd\x20") const;
/**
* Convert a generic data type to string.
*
* The conversion is done via std::ostringstream.
*
* @param source The value to convert.
* @return string
*/
template<class T> static string toStr(const T& source) {
std::ostringstream stream;
stream << source;
return string(stream.str());
}
/**
* Convert the string to a generic data type.
*
* The conversion is done via std::istringstream.
*
* @return The converted string.
*/
template<class T> T convert() const {
std::istringstream stream(*this);
T result;
stream >> result;
return result;
}
};
} // namespace Vita
......
......@@ -11,236 +11,236 @@
#include <string>
Config::Config(std::string configPath, std::string type)
: type_(type), basePath_(configPath.substr(0, configPath.find_last_of('/'))),
configPath_(configPath)
: type_(type), basePath_(configPath.substr(0, configPath.find_last_of('/'))),
configPath_(configPath)
{
// Add new HardwareIDs group to vector if vector is empty
if (hwdIDs_.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
// Add new HardwareIDs group to vector if vector is empty
if (hwdIDs_.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
}
bool Config::readConfigFile(std::string configPath)
{
std::ifstream file(configPath.c_str(), std::ios::in);
if (!file.is_open())
{
return false;
}
Vita::string line;
Vita::string key;
Vita::string value;
std::vector<Vita::string> parts;
while (!file.eof())
{
getline(file, line);
size_t pos = line.find_first_of('#');
if (pos != std::string::npos)
{
line.erase(pos);
}
if (line.trim().empty())
{
continue;
}
parts = line.explode("=");
key = parts.front().trim().toLower();
value = parts.back().trim("\"").trim();
// Read in extern file
if (value.size() > 1 && value.substr(0, 1) == ">")
{
std::ifstream file(getRightConfigPath(value.substr(1), basePath_).c_str(),
std::ios::in);
if (!file.is_open())
{
return false;
}
Vita::string line;
value.clear();
while (!file.eof())
{
getline(file, line);
size_t pos = line.find_first_of('#');
if (pos != std::string::npos)
{
line.erase(pos);
}
if (line.trim().empty())
{
continue;
}
value += " " + line.trim();
}
value = value.trim();
// remove all multiple spaces
while (value.find(" ") != std::string::npos)
{
value = value.replace(" ", " ");
}
}
if (key == "include")
{
readConfigFile(getRightConfigPath(value, basePath_));
}
else if (key == "name")
{
name_ = value.toLower();
}
else if (key == "version")
{
version_ = value;
}
else if (key == "info")
{
info_ = value;
}
else if (key == "priority")
{
priority_ = value.convert<int>();
}
else if (key == "freedriver")
{
value = value.toLower();
if (value == "false")
{
freedriver_ = false;
}
else if (value == "true")
{