Skip to content

Commit

Permalink
Make namespace std clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Apr 18, 2024
1 parent 7323075 commit 9fb3ef7
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 167 deletions.
179 changes: 89 additions & 90 deletions changes/modifications.cpp

Large diffs are not rendered by default.

31 changes: 15 additions & 16 deletions changes/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
#include <locale/translate.h>
#include <locale/logic.h>
#include <database/statistics.h>
using namespace std;


// Internal function declarations.
void changes_statistics_add (Assets_View & view, const string & date, int count);
void changes_statistics_add (Assets_View& view, const std::string& date, int count);


string changes_statistics_url ()
std::string changes_statistics_url ()
{
return "changes/statistics";
}
Expand All @@ -47,41 +46,41 @@ bool changes_statistics_acl (Webserver_Request& webserver_request)
}


void changes_statistics_add (Assets_View& view, const string& date, int count)
void changes_statistics_add (Assets_View& view, const std::string& date, int count)
{
if (count) {
map <string, string> values;
std::map <std::string, std::string> values;
values ["date"] = date;
values ["count"] = filter::strings::convert_to_string (count);
view.add_iteration ("statistics", values);
}
}


string changes_statistics ([[maybe_unused]] Webserver_Request& webserver_request)
std::string changes_statistics ([[maybe_unused]] Webserver_Request& webserver_request)
{
#ifdef HAVE_CLIENT
return string();
return std::string();
#endif

#ifdef HAVE_CLOUD

string page {};
std::string page {};
Assets_Header header = Assets_Header (translate("Change statistics"), webserver_request);
page += header.run ();
Assets_View view {};


string everyone = translate ("Everyone");
string user = webserver_request.query["user"];
const std::string everyone = translate ("Everyone");
std::string user = webserver_request.query["user"];
if (user == everyone) user.clear ();


vector <pair <int, int>> changes = Database_Statistics::get_changes (user);
string last_date {};
std::vector <std::pair <int, int>> changes = Database_Statistics::get_changes (user);
std::string last_date {};
int last_count {0};
for (const auto & element : changes) {
const string date = locale_logic_date (element.first);
for (const auto& element : changes) {
const std::string date = locale_logic_date (element.first);
const int count = element.second;
if (date == last_date) {
last_count += count;
Expand All @@ -96,10 +95,10 @@ string changes_statistics ([[maybe_unused]] Webserver_Request& webserver_request
}


vector <string> users = Database_Statistics::get_users ();
std::vector <std::string> users = Database_Statistics::get_users ();
users.push_back (everyone);
for (size_t i = 0; i < users.size (); i++) {
map <string, string> values;
std::map <std::string, std::string> values;
if (i) values ["divider"] = "|";
values ["user"] = users[i];
view.add_iteration ("users", values);
Expand Down
49 changes: 24 additions & 25 deletions checks/french.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,55 @@
#include <filter/usfm.h>
#include <database/check.h>
#include <locale/translate.h>
using namespace std;


// In French there is a no-break space after the « and before the » ! ? : ;
// The Unicode value for the no-break space is U+00A0.
// Another type of non-breaking space will be acceptable too.
void checks_french::space_before_after_punctuation (const string & bible, int book, int chapter,
const map <int, string> & texts)
void checks_french::space_before_after_punctuation (const std::string& bible, int book, int chapter,
const std::map <int, std::string>& texts)
{
Database_Check database_check {};
string nbsp = filter::strings::non_breaking_space_u00A0 ();
string nnbsp = filter::strings::narrow_non_breaking_space_u202F ();
vector <string> right_punctuation = { right_guillemet(), "!", "?", ":", ";" };
const std::string nbsp = filter::strings::non_breaking_space_u00A0 ();
const std::string nnbsp = filter::strings::narrow_non_breaking_space_u202F ();
const std::vector <std::string> right_punctuation = { right_guillemet(), "!", "?", ":", ";" };
for (const auto & element : texts) {
int verse = element.first;

{
string text = element.second;
std::string text = element.second;
size_t pos = text.find (left_guillemet ());
while (pos != std::string::npos) {
text.erase (0, pos + left_guillemet ().size ());
bool space_follows = text.find (" ") == 0;
bool nbsp_follows = text.find (nbsp) == 0;
bool nnbsp_follows = text.find (nnbsp) == 0;
if (space_follows) {
string message = left_guillemet () + " - " + translate ("Should be followed by a no-break space rather than a plain space in French");
const std::string message = left_guillemet () + " - " + translate ("Should be followed by a no-break space rather than a plain space in French");
database_check.recordOutput (bible, book, chapter, verse, message);
} else if (!nbsp_follows && !nnbsp_follows) {
string message = left_guillemet () + " - " + translate ("Should be followed by a no-break space in French");
const std::string message = left_guillemet () + " - " + translate ("Should be followed by a no-break space in French");
database_check.recordOutput (bible, book, chapter, verse, message);
}
pos = text.find (left_guillemet ());
}
}

for (const auto & punctuation : right_punctuation) {
string text = element.second;
std::string text = element.second;
// The location of this punctuation character.
size_t pos = filter::strings::unicode_string_strpos (text, punctuation);
while (pos != std::string::npos) {
if (pos > 0) {
string preceding_character = filter::strings::unicode_string_substr (text, pos - 1, 1);
const std::string preceding_character = filter::strings::unicode_string_substr (text, pos - 1, 1);
if (preceding_character == " ") {
string message = punctuation + " - " + translate ("Should be preceded by a no-break space rather than a plain space in French");
const std::string message = punctuation + " - " + translate ("Should be preceded by a no-break space rather than a plain space in French");
database_check.recordOutput (bible, book, chapter, verse, message);
}
else if (preceding_character == nbsp) { /* This is OK. */ }
else if (preceding_character == nnbsp) { /* This is OK. */ }
else {
string message = punctuation + " - " + translate ("Should be preceded by a no-break space in French");
const std::string message = punctuation + " - " + translate ("Should be preceded by a no-break space in French");
database_check.recordOutput (bible, book, chapter, verse, message);
}
}
Expand All @@ -90,8 +89,8 @@ void checks_french::space_before_after_punctuation (const string & bible, int bo
// « This is the text of the citation.
// « This is a new paragraph, and it ends the citation ».
// This checks on that style.
void checks_french::citation_style (const string & bible, int book, int chapter,
const vector <map <int, string>> & verses_paragraphs)
void checks_french::citation_style (const std::string & bible, int book, int chapter,
const std::vector <std::map <int, std::string>>& verses_paragraphs)
{
Database_Check database_check {};

Expand All @@ -103,7 +102,7 @@ void checks_french::citation_style (const string & bible, int book, int chapter,
for (unsigned int paragraph_counter = 0; paragraph_counter < verses_paragraphs.size (); paragraph_counter++) {

// Container with verse numbers as the keys, plus the text of the whole paragraph.
const map <int, string> verses_paragraph = verses_paragraphs [paragraph_counter];
const std::map <int, std::string> verses_paragraph = verses_paragraphs [paragraph_counter];

// Skip empty containers.
if (verses_paragraph.empty ()) continue;
Expand All @@ -114,11 +113,11 @@ void checks_french::citation_style (const string & bible, int book, int chapter,
if (paragraph_counter) {
if (previous_paragraph_open_citation) {
int verse = verses_paragraph.begin()->first;
string text = verses_paragraph.begin()->second;
const std::string text = verses_paragraph.begin()->second;
if (!text.empty ()) {
string character = filter::strings::unicode_string_substr (text, 0, 1);
const std::string character = filter::strings::unicode_string_substr (text, 0, 1);
if (character != left_guillemet ()) {
string message = translate ("The previous paragraph contains a citation not closed with a » therefore the current paragraph is expected to start with a « to continue that citation in French");
const std::string message = translate ("The previous paragraph contains a citation not closed with a » therefore the current paragraph is expected to start with a « to continue that citation in French");
database_check.recordOutput (bible, book, chapter, verse, message);
}
}
Expand All @@ -127,8 +126,8 @@ void checks_french::citation_style (const string & bible, int book, int chapter,

// Count the number of left and right guillements in the paragraph.
int last_verse {0};
string paragraph {};
for (const auto & element : verses_paragraph) {
std::string paragraph {};
for (const auto& element : verses_paragraph) {
paragraph.append (element.second);
last_verse = element.first;
}
Expand All @@ -142,26 +141,26 @@ void checks_french::citation_style (const string & bible, int book, int chapter,

// Whether there's too many left guillements.
if (opener_count > (closer_count + 1)) {
string message = translate ("The paragraph contains more left guillements than needed");
const std::string message = translate ("The paragraph contains more left guillements than needed");
database_check.recordOutput (bible, book, chapter, last_verse, message);
}

// Whether there's too many right guillements.
if (closer_count > opener_count) {
string message = translate ("The paragraph contains more right guillements than needed");
const std::string message = translate ("The paragraph contains more right guillements than needed");
database_check.recordOutput (bible, book, chapter, last_verse, message);
}
}
}


string checks_french::left_guillemet ()
std::string checks_french::left_guillemet ()
{
return "«";
}


string checks_french::right_guillemet ()
std::string checks_french::right_guillemet ()
{
return "»";
}
11 changes: 5 additions & 6 deletions checks/headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@
#include <filter/string.h>
#include <database/check.h>
#include <locale/translate.h>
using namespace std;


void checks_headers::no_punctuation_at_end (const string & bible, int book, int chapter,
const map <int, string> & headings,
const string & centermarks, const string & endmarks)
void checks_headers::no_punctuation_at_end (const std::string& bible, int book, int chapter,
const std::map <int, std::string>& headings,
const std::string& centermarks, const std::string& endmarks)
{
Database_Check database_check {};
for (const auto & element : headings) {
int verse = element.first;
string heading = element.second;
const std::string heading = element.second;
// Full stops often occur in the inspired headings of many Psalms in verse 0.
// Skip these.
if ((book == 19) && (verse == 0)) continue;
string last_character {};
std::string last_character {};
if (!heading.empty ()) last_character = heading.substr (heading.size () - 1);
bool message {false};
if (centermarks.find (last_character) != std::string::npos) message = true;
Expand Down
9 changes: 4 additions & 5 deletions checks/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@
#include <database/bibles.h>
#include <database/config/bible.h>
#include <tasks/logic.h>
using namespace std;


void checks_logic_start_all ()
{
Database_Bibles database_bibles {};
const vector <string> & bibles = database_bibles.get_bibles ();
for (const auto & bible : bibles) {
bool enabled = Database_Config_Bible::getDailyChecksEnabled (bible);
const std::vector <std::string>& bibles = database_bibles.get_bibles ();
for (const auto& bible : bibles) {
const bool enabled = Database_Config_Bible::getDailyChecksEnabled (bible);
if (enabled) checks_logic_start (bible);
}
}


void checks_logic_start (const string & bible)
void checks_logic_start (const std::string& bible)
{
tasks_logic_queue (CHECKBIBLE, {bible});
}
49 changes: 24 additions & 25 deletions checks/pairs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,27 @@
#include <database/check.h>
#include <locale/translate.h>
#include <checks/french.h>
using namespace std;


void checks_pairs::run (const string & bible, int book, int chapter,
const map <int, string> & texts,
const vector <pair <string, string> > & pairs,
void checks_pairs::run (const std::string& bible, int book, int chapter,
const std::map <int, std::string> & texts,
const std::vector <std::pair <std::string, std::string>>& pairs,
bool french_citation_style)
{
// This holds the opener characters of the pairs which were opened in the text.
// For example, it may hold the "[".
vector <int> verses {};
vector <string> opened {};
std::vector <int> verses {};
std::vector <std::string> opened {};

// Containers with the openers and the closers.
// If the check on the French citation style is active,
// skip the French guillemets.
vector <string> openers {};
vector <string> closers {};
for (const auto & element : pairs) {
string opener = element.first;
std::vector <std::string> openers {};
std::vector <std::string> closers {};
for (const auto& element : pairs) {
const std::string opener = element.first;
if (french_citation_style && (opener == checks_french::left_guillemet ())) continue;
string closer = element.second;
const std::string closer = element.second;
if (french_citation_style && (opener == checks_french::right_guillemet ())) continue;
openers.push_back (opener);
closers.push_back (closer);
Expand All @@ -55,11 +54,11 @@ void checks_pairs::run (const string & bible, int book, int chapter,
// Go through the verses with their texts.
for (const auto & element : texts) {
int verse = element.first;
string text = element.second;
std::string text = element.second;
size_t length = filter::strings::unicode_string_length (text);
for (size_t pos = 0; pos < length; pos++) {

string character = filter::strings::unicode_string_substr (text, pos, 1);
const std::string character = filter::strings::unicode_string_substr (text, pos, 1);

if (in_array (character, openers)) {
verses.push_back (verse);
Expand All @@ -68,7 +67,7 @@ void checks_pairs::run (const string & bible, int book, int chapter,

if (in_array (character, closers)) {

string opener = match (character, pairs);
const std::string opener = match (character, pairs);
bool mismatch = false;
if (opened.empty ()) {
mismatch = true;
Expand All @@ -79,9 +78,9 @@ void checks_pairs::run (const string & bible, int book, int chapter,
mismatch = true;
}
if (mismatch) {
string fragment1 = translate ("Closing character");
string fragment2 = translate ("without its matching opening character");
stringstream message;
const std::string fragment1 = translate ("Closing character");
const std::string fragment2 = translate ("without its matching opening character");
std::stringstream message {};
message << fragment1 << " " << quoted(character) << " " << fragment2 << " " << quoted(opener);
database_check.recordOutput (bible, book, chapter, verse, message.str());
}
Expand All @@ -92,22 +91,22 @@ void checks_pairs::run (const string & bible, int book, int chapter,
// Report unclosed openers.
for (size_t i = 0; i < verses.size (); i++) {
int verse = verses [i];
string opener = opened [i];
string closer = match (opener, pairs);
string fragment1 = translate ("Opening character");
string fragment2 = translate ("without its matching closing character");
stringstream message;
const std::string opener = opened [i];
const std::string closer = match (opener, pairs);
const std::string fragment1 = translate ("Opening character");
const std::string fragment2 = translate ("without its matching closing character");
std::stringstream message {};
message << fragment1 << " " << quoted(opener) << " " << fragment2 << " " << quoted(closer);
database_check.recordOutput (bible, book, chapter, verse, message.str());
}
}


string checks_pairs::match (const string & character, const vector <pair <string, string> > & pairs)
std::string checks_pairs::match (const std::string & character, const std::vector <std::pair <std::string, std::string>>& pairs)
{
for (auto & element : pairs) {
for (const auto& element : pairs) {
if (character == element.first) return element.second;
if (character == element.second) return element.first;
}
return string();
return std::string();
}
1 change: 1 addition & 0 deletions pkgdata/files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
/jsonxx/LICENSE
/ldap
/lexicon
/libbibledit.a.yHm3kK
/library
/livetest
/livetest/initialize.sh
Expand Down

0 comments on commit 9fb3ef7

Please sign in to comment.