Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #524 from rakshasa/feature-flags
Feature flags
- Loading branch information
Showing
11 changed files
with
399 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// rTorrent - BitTorrent client | ||
// Copyright (C) 2005-2011, Jari Sundell | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
// | ||
// In addition, as a special exception, the copyright holders give | ||
// permission to link the code of portions of this program with the | ||
// OpenSSL library under certain conditions as described in each | ||
// individual source file, and distribute linked combinations | ||
// including the two. | ||
// | ||
// You must obey the GNU General Public License in all respects for | ||
// all of the code used other than OpenSSL. If you modify file(s) | ||
// with this exception, you may extend this exception to your version | ||
// of the file(s), but you are not obligated to do so. If you do not | ||
// wish to do so, delete this exception statement from your version. | ||
// If you delete this exception statement from all source files in the | ||
// program, then also delete it here. | ||
// | ||
// Contact: Jari Sundell <jaris@ifi.uio.no> | ||
// | ||
// Skomakerveien 33 | ||
// 3185 Skoppum, NORWAY | ||
|
||
#include "parse_options.h" | ||
|
||
#include <algorithm> | ||
#include <locale> | ||
#include <torrent/exceptions.h> | ||
|
||
namespace rpc { | ||
|
||
int | ||
parse_option_flag(const std::string& option, std::function<int (const std::string&)> ftor) { | ||
auto first = option.begin(); | ||
auto last = option.end(); | ||
|
||
first = std::find_if(first, last, [](char c) { return !std::isspace(c, std::locale::classic()); }); | ||
|
||
if (first == last) | ||
throw torrent::input_error(option); | ||
|
||
auto next = std::find_if(first, last, [](char c) { return !std::isalnum(c, std::locale::classic()) && c != '_'; }); | ||
|
||
if (first == next) | ||
throw torrent::input_error(option); | ||
|
||
if (std::find_if(next, last, [](char c) { return !std::isspace(c, std::locale::classic()); }) != last) | ||
throw torrent::input_error(option); | ||
|
||
return ftor(std::string(first, next)); | ||
} | ||
|
||
int | ||
parse_option_flags(const std::string& option, std::function<int (const std::string&)> ftor, int flags) { | ||
auto first = option.begin(); | ||
auto last = option.end(); | ||
|
||
while (first != last) { | ||
first = std::find_if(first, last, [](char c) { return !std::isspace(c, std::locale::classic()); }); | ||
|
||
if (first == last) | ||
break; | ||
|
||
auto next = std::find_if(first, last, [](char c) { return !std::isalnum(c, std::locale::classic()) && c != '_'; }); | ||
|
||
if (first == next) | ||
throw torrent::input_error(option); | ||
|
||
flags |= ftor(std::string(first, next)); | ||
|
||
first = std::find_if(next, last, [](char c) { return !std::isspace(c, std::locale::classic()); }); | ||
|
||
if (first == last) | ||
break; | ||
|
||
if (*first++ != '|' || first == last) | ||
throw torrent::input_error(option); | ||
} | ||
|
||
return flags; | ||
} | ||
|
||
void | ||
parse_option_for_each(const std::string& option, std::function<int (const std::string&)> ftor) { | ||
auto first = option.begin(); | ||
auto last = option.end(); | ||
|
||
while (first != last) { | ||
first = std::find_if(first, last, [](char c) { return !std::isspace(c, std::locale::classic()); }); | ||
|
||
if (first == last) | ||
break; | ||
|
||
auto next = std::find_if(first, last, [](char c) { return !std::isalnum(c, std::locale::classic()) && c != '_'; }); | ||
|
||
if (first == next) | ||
throw torrent::input_error(option); | ||
|
||
ftor(std::string(first, next)); | ||
|
||
first = std::find_if(next, last, [](char c) { return !std::isspace(c, std::locale::classic()); }); | ||
|
||
if (first == last) | ||
break; | ||
|
||
if (*first++ != '|' || first == last) | ||
throw torrent::input_error(option); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// rTorrent - BitTorrent client | ||
// Copyright (C) 2005-2011, Jari Sundell | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
// | ||
// In addition, as a special exception, the copyright holders give | ||
// permission to link the code of portions of this program with the | ||
// OpenSSL library under certain conditions as described in each | ||
// individual source file, and distribute linked combinations | ||
// including the two. | ||
// | ||
// You must obey the GNU General Public License in all respects for | ||
// all of the code used other than OpenSSL. If you modify file(s) | ||
// with this exception, you may extend this exception to your version | ||
// of the file(s), but you are not obligated to do so. If you do not | ||
// wish to do so, delete this exception statement from your version. | ||
// If you delete this exception statement from all source files in the | ||
// program, then also delete it here. | ||
// | ||
// Contact: Jari Sundell <jaris@ifi.uio.no> | ||
// | ||
// Skomakerveien 33 | ||
// 3185 Skoppum, NORWAY | ||
|
||
#ifndef RTORRENT_RPC_PARSE_OPTIONS_H | ||
#define RTORRENT_RPC_PARSE_OPTIONS_H | ||
|
||
#include <cstring> | ||
#include <functional> | ||
#include <string> | ||
|
||
namespace rpc { | ||
|
||
int parse_option_flag(const std::string& option, std::function<int (const std::string&)> ftor); | ||
int parse_option_flags(const std::string& option, std::function<int (const std::string&)> ftor, int flags = int()); | ||
|
||
void parse_option_for_each(const std::string& option, std::function<void (const std::string&)> ftor); | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef HELPERS_ASSERT_H | ||
#define HELPERS_ASSERT_H | ||
|
||
#define ASSERT_CATCH_INPUT_ERROR(some_code) \ | ||
try { some_code; CPPUNIT_ASSERT("torrent::input_error not caught" && false); } catch (torrent::input_error& e) { } | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.