diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/poco/Util/src/IniFileConfiguration.cpp | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/poco/Util/src/IniFileConfiguration.cpp')
-rw-r--r-- | contrib/libs/poco/Util/src/IniFileConfiguration.cpp | 380 |
1 files changed, 190 insertions, 190 deletions
diff --git a/contrib/libs/poco/Util/src/IniFileConfiguration.cpp b/contrib/libs/poco/Util/src/IniFileConfiguration.cpp index 82c48bd695..76447c10ab 100644 --- a/contrib/libs/poco/Util/src/IniFileConfiguration.cpp +++ b/contrib/libs/poco/Util/src/IniFileConfiguration.cpp @@ -1,190 +1,190 @@ -// -// IniFileConfiguration.cpp -// -// Library: Util -// Package: Configuration -// Module: IniFileConfiguration -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#include "Poco/Util/IniFileConfiguration.h" - - -#ifndef POCO_UTIL_NO_INIFILECONFIGURATION - - -#include "Poco/Exception.h" -#include "Poco/String.h" -#include "Poco/Path.h" -#include "Poco/FileStream.h" -#include "Poco/Ascii.h" -#include <set> - - -using Poco::icompare; -using Poco::trim; -using Poco::Path; - - -namespace Poco { -namespace Util { - - -IniFileConfiguration::IniFileConfiguration() -{ -} - - -IniFileConfiguration::IniFileConfiguration(std::istream& istr) -{ - load(istr); -} - - -IniFileConfiguration::IniFileConfiguration(const std::string& path) -{ - load(path); -} - - -IniFileConfiguration::~IniFileConfiguration() -{ -} - - -void IniFileConfiguration::load(std::istream& istr) -{ - _map.clear(); - _sectionKey.clear(); - while (!istr.eof()) - { - parseLine(istr); - } -} - - -void IniFileConfiguration::load(const std::string& path) -{ - Poco::FileInputStream istr(path); - if (istr.good()) - load(istr); - else - throw Poco::OpenFileException(path); -} - - -bool IniFileConfiguration::getRaw(const std::string& key, std::string& value) const -{ - IStringMap::const_iterator it = _map.find(key); - if (it != _map.end()) - { - value = it->second; - return true; - } - else return false; -} - - -void IniFileConfiguration::setRaw(const std::string& key, const std::string& value) -{ - _map[key] = value; -} - - -void IniFileConfiguration::enumerate(const std::string& key, Keys& range) const -{ - std::set<std::string> keys; - std::string prefix = key; - if (!prefix.empty()) prefix += '.'; - std::string::size_type psize = prefix.size(); - for (IStringMap::const_iterator it = _map.begin(); it != _map.end(); ++it) - { - if (icompare(it->first, psize, prefix) == 0) - { - std::string subKey; - std::string::size_type end = it->first.find('.', psize); - if (end == std::string::npos) - subKey = it->first.substr(psize); - else - subKey = it->first.substr(psize, end - psize); - if (keys.find(subKey) == keys.end()) - { - range.push_back(subKey); - keys.insert(subKey); - } - } - } -} - - -void IniFileConfiguration::removeRaw(const std::string& key) -{ - std::string prefix = key; - if (!prefix.empty()) prefix += '.'; - std::string::size_type psize = prefix.size(); - IStringMap::iterator it = _map.begin(); - IStringMap::iterator itCur; - while (it != _map.end()) - { - itCur = it++; - if ((icompare(itCur->first, key) == 0) || (icompare(itCur->first, psize, prefix) == 0)) - { - _map.erase(itCur); - } - } -} - - -bool IniFileConfiguration::ICompare::operator () (const std::string& s1, const std::string& s2) const -{ - return icompare(s1, s2) < 0; -} - - -void IniFileConfiguration::parseLine(std::istream& istr) -{ - static const int eof = std::char_traits<char>::eof(); - - int c = istr.get(); - while (c != eof && Poco::Ascii::isSpace(c)) c = istr.get(); - if (c != eof) - { - if (c == ';') - { - while (c != eof && c != '\n') c = istr.get(); - } - else if (c == '[') - { - std::string key; - c = istr.get(); - while (c != eof && c != ']' && c != '\n') { key += (char) c; c = istr.get(); } - _sectionKey = trim(key); - } - else - { - std::string key; - while (c != eof && c != '=' && c != '\n') { key += (char) c; c = istr.get(); } - std::string value; - if (c == '=') - { - c = istr.get(); - while (c != eof && c != '\n') { value += (char) c; c = istr.get(); } - } - std::string fullKey = _sectionKey; - if (!fullKey.empty()) fullKey += '.'; - fullKey.append(trim(key)); - _map[fullKey] = trim(value); - } - } -} - - -} } // namespace Poco::Util - - -#endif // POCO_UTIL_NO_INIFILECONFIGURATION
\ No newline at end of file +// +// IniFileConfiguration.cpp +// +// Library: Util +// Package: Configuration +// Module: IniFileConfiguration +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#include "Poco/Util/IniFileConfiguration.h" + + +#ifndef POCO_UTIL_NO_INIFILECONFIGURATION + + +#include "Poco/Exception.h" +#include "Poco/String.h" +#include "Poco/Path.h" +#include "Poco/FileStream.h" +#include "Poco/Ascii.h" +#include <set> + + +using Poco::icompare; +using Poco::trim; +using Poco::Path; + + +namespace Poco { +namespace Util { + + +IniFileConfiguration::IniFileConfiguration() +{ +} + + +IniFileConfiguration::IniFileConfiguration(std::istream& istr) +{ + load(istr); +} + + +IniFileConfiguration::IniFileConfiguration(const std::string& path) +{ + load(path); +} + + +IniFileConfiguration::~IniFileConfiguration() +{ +} + + +void IniFileConfiguration::load(std::istream& istr) +{ + _map.clear(); + _sectionKey.clear(); + while (!istr.eof()) + { + parseLine(istr); + } +} + + +void IniFileConfiguration::load(const std::string& path) +{ + Poco::FileInputStream istr(path); + if (istr.good()) + load(istr); + else + throw Poco::OpenFileException(path); +} + + +bool IniFileConfiguration::getRaw(const std::string& key, std::string& value) const +{ + IStringMap::const_iterator it = _map.find(key); + if (it != _map.end()) + { + value = it->second; + return true; + } + else return false; +} + + +void IniFileConfiguration::setRaw(const std::string& key, const std::string& value) +{ + _map[key] = value; +} + + +void IniFileConfiguration::enumerate(const std::string& key, Keys& range) const +{ + std::set<std::string> keys; + std::string prefix = key; + if (!prefix.empty()) prefix += '.'; + std::string::size_type psize = prefix.size(); + for (IStringMap::const_iterator it = _map.begin(); it != _map.end(); ++it) + { + if (icompare(it->first, psize, prefix) == 0) + { + std::string subKey; + std::string::size_type end = it->first.find('.', psize); + if (end == std::string::npos) + subKey = it->first.substr(psize); + else + subKey = it->first.substr(psize, end - psize); + if (keys.find(subKey) == keys.end()) + { + range.push_back(subKey); + keys.insert(subKey); + } + } + } +} + + +void IniFileConfiguration::removeRaw(const std::string& key) +{ + std::string prefix = key; + if (!prefix.empty()) prefix += '.'; + std::string::size_type psize = prefix.size(); + IStringMap::iterator it = _map.begin(); + IStringMap::iterator itCur; + while (it != _map.end()) + { + itCur = it++; + if ((icompare(itCur->first, key) == 0) || (icompare(itCur->first, psize, prefix) == 0)) + { + _map.erase(itCur); + } + } +} + + +bool IniFileConfiguration::ICompare::operator () (const std::string& s1, const std::string& s2) const +{ + return icompare(s1, s2) < 0; +} + + +void IniFileConfiguration::parseLine(std::istream& istr) +{ + static const int eof = std::char_traits<char>::eof(); + + int c = istr.get(); + while (c != eof && Poco::Ascii::isSpace(c)) c = istr.get(); + if (c != eof) + { + if (c == ';') + { + while (c != eof && c != '\n') c = istr.get(); + } + else if (c == '[') + { + std::string key; + c = istr.get(); + while (c != eof && c != ']' && c != '\n') { key += (char) c; c = istr.get(); } + _sectionKey = trim(key); + } + else + { + std::string key; + while (c != eof && c != '=' && c != '\n') { key += (char) c; c = istr.get(); } + std::string value; + if (c == '=') + { + c = istr.get(); + while (c != eof && c != '\n') { value += (char) c; c = istr.get(); } + } + std::string fullKey = _sectionKey; + if (!fullKey.empty()) fullKey += '.'; + fullKey.append(trim(key)); + _map[fullKey] = trim(value); + } + } +} + + +} } // namespace Poco::Util + + +#endif // POCO_UTIL_NO_INIFILECONFIGURATION
\ No newline at end of file |