Skip to content

Commit

Permalink
Make std:: namespace more clear in code
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Apr 18, 2024
1 parent 813e19f commit 0e3cf1e
Show file tree
Hide file tree
Showing 104 changed files with 473 additions and 474 deletions.
45 changes: 22 additions & 23 deletions checks/sentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <webserver/request.h>
#include <filter/string.h>
#include <locale/translate.h>
using namespace std;


void Checks_Sentences::enter_capitals (const std::string& capitals)
Expand Down Expand Up @@ -54,7 +53,7 @@ void Checks_Sentences::enter_disregards (const std::string& disregards)
}


void Checks_Sentences::enter_names (string names)
void Checks_Sentences::enter_names (std::string names)
{
m_names.clear ();
names = filter::strings::replace ("\n", " ", names);
Expand Down Expand Up @@ -84,14 +83,14 @@ void Checks_Sentences::initialize ()
}


void Checks_Sentences::check (const std::map <int, string> & texts)
void Checks_Sentences::check (const std::map <int, std::string> & texts)
{
std::vector <int> verse_numbers {};
std::vector <std::string> characters {};
int iterations {0};
for (const auto & element : texts) {
int verse = element.first;
string text = element.second;
std::string text = element.second;
// For the second and subsequent verse_numbers, add a space to the text,
// because this is what is supposed to happen in USFM.
if (iterations > 0) {
Expand Down Expand Up @@ -181,22 +180,22 @@ void Checks_Sentences::check_character ()
// The USFM markers that start paragraphs that do not need to start with the correct capitalization.
// Usually such markers are poetic markers like \q1 and so on.
// $verses_paragraphs: The entire paragraphs, with verse number as their keys.
void Checks_Sentences::paragraphs (const std::vector <string> & paragraph_start_markers,
const std::vector <string> & within_sentence_paragraph_markers,
const std::vector <map <int, string>> & verses_paragraphs)
void Checks_Sentences::paragraphs (const std::vector <std::string>& paragraph_start_markers,
const std::vector <std::string>& within_sentence_paragraph_markers,
const std::vector <std::map <int, std::string>>& verses_paragraphs)
{
// Iterate over the paragraphs.
for (unsigned int p = 0; p < verses_paragraphs.size (); p++) {

// Container with verse numbers and the whole paragraph.
const std::map <int, string> & verses_paragraph = verses_paragraphs [p];
const std::map <int, std::string> & verses_paragraph = verses_paragraphs [p];

// Skip empty container.
if (verses_paragraph.empty ()) continue;

// Get the first character of the paragraph.
int verse = verses_paragraph.begin()->first;
string character2 = verses_paragraph.begin()->second;
std::string character2 = verses_paragraph.begin()->second;
if (!character2.empty ()) {
character2 = filter::strings::unicode_string_substr (character2, 0, 1);
}
Expand All @@ -206,9 +205,9 @@ void Checks_Sentences::paragraphs (const std::vector <string> & paragraph_start_
if (!is_capital) {
const std::string& paragraph_marker = paragraph_start_markers [p];
if (!in_array (paragraph_marker, within_sentence_paragraph_markers)) {
string context = verses_paragraph.begin()->second;
std::string context = verses_paragraph.begin()->second;
context = filter::strings::unicode_string_substr (context, 0, 15);
checking_results.push_back (pair (verse, translate ("Paragraph does not start with a capital:") + " " + context));
checking_results.push_back (std::pair (verse, translate ("Paragraph does not start with a capital:") + " " + context));
}
}

Expand All @@ -219,9 +218,9 @@ void Checks_Sentences::paragraphs (const std::vector <string> & paragraph_start_
size_t length = filter::strings::unicode_string_length (character2);
character2 = filter::strings::unicode_string_substr (character2, length - 1, 1);
}
string previous_character = verses_paragraph.rbegin()->second;
std::string previous_character = verses_paragraph.rbegin()->second;
if (!previous_character.empty ()) {
size_t length = filter::strings::unicode_string_length (character2);
const size_t length = filter::strings::unicode_string_length (character2);
if (length >= 2) {
previous_character = filter::strings::unicode_string_substr (previous_character, length - 2, 1);
} else {
Expand All @@ -234,37 +233,37 @@ void Checks_Sentences::paragraphs (const std::vector <string> & paragraph_start_
if (!is_end_mark) {
// If the next paragraph starts with a marker that indicates it should not necessarily be capitalized,
// then the current paragraph may have punctuation that would be incorrect otherwise.
string next_paragraph_marker {};
std::string next_paragraph_marker {};
size_t p2 = p + 1;
if (p2 < paragraph_start_markers.size ()) {
next_paragraph_marker = paragraph_start_markers [p2];
}
if (next_paragraph_marker.empty () || (!in_array (next_paragraph_marker, within_sentence_paragraph_markers))) {
string context = verses_paragraph.rbegin()->second;
std::string context = verses_paragraph.rbegin()->second;
const size_t length = filter::strings::unicode_string_length (character2);
if (length >= 15) {
context = filter::strings::unicode_string_substr (context, length - 15, 15);
}
checking_results.push_back (pair (verse, translate ("Paragraph does not end with an end marker:") + " " + context));
checking_results.push_back (std::pair (verse, translate ("Paragraph does not end with an end marker:") + " " + context));
}
}

}
}


vector <pair<int, string>> Checks_Sentences::get_results ()
std::vector <std::pair<int, std::string>> Checks_Sentences::get_results ()
{
return checking_results;
}


void Checks_Sentences::add_result (string text, int modifier)
void Checks_Sentences::add_result (std::string text, int modifier)
{
// Get previous and next text fragment.
int start = current_position - 25;
if (start < 0) start = 0;
string previousFragment = filter::strings::unicode_string_substr (full_text, static_cast <size_t> (start), static_cast <size_t> (current_position - start - 1));
std::string previousFragment = filter::strings::unicode_string_substr (full_text, static_cast <size_t> (start), static_cast <size_t> (current_position - start - 1));
int iterations {5};
while (iterations) {
const size_t pos = previousFragment.find (" ");
Expand All @@ -275,16 +274,16 @@ void Checks_Sentences::add_result (string text, int modifier)
}
iterations--;
}
string nextFragment = filter::strings::unicode_string_substr (full_text, static_cast <size_t> (current_position), 25);
std::string nextFragment = filter::strings::unicode_string_substr (full_text, static_cast <size_t> (current_position), 25);
while (nextFragment.length () > 10) {
const size_t pos = nextFragment.rfind (" ");
if (pos == std::string::npos) nextFragment.erase (nextFragment.length () - 1, 1);
else nextFragment.erase (pos);
}
// Check whether the result can be skipped due to a name being involved.
if (modifier == skip_names) {
string haystack = character + nextFragment;
for (auto name : m_names) {
const std::string haystack = character + nextFragment;
for (const auto& name : m_names) {
if (haystack.find (name) == 0) return;
}
}
Expand All @@ -296,7 +295,7 @@ void Checks_Sentences::add_result (string text, int modifier)
text += ": " + previousFragment + character + nextFragment;
}
// Store checking result.
checking_results.push_back (pair (verse_number, text));
checking_results.push_back (std::pair (verse_number, text));
}


Expand Down
4 changes: 2 additions & 2 deletions checks/space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void double_space_usfm (const std::string& bible, int book, int chapter, int ver
}


void space_before_punctuation (const std::string& bible, int book, int chapter, const std::map <int, string> & texts)
void space_before_punctuation (const std::string& bible, int book, int chapter, const std::map <int, std::string> & texts)
{
Database_Check database_check {};
for (const auto & element : texts) {
Expand Down Expand Up @@ -103,7 +103,7 @@ bool transpose_note_space (string & usfm)
bool transposed {false};
const size_t pos = usfm.find(" ");
if (pos != std::string::npos) {
std::map <string, string> data = {
std::map <string, std::string> data = {
pair (R"(\fk )", R"( \fk )"),
pair (R"(\ft )", R"( \ft )"),
pair (R"(\xt )", R"( \xt )")
Expand Down
2 changes: 1 addition & 1 deletion checks/usfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void Checks_Usfm::figure ()
}


vector <pair<int, string>> Checks_Usfm::get_results ()
vector <std::pair<int, std::string>> Checks_Usfm::get_results ()
{
return checking_results;
}
Expand Down
10 changes: 5 additions & 5 deletions checks/verses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ using namespace std;


void checks_verses::missing_punctuation_at_end (const std::string& bible, int book, int chapter,
const std::map <int, string> & verses,
const std::map <int, std::string> & verses,
const std::string& center_marks, const std::string& end_marks,
const std::string& disregards)
{
const std::vector <string> centermarks = filter::strings::explode (center_marks, ' ');
const std::vector <string> endmarks = filter::strings::explode (end_marks, ' ');
const std::vector <string> ignores = filter::strings::explode (disregards, ' ');
const std::vector <std::string> centermarks = filter::strings::explode (center_marks, ' ');
const std::vector <std::string> endmarks = filter::strings::explode (end_marks, ' ');
const std::vector <std::string> ignores = filter::strings::explode (disregards, ' ');
Database_Check database_check {};
for (const auto & element : verses) {
int verse = element.first;
Expand All @@ -56,7 +56,7 @@ void checks_verses::missing_punctuation_at_end (const std::string& bible, int bo


void checks_verses::patterns (const std::string& bible, int book, int chapter,
const std::map <int, string> & verses, const std::vector <string> & patterns)
const std::map <int, std::string> & verses, const std::vector <std::string> & patterns)
{
Database_Check database_check {};
for (const auto & element : verses) {
Expand Down
4 changes: 2 additions & 2 deletions checksum/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ string checksum_logic::get (const std::string& data)

// This function gets the checksum for $data, and returns it.
// It calculates the length of vector 'data' in bytes.
string checksum_logic::get (const std::vector <string>& data)
string checksum_logic::get (const std::vector <std::string>& data)
{
int length = 0;
for (auto & bit : data) length += static_cast<int>(bit.length ());
Expand Down Expand Up @@ -99,7 +99,7 @@ string checksum_logic::get_bible (Webserver_Request& webserver_request, const st


// Returns a proper checksum for the USFM in the array of $bibles.
string checksum_logic::get_bibles (Webserver_Request& webserver_request, const std::vector <string> & bibles)
string checksum_logic::get_bibles (Webserver_Request& webserver_request, const std::vector <std::string> & bibles)
{
std::vector <std::string> checksums;
for (const auto & bible : bibles) {
Expand Down
4 changes: 2 additions & 2 deletions client/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void client_logic_usfm_resources_update ()
}


vector <string> client_logic_usfm_resources_get ()
vector <std::string> client_logic_usfm_resources_get ()
{
string contents = filter_url_file_get_contents (client_logic_usfm_resources_path ());
return filter::strings::explode (contents, '\n');
Expand Down Expand Up @@ -272,7 +272,7 @@ void client_logic_no_cache_resource_remove (string name)
}


vector <string> client_logic_no_cache_resources_get ()
vector <std::string> client_logic_no_cache_resources_get ()
{
string contents = filter_url_file_get_contents (client_logic_no_cache_resources_path());
vector<string> resources = filter::strings::explode(contents, "\n");
Expand Down
2 changes: 1 addition & 1 deletion collaboration/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ std::string collaboration_index (Webserver_Request& webserver_request)

// Get the status of the git repository.
// This could have been done through the following:
// std::vector <string> statuslines = filter_git_status (repositoryfolder);
// std::vector <std::string> statuslines = filter_git_status (repositoryfolder);
// But this function does not capture standard error.
// And the standard error output is needed in case of failures.
// So the following is used instead.
Expand Down
2 changes: 1 addition & 1 deletion database/bibleactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void Database_BibleActions::record (string bible, int book, int chapter, string
}


vector <string> Database_BibleActions::getBibles ()
vector <std::string> Database_BibleActions::getBibles ()
{
SqliteDatabase sql (filename ());
sql.add ("SELECT DISTINCT bible FROM bibleactions ORDER BY bible;");
Expand Down
2 changes: 1 addition & 1 deletion database/bibleimages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace std;
// That should be resilient enough.


vector <string> Database_BibleImages::get ()
vector <std::string> Database_BibleImages::get ()
{
std::vector <std::string> files = filter_url_scandir (folder ());
std::vector <std::string> images;
Expand Down
6 changes: 3 additions & 3 deletions database/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ vector <Database_Check_Hit> Database_Check::getHits ()
std::vector <Database_Check_Hit> hits;
SqliteDatabase sql (filename ());
sql.add ("SELECT rowid, bible, book, chapter, verse, data FROM output2;");
std::map <string, std::vector <string> > result = sql.query ();
std::map <string, std::vector <std::string> > result = sql.query ();
std::vector <std::string> rowids = result ["rowid"];
std::vector <std::string> bibles = result ["bible"];
std::vector <std::string> books = result ["book"];
Expand Down Expand Up @@ -232,7 +232,7 @@ Passage Database_Check::getPassage (int id)
sql.add ("SELECT book, chapter, verse FROM output2 WHERE rowid =");
sql.add (id);
sql.add (";");
std::map <string, std::vector <string> > result = sql.query ();
std::map <string, std::vector <std::string> > result = sql.query ();
std::vector <std::string> books = result ["book"];
std::vector <std::string> chapters = result ["chapter"];
std::vector <std::string> verses = result ["verse"];
Expand All @@ -249,7 +249,7 @@ vector <Database_Check_Hit> Database_Check::getSuppressions ()
SqliteDatabase sql (filename ());
std::vector <Database_Check_Hit> hits;
sql.add ("SELECT rowid, bible, book, chapter, verse, data FROM suppress2;");
std::map <string, std::vector <string> > result = sql.query ();
std::map <string, std::vector <std::string> > result = sql.query ();
std::vector <std::string> rowids = result ["rowid"];
std::vector <std::string> bibles = result ["bible"];
std::vector <std::string> books = result ["book"];
Expand Down
2 changes: 1 addition & 1 deletion database/config/bible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace std;
// Cache values in memory for better speed.
// The speed improvement is supposed to come from reading a value from disk only once,
// and after that to read the value straight from the memory cache.
map <string, string> database_config_bible_cache;
map <string, std::string> database_config_bible_cache;


// Functions for getting and setting values or lists of values follow now:
Expand Down
Loading

0 comments on commit 0e3cf1e

Please sign in to comment.