Skip to content

Commit

Permalink
Make namespace std explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Apr 16, 2024
1 parent 7bddd2f commit 7323075
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 120 deletions.
24 changes: 12 additions & 12 deletions book/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
#include <locale/translate.h>
#include <bb/logic.h>
#include <filter/string.h>
using namespace std;


// Creates book template with ID $book in Bible $bible.
// If a $chapter is given instead of -1, it creates that chapter only.
// If the $chapter is -1, it creates all chapters within that book.
bool book_create (const string & bible, const book_id book, const int chapter, vector <string> & feedback)
bool book_create (const std::string & bible, const book_id book, const int chapter,
std::vector<std::string>& feedback)
{
Database_Bibles database_bibles {};
Database_Versifications database_versifications {};

vector <string> bibles = database_bibles.get_bibles ();
const std::vector <std::string> bibles = database_bibles.get_bibles ();
if (!in_array (bible, bibles)) {
feedback.push_back (translate("Bible bible does not exist: Cannot create book"));
return false;
Expand All @@ -49,10 +49,10 @@ bool book_create (const string & bible, const book_id book, const int chapter, v
}

// The chapters that have been created.
vector <int> chapters_created {};
std::vector <int> chapters_created {};

// The USFM created.
string data {};
std::string data {};

// Chapter 0.
if (chapter <= 0) {
Expand All @@ -65,12 +65,12 @@ bool book_create (const string & bible, const book_id book, const int chapter, v


// Subsequent chapters.
string versification = Database_Config_Bible::getVersificationSystem (bible);
vector <Passage> versification_data = database_versifications.getBooksChaptersVerses (versification);
for (const auto & row : versification_data) {
const std::string versification = Database_Config_Bible::getVersificationSystem (bible);
const std::vector <Passage> versification_data = database_versifications.getBooksChaptersVerses (versification);
for (const auto& row : versification_data) {
if (book == static_cast<book_id>(row.m_book)) {
int ch = row.m_chapter;
int verse = filter::strings::convert_to_int (row.m_verse);
const int ch = row.m_chapter;
const int verse = filter::strings::convert_to_int (row.m_verse);
if ((chapter < 0) || (chapter == ch)) {
data = "\\c " + filter::strings::convert_to_string (ch) + "\n";
data += "\\p\n";
Expand All @@ -88,8 +88,8 @@ bool book_create (const string & bible, const book_id book, const int chapter, v
feedback.push_back (translate("No chapters have been created"));
return false;
}
string created;
for (auto & chapter_created : chapters_created) {
std::string created;
for (const auto& chapter_created : chapters_created) {
if (!created.empty ()) created.append (" ");
created.append (filter::strings::convert_to_string (chapter_created));
}
Expand Down
73 changes: 36 additions & 37 deletions changes/change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@
#include <pugixml.hpp>
#endif
#pragma GCC diagnostic pop
using namespace std;


string changes_change_url ()
std::string changes_change_url ()
{
return "changes/change";
}
Expand All @@ -61,7 +60,7 @@ bool changes_change_acl (Webserver_Request& webserver_request)
}


string changes_change (Webserver_Request& webserver_request)
std::string changes_change (Webserver_Request& webserver_request)
{
Database_Modifications database_modifications {};
Database_Notes database_notes (webserver_request);
Expand All @@ -70,35 +69,35 @@ string changes_change (Webserver_Request& webserver_request)

// Note unsubscribe handler.
if (webserver_request.post.count ("unsubscribe")) {
string unsubscribe = webserver_request.post["unsubscribe"];
std::string unsubscribe = webserver_request.post["unsubscribe"];
unsubscribe.erase (0, 11);
notes_logic.unsubscribe (filter::strings::convert_to_int (unsubscribe));
return string();
return std::string();
}


// Note unassign handler.
if (webserver_request.post.count ("unassign")) {
string unassign = webserver_request.post["unassign"];
std::string unassign = webserver_request.post["unassign"];
unassign.erase (0, 8);
notes_logic.unassignUser (filter::strings::convert_to_int (unassign), webserver_request.session_logic()->currentUser ());
return string();
return std::string();
}


// Note mark for deletion handler.
if (webserver_request.post.count("delete")) {
string erase = webserver_request.post["delete"];
std::string erase = webserver_request.post["delete"];
erase.erase (0, 6);
const int identifier {filter::strings::convert_to_int (erase)};
notes_logic.markForDeletion (identifier);
return string();
return std::string();
}


// From here on the script will produce output.
Assets_View view {};
const string username {webserver_request.session_logic()->currentUser ()};
const std::string username {webserver_request.session_logic()->currentUser ()};
const int level {webserver_request.session_logic ()->currentLevel ()};


Expand All @@ -108,39 +107,39 @@ string changes_change (Webserver_Request& webserver_request)


// Get old text, modification, new text, date.
const string old_text {database_modifications.getNotificationOldText (id)};
const std::string old_text {database_modifications.getNotificationOldText (id)};
view.set_variable ("old_text", old_text);
const string modification {database_modifications.getNotificationModification (id)};
const std::string modification {database_modifications.getNotificationModification (id)};
view.set_variable ("modification", modification);
const string new_text {database_modifications.getNotificationNewText (id)};
const std::string new_text {database_modifications.getNotificationNewText (id)};
view.set_variable ("new_text", new_text);
const string date {locale_logic_date (database_modifications.getNotificationTimeStamp (id))};
const std::string date {locale_logic_date (database_modifications.getNotificationTimeStamp (id))};
view.set_variable ("date", date);


// Bibles and passage.
const Passage passage {database_modifications.getNotificationPassage (id)};
const vector <string> bibles {access_bible::bibles (webserver_request)};
const std::vector<std::string> bibles {access_bible::bibles (webserver_request)};


// Get notes for the passage.
vector <int> notes = database_notes.select_notes (bibles, // Bibles.
passage.m_book, passage.m_chapter, filter::strings::convert_to_int (passage.m_verse),
0, // Passage selector.
0, // Edit selector.
0, // Non-edit selector.
"", // Status selector.
"", // Bible selector.
"", // Assignment selector.
0, // Subscription selector.
-1, // Severity selector.
0, // Text selector.
"", // Search text.
-1); // Limit.
std::vector<int> notes = database_notes.select_notes (bibles, // Bibles.
passage.m_book, passage.m_chapter, filter::strings::convert_to_int (passage.m_verse),
0, // Passage selector.
0, // Edit selector.
0, // Non-edit selector.
"", // Status selector.
"", // Bible selector.
"", // Assignment selector.
0, // Subscription selector.
-1, // Severity selector.
0, // Text selector.
"", // Search text.
-1); // Limit.

// Remove the ones marked for deletion.
{
vector <int> notes2;
std::vector <int> notes2;
for (const auto note : notes) {
if (!database_notes.is_marked_for_deletion (note)) {
notes2.push_back (note);
Expand All @@ -150,17 +149,17 @@ string changes_change (Webserver_Request& webserver_request)
}

// Sort them, most recent notes first.
vector <int> timestamps;
std::vector <int> timestamps {};
for (const auto note : notes) {
int timestap = database_notes.get_modified (note);
const int timestap = database_notes.get_modified (note);
timestamps.push_back (timestap);
}
filter::strings::quick_sort (timestamps, notes, 0, static_cast <unsigned int> (notes.size ()));
reverse (notes.begin(), notes.end());


// Whether there"s a live notes editor available.
bool live_notes_editor = Ipc_Notes::alive (webserver_request, false);
const bool live_notes_editor = Ipc_Notes::alive (webserver_request, false);
if (live_notes_editor)
view.enable_zone ("alive");
else
Expand All @@ -170,14 +169,14 @@ string changes_change (Webserver_Request& webserver_request)
// Details for the notes.
pugi::xml_document notes_document {};
for (const auto note : notes) {
string summary = database_notes.get_summary (note);
std::string summary = database_notes.get_summary (note);
summary = filter::strings::escape_special_xml_characters (summary);
bool subscription = database_notes.is_subscribed (note, username);
bool assignment = database_notes.is_assigned (note, username);
const bool subscription = database_notes.is_subscribed (note, username);
const bool assignment = database_notes.is_assigned (note, username);
pugi::xml_node tr_node = notes_document.append_child("tr");
pugi::xml_node td_node = tr_node.append_child("td");
pugi::xml_node a_node = td_node.append_child("a");
string href {};
std::string href {};
if (live_notes_editor) {
a_node.append_attribute("class") = "opennote";
href = filter::strings::convert_to_string (note);
Expand Down Expand Up @@ -205,7 +204,7 @@ string changes_change (Webserver_Request& webserver_request)
a_node2.text().set(("[" + translate("mark for deletion") + "]").c_str());
}
}
stringstream notesblock {};
std::stringstream notesblock {};
notes_document.print(notesblock, "", pugi::format_raw);
view.set_variable ("notesblock", notesblock.str());

Expand Down
Loading

0 comments on commit 7323075

Please sign in to comment.