Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
KayEss committed Nov 25, 2018
1 parent a8c2bec commit 013fe12
Show file tree
Hide file tree
Showing 47 changed files with 1,286 additions and 1,144 deletions.
4 changes: 1 addition & 3 deletions Cpp/fost-csj/iterator.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@
FSL_TEST_SUITE(csj_iterator);


FSL_TEST_FUNCTION(one_line) {
}

FSL_TEST_FUNCTION(one_line) {}
59 changes: 29 additions & 30 deletions Cpp/fost-csj/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@


namespace {
template<typename P, typename Iter, typename Vec> inline
void parseline(
const P &parser, Iter &pos, Iter end, Vec &into
) {
template<typename P, typename Iter, typename Vec>
inline void parseline(const P &parser, Iter &pos, Iter end, Vec &into) {
into.clear();
if ( pos != end ) {
auto line_pos = f5::make_u32u16_iterator((*pos).begin(), (*pos).end());
if ( not boost::spirit::qi::parse(line_pos.first, line_pos.second, parser, into)
|| line_pos.first != line_pos.second )
{
throw fostlib::exceptions::not_implemented(__func__,
"Could not parse row", *pos);
if (pos != end) {
auto line_pos =
f5::make_u32u16_iterator((*pos).begin(), (*pos).end());
if (not boost::spirit::qi::parse(
line_pos.first, line_pos.second, parser, into)
|| line_pos.first != line_pos.second) {
throw fostlib::exceptions::not_implemented(
__func__, "Could not parse row", *pos);
}
}
}
Expand All @@ -36,13 +35,12 @@ namespace {

fostlib::csj::parser::parser(f5::u8view str)
: line_iter(splitter(str, '\n')),
li_pos(line_iter.begin()),
li_end(line_iter.end())
{
li_pos(line_iter.begin()),
li_end(line_iter.end()) {
parseline(headers_p, li_pos, li_end, headers);
if ( not headers.size() ) {
throw exceptions::not_implemented(__func__,
"No headers were found when parsing CSJ");
if (not headers.size()) {
throw exceptions::not_implemented(
__func__, "No headers were found when parsing CSJ");
}
++li_pos;
}
Expand All @@ -62,36 +60,37 @@ fostlib::csj::parser::const_iterator fostlib::csj::parser::end() const {


fostlib::csj::parser::const_iterator::const_iterator(
const parser &o, line_iter_t::const_iterator p
) : owner(o), pos(p) {
const parser &o, line_iter_t::const_iterator p)
: owner(o), pos(p) {
parseline(owner.line_p, pos, owner.li_end, line);
}


fostlib::csj::parser::const_iterator &fostlib::csj::parser::const_iterator::operator ++ () {
fostlib::csj::parser::const_iterator &fostlib::csj::parser::const_iterator::
operator++() {
parseline(owner.line_p, ++pos, owner.li_end, line);
if ( not line.size() ) {
if (not line.size()) {
// We've hit a blank line. Make sure we only get them from now on
while ( pos != owner.li_end ) {
while (pos != owner.li_end) {
parseline(owner.line_p, ++pos, owner.li_end, line);
if ( line.size() ) {
throw exceptions::not_implemented(__func__,
"Empty line embedded in CSJ file");
if (line.size()) {
throw exceptions::not_implemented(
__func__, "Empty line embedded in CSJ file");
}
}
} else if ( line.size() != owner.header().size() ) {
throw fostlib::exceptions::not_implemented(__func__,
"Number of columns didn't match number of headers", line);
} else if (line.size() != owner.header().size()) {
throw fostlib::exceptions::not_implemented(
__func__, "Number of columns didn't match number of headers",
line);
}
return *this;
}


fostlib::json fostlib::csj::parser::const_iterator::as_json() const {
fostlib::json row;
for ( std::size_t c{}; c != line.size(); ++c ) {
for (std::size_t c{}; c != line.size(); ++c) {
fostlib::insert(row, owner.header()[c], line[c]);
}
return row;
}

11 changes: 7 additions & 4 deletions Cpp/fost-csj/parser.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ FSL_TEST_FUNCTION(one_line_trailing_new_line) {


FSL_TEST_FUNCTION(one_line_trailing_new_lines) {
fostlib::utf8_string str("\"h1\",\"h2\",\"h3\",\"h4\",\"h5\"\n1,2,3,4,5\n\n\n");
fostlib::utf8_string str(
"\"h1\",\"h2\",\"h3\",\"h4\",\"h5\"\n1,2,3,4,5\n\n\n");
fostlib::csj::parser csj(str);
auto line = *(csj.begin());
FSL_CHECK_EQ(line.size(), 5u);
Expand All @@ -67,7 +68,8 @@ FSL_TEST_FUNCTION(one_line_trailing_new_lines) {


FSL_TEST_FUNCTION(two_lines) {
fostlib::utf8_string str("\"h1\",\"h2\",\"h3\",\"h4\",\"h5\"\n1,2,3,4,5\n6,7,8,9,10");
fostlib::utf8_string str(
"\"h1\",\"h2\",\"h3\",\"h4\",\"h5\"\n1,2,3,4,5\n6,7,8,9,10");
fostlib::csj::parser csj(str);
auto line = *(++csj.begin());
FSL_CHECK_EQ(line.size(), 5u);
Expand All @@ -82,7 +84,9 @@ FSL_TEST_FUNCTION(two_lines) {


FSL_TEST_FUNCTION(two_lines_and_spaces) {
fostlib::utf8_string str("\"h1\",\"h2\",\"h3\",\"h4\",\"h5\"\n1,2, 3, 4,5\n6,7, \"8\",9,10\n");
fostlib::utf8_string str(
"\"h1\",\"h2\",\"h3\",\"h4\",\"h5\"\n1,2, 3, 4,5\n6,7, "
"\"8\",9,10\n");
fostlib::csj::parser csj(str);
auto line = *(++csj.begin());
FSL_CHECK_EQ(line.size(), 5u);
Expand All @@ -94,4 +98,3 @@ FSL_TEST_FUNCTION(two_lines_and_spaces) {
FSL_CHECK_EQ(*(iter++), fostlib::json(10));
FSL_CHECK(iter == line.end());
}

10 changes: 4 additions & 6 deletions Cpp/fostgres-core/dbconnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@


fostlib::pg::connection fostgres::connection(
const fostlib::json &config,
const fostlib::nullable<fostlib::string> &zoneinfo,
const fostlib::nullable<fostlib::string> &/*subrole*/
const fostlib::json &config,
const fostlib::nullable<fostlib::string> &zoneinfo,
const fostlib::nullable<fostlib::string> & /*subrole*/
) {
fostlib::pg::connection cnx(config);
if ( zoneinfo ) {
cnx.zoneinfo(zoneinfo.value());
}
if (zoneinfo) { cnx.zoneinfo(zoneinfo.value()); }
return cnx;
}
1 change: 0 additions & 1 deletion Cpp/fostgres-core/fostgres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@


const fostlib::module fostgres::c_fostgres("fostgres");

35 changes: 17 additions & 18 deletions Cpp/fostgres-core/iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ namespace {
std::vector<fostlib::string> columns(const RS &rs) {
std::vector<fostlib::string> cols;
std::size_t number{0};
for ( const auto &c : rs.columns() ) {
for (const auto &c : rs.columns()) {
cols.push_back(c.value_or("un-named." + std::to_string(++number)));
}
return cols;
}
}


std::pair<std::vector<fostlib::string>, fostlib::pg::recordset> fostgres::column_names(
fostlib::pg::recordset && rs
) {
std::pair<std::vector<fostlib::string>, fostlib::pg::recordset>
fostgres::column_names(fostlib::pg::recordset &&rs) {
return std::make_pair(columns(rs), std::move(rs));
}

Expand All @@ -39,12 +38,13 @@ std::pair<std::vector<fostlib::string>, fostlib::pg::recordset> fostgres::column
*/


fostgres::json_recordset::json_recordset(std::pair<std::vector<fostlib::string>, fostlib::pg::recordset> rs)
: names(std::move(rs.first)), rs(std::move(rs.second)) {
}
fostgres::json_recordset::json_recordset(
std::pair<std::vector<fostlib::string>, fostlib::pg::recordset> rs)
: names(std::move(rs.first)), rs(std::move(rs.second)) {}


fostgres::json_recordset::const_iterator fostgres::json_recordset::begin() const {
fostgres::json_recordset::const_iterator
fostgres::json_recordset::begin() const {
return {names, rs.begin()};
}

Expand All @@ -60,27 +60,26 @@ fostgres::json_recordset::const_iterator fostgres::json_recordset::end() const {


fostgres::json_recordset::const_iterator::const_iterator(
const std::vector<fostlib::string> &n,
fostlib::pg::recordset::const_iterator p)
: names(&n), pos(std::move(p)) {
}
const std::vector<fostlib::string> &n,
fostlib::pg::recordset::const_iterator p)
: names(&n), pos(std::move(p)) {}


fostgres::json_recordset::const_iterator &fostgres::json_recordset::const_iterator::operator ++ () {
fostgres::json_recordset::const_iterator &
fostgres::json_recordset::const_iterator::operator++() {
++pos;
return *this;
}


fostlib::json::object_t &fostgres::json_recordset::const_iterator::operator * () {
if ( not names ) {
fostlib::json::object_t &fostgres::json_recordset::const_iterator::operator*() {
if (not names) {
throw fostlib::exceptions::null(
"Can't dereference an empty json_recordset::const_iterator");
"Can't dereference an empty json_recordset::const_iterator");
}
const auto &row = *pos;
for ( std::size_t index{}; index < names->size(); ++index ) {
for (std::size_t index{}; index < names->size(); ++index) {
object[(*names)[index]] = row[index];
}
return object;
}

38 changes: 20 additions & 18 deletions Cpp/fostgres-fg/contains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,52 @@


namespace {
fostlib::nullable<fostlib::jcursor> walk(
fostlib::jcursor &path, const fostlib::json &super, const fostlib::json &sub
) {
if ( sub.isnull() || sub.isatom() || sub.isarray() ) {
if ( super[path] == sub ) {
fostlib::nullable<fostlib::jcursor>
walk(fostlib::jcursor &path,
const fostlib::json &super,
const fostlib::json &sub) {
if (sub.isnull() || sub.isatom() || sub.isarray()) {
if (super[path] == sub) {
return fostlib::null;
} else {
return path;
}
} else if ( sub.isobject() ) {
for ( fostlib::json::const_iterator p(sub.begin()); p != sub.end(); ++p ) {
} else if (sub.isobject()) {
for (fostlib::json::const_iterator p(sub.begin()); p != sub.end();
++p) {
path /= p.key();
if ( super.has_key(path) ) {
if (super.has_key(path)) {
auto part = walk(path, super, *p);
if ( part ) return path;
if (part) return path;
} else {
if ( *p != fostlib::json() ) {
return path;
}
if (*p != fostlib::json()) { return path; }
}
path.pop();
}
} else {
throw fostlib::exceptions::not_implemented(__func__,
"Can't walk across ths sub-object", sub);
throw fostlib::exceptions::not_implemented(
__func__, "Can't walk across ths sub-object", sub);
}
return fostlib::null;
}
}


fostlib::nullable<fostlib::jcursor> fg::contains(const fg::json &super, const fg::json &sub) {
fostlib::nullable<fostlib::jcursor>
fg::contains(const fg::json &super, const fg::json &sub) {
fostlib::jcursor path;
return walk(path, super, sub);
}


void fg::throw_contains_error(fg::json actual, fg::json expected, fg::jcursor contains) {
fostlib::exceptions::test_failure error("Mismatched response body", __FILE__, __LINE__);
void fg::throw_contains_error(
fg::json actual, fg::json expected, fg::jcursor contains) {
fostlib::exceptions::test_failure error(
"Mismatched response body", __FILE__, __LINE__);
fostlib::insert(error.data(), "expected", expected);
fostlib::insert(error.data(), "actual", actual);
fostlib::insert(error.data(), "mismatch", "path", contains);
fostlib::insert(error.data(), "mismatch", "expected", expected[contains]);
fostlib::insert(error.data(), "mismatch", "actual", actual[contains]);
throw error;
}

20 changes: 9 additions & 11 deletions Cpp/fostgres-fg/fg.builtin.checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
#include <fostgres/fg/fg.hpp>


fg::frame::builtin fg::lib::contains =
[](fg::frame &stack, fg::json::const_iterator pos, fg::json::const_iterator end) {
auto data = stack.resolve(stack.argument("data", pos, end));
auto check = stack.resolve(stack.argument("check", pos, end));
auto result = fg::contains(data, check);
if ( result ) {
throw_contains_error(data, check, result.value());
}
return data;
};

fg::frame::builtin fg::lib::contains = [](fg::frame &stack,
fg::json::const_iterator pos,
fg::json::const_iterator end) {
auto data = stack.resolve(stack.argument("data", pos, end));
auto check = stack.resolve(stack.argument("check", pos, end));
auto result = fg::contains(data, check);
if (result) { throw_contains_error(data, check, result.value()); }
return data;
};
Loading

0 comments on commit 013fe12

Please sign in to comment.