Skip to content

Commit

Permalink
Fewer void pointers and specify std library more often
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Dec 29, 2023
1 parent 7e3c1b4 commit 3909d8b
Show file tree
Hide file tree
Showing 68 changed files with 372 additions and 374 deletions.
6 changes: 3 additions & 3 deletions bootstrap/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void bootstrap_index (Webserver_Request& webserver_request)
|| (extension == "map")
|| (extension == "webmanifest")
) {
http_stream_file (std::addressof(webserver_request), true);
http_stream_file (webserver_request, true);
return;
}

Expand All @@ -300,7 +300,7 @@ void bootstrap_index (Webserver_Request& webserver_request)

// Serve resource downloads.
if ((extension == "sqlite") && (webserver_request.get.find (Database_Cache::fragment ()) != std::string::npos)) {
http_stream_file (std::addressof(webserver_request), false);
http_stream_file (webserver_request, false);
return;
}

Expand Down Expand Up @@ -961,7 +961,7 @@ void bootstrap_index (Webserver_Request& webserver_request)
}
if (extension == "sqlite") {
if (filter_url_dirname (url) == filter_url_temp_dir ()) {
http_stream_file (std::addressof(webserver_request), false);
http_stream_file (webserver_request, false);
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions checks/french.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void checks_french::space_before_after_punctuation (const string & bible, int bo
{
string text = element.second;
size_t pos = text.find (left_guillemet ());
while (pos != string::npos) {
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;
Expand All @@ -61,7 +61,7 @@ void checks_french::space_before_after_punctuation (const string & bible, int bo
string text = element.second;
// The location of this punctuation character.
size_t pos = filter::strings::unicode_string_strpos (text, punctuation);
while (pos != string::npos) {
while (pos != std::string::npos) {
if (pos > 0) {
string preceding_character = filter::strings::unicode_string_substr (text, pos - 1, 1);
if (preceding_character == " ") {
Expand Down
4 changes: 2 additions & 2 deletions checks/headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ void checks_headers::no_punctuation_at_end (const string & bible, int book, int
string last_character {};
if (!heading.empty ()) last_character = heading.substr (heading.size () - 1);
bool message {false};
if (centermarks.find (last_character) != string::npos) message = true;
if (endmarks.find (last_character) != string::npos) message = true;
if (centermarks.find (last_character) != std::string::npos) message = true;
if (endmarks.find (last_character) != std::string::npos) message = true;
if (message) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Punctuation at end of heading:") + " " + heading);
}
Expand Down
4 changes: 2 additions & 2 deletions checks/sentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void Checks_Sentences::add_result (string text, int modifier)
int iterations {5};
while (iterations) {
const size_t pos = previousFragment.find (" ");
if (pos != string::npos) {
if (pos != std::string::npos) {
if ((previousFragment.length () - pos) > 10) {
previousFragment.erase (0, pos + 1);
}
Expand All @@ -278,7 +278,7 @@ void Checks_Sentences::add_result (string text, int modifier)
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 == string::npos) nextFragment.erase (nextFragment.length () - 1, 1);
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.
Expand Down
22 changes: 11 additions & 11 deletions checks/space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace checks::space {
void double_space_usfm (const string & bible, int book, int chapter, int verse, const string & data)
{
const size_t pos = data.find (" ");
if (pos != string::npos) {
if (pos != std::string::npos) {
int start = static_cast<int>(pos) - 10;
if (start < 0) start = 0;
string fragment = data.substr (static_cast <size_t> (start), 20);
Expand All @@ -47,22 +47,22 @@ void space_before_punctuation (const string & bible, int book, int chapter, cons
for (const auto & element : texts) {
const int verse = element.first;
string text = element.second;
if (text.find (" ,") != string::npos) {
if (text.find (" ,") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before a comma"));
}
if (text.find (" ;") != string::npos) {
if (text.find (" ;") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before a semicolon"));
}
if (text.find (" :") != string::npos) {
if (text.find (" :") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before a colon"));
}
if (text.find (" .") != string::npos) {
if (text.find (" .") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before a full stop"));
}
if (text.find (" ?") != string::npos) {
if (text.find (" ?") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before a question mark"));
}
if (text.find (" !") != string::npos) {
if (text.find (" !") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before an exclamation mark"));
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ bool transpose_note_space (string & usfm)

bool transposed {false};
const size_t pos = usfm.find(" ");
if (pos != string::npos) {
if (pos != std::string::npos) {
map <string, string> data = {
pair (R"(\fk )", R"( \fk )"),
pair (R"(\ft )", R"( \ft )"),
Expand All @@ -121,13 +121,13 @@ bool transpose_note_space (string & usfm)
void space_before_final_note_markup (const string & bible, int book, int chapter, int verse, const string & data)
{
Database_Check database_check {};
if (data.find (R"( \f*)") != string::npos) {
if (data.find (R"( \f*)") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before final note markup"));
}
if (data.find (R"( \fe*)") != string::npos) {
if (data.find (R"( \fe*)") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before final note markup"));
}
if (data.find (R"( \x*)") != string::npos) {
if (data.find (R"( \x*)") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before final cross reference markup"));
}
}
Expand Down
20 changes: 10 additions & 10 deletions checks/usfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ void Checks_Usfm::new_line_in_usfm (const string & usfm)
{
size_t position {string::npos};
size_t pos = usfm.find ("\\\n");
if (pos != string::npos) {
if (pos != std::string::npos) {
position = pos;
}
pos = usfm.find ("\\ \n");
if (pos != string::npos) {
if (pos != std::string::npos) {
position = pos;
}
if (position != string::npos) {
if (position != std::string::npos) {
if (position == 0) position = 1;
string bit = usfm.substr (position - 1, 10);
bit = filter::strings::replace ("\n", " ", bit);
Expand Down Expand Up @@ -229,15 +229,15 @@ void Checks_Usfm::forward_slash (const string & usfm)
string code = filter::strings::replace ("\n", " ", usfm);
size_t pos = code.find ("/");
string bit {};
if (pos != string::npos) {
if (pos != std::string::npos) {
size_t pos2 = code.find (" ", pos);
if (pos2 != string::npos) {
if (pos2 != std::string::npos) {
bit = code.substr (pos, pos2 - pos);
} else {
bit = code.substr (pos, 100);
}
pos2 = bit.find ("*");
if (pos2 != string::npos) {
if (pos2 != std::string::npos) {
bit = bit.substr (0, pos2);
}
string marker = bit.substr (1, 100);
Expand Down Expand Up @@ -346,9 +346,9 @@ void Checks_Usfm::toc (string usfm)
if ((type == book_type::old_testament) || (type == book_type::new_testament)) {

// Check on the presence of the table of contents markers in this chapter.
bool toc1_present = usfm.find (filter::usfm::get_opening_usfm (long_toc1_marker)) != string::npos;
bool toc2_present = usfm.find (filter::usfm::get_opening_usfm (short_toc2_marker)) != string::npos;
bool toc3_present = usfm.find (filter::usfm::get_opening_usfm (abbrev_toc3_marker)) != string::npos;
bool toc1_present = usfm.find (filter::usfm::get_opening_usfm (long_toc1_marker)) != std::string::npos;
bool toc2_present = usfm.find (filter::usfm::get_opening_usfm (short_toc2_marker)) != std::string::npos;
bool toc3_present = usfm.find (filter::usfm::get_opening_usfm (abbrev_toc3_marker)) != std::string::npos;

// The markers should be on chapter 0 only.
if (chapter_number == 0) {
Expand Down Expand Up @@ -394,7 +394,7 @@ void Checks_Usfm::figure ()
}
}
size_t pos = usfm.find("");
if (pos != string::npos) {
if (pos != std::string::npos) {
add_result (translate ("Unusual quotation mark found:") + " " + usfm, display_nothing);
}
}
Expand Down
2 changes: 1 addition & 1 deletion checks/verses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void checks_verses::patterns (const string & bible, int book, int chapter,
const string text = element.second;
for (const auto & pattern : patterns) {
if (pattern.empty ()) continue;
if (text.find (pattern) != string::npos) {
if (text.find (pattern) != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Pattern found in text:") + " " + pattern);
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ string client_logic_connection_setup (string user, string hash)
// https://github.com/bibledit/cloud/issues/829.
string upgrade_required = filter_url_http_response_code_text (426);
size_t pos = error.find (upgrade_required);
if (pos != string::npos) {
if (pos != std::string::npos) {
// Since the error code ends without a full stop, add a full stop to it first.
error.append (". ");
// Add a good explanation to the error code so the user knows what to do if this error occurs.
Expand Down
10 changes: 5 additions & 5 deletions database/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ string database_filebased_cache_name_by_ip (string address, string id)
id = "_" + id;
string ipv4_sp = "::ffff:";
const unsigned long pos = address.find (ipv4_sp);
if (address.find (ipv4_sp) != string::npos) address.erase (pos, ipv4_sp.length ());
if (address.find (id) == string::npos) address.append (id);
if (address.find (ipv4_sp) != std::string::npos) address.erase (pos, ipv4_sp.length ());
if (address.find (id) == std::string::npos) address.append (id);
return address;
}

Expand All @@ -328,7 +328,7 @@ string database_filebased_cache_name_by_ip (string address, string id)
string database_filebased_cache_name_by_session_id (string sid, string id)
{
id = "_" + id;
if (sid.find (id) == string::npos) sid.append (id);
if (sid.find (id) == std::string::npos) sid.append (id);
return sid;
}

Expand Down Expand Up @@ -424,7 +424,7 @@ void database_cache_trim (bool clear)
{
vector<string> bits = filter::strings::explode(output, ' ');
for (auto bit : bits) {
if (bit.find ("%") != string::npos) {
if (bit.find ("%") != std::string::npos) {
percentage_disk_in_use = filter::strings::convert_to_int(bit);
// If a real percentage was found, other than 0, then skip the remainder.
// On macOS the first percentage found is %iused, so will be skipped.
Expand Down Expand Up @@ -515,7 +515,7 @@ bool database_cache_can_cache (const string & error, const string & html)

// Do not cache the data if Cloudflare does DDoS protection.
// https://github.com/bibledit/cloud/issues/693.
if (html.find ("Cloudflare") != string::npos) cache = false;
if (html.find ("Cloudflare") != std::string::npos) cache = false;

return cache;
}
2 changes: 1 addition & 1 deletion database/confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ unsigned int Database_Confirm::search_id (string subject)
vector <string> ids = sql.query () ["id"];
for (string id : ids) {
size_t pos = subject.find (id);
if (pos != string::npos) {
if (pos != std::string::npos) {
return static_cast<unsigned>(filter::strings::convert_to_int (id));
}
}
Expand Down
2 changes: 1 addition & 1 deletion database/notes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void Database_Notes::sync ()
}
}
// New JSON storage mechanism, e.g. file "894093.json".
if ((bit2.length () == 11) && bit2.find (".json") != string::npos) {
if ((bit2.length () == 11) && bit2.find (".json") != std::string::npos) {
int identifier = filter::strings::convert_to_int (bit1 + bit2.substr (0,6));
identifiers.push_back (identifier);
update_database (identifier);
Expand Down
2 changes: 1 addition & 1 deletion database/userresources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ vector <string> Database_UserResources::names ()
vector <string> names;
vector <string> files = filter_url_scandir (folder ());
for (auto name : files) {
if (name.find (fragment ()) != string::npos) {
if (name.find (fragment ()) != std::string::npos) {
name.erase (0, fragment ().size ());
name = filter_url_filename_unclean (name);
names.push_back (name);
Expand Down
4 changes: 2 additions & 2 deletions demo/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void demo_create_sample_bible ()
// * it means that Bibledit uses a different name for the Sample Bible,
// * and the file needs an update.
size_t pos = file.find(demo_sample_bible_name());
if (pos == string::npos) {
if (pos == std::string::npos) {
string filename = "Sample";
file = filter::strings::replace(filename, demo_sample_bible_name(), file);
}
Expand Down Expand Up @@ -312,7 +312,7 @@ void demo_prepare_sample_bible ()
files.clear ();
filter_url_recursive_scandir (directory, files);
for (const auto & file : files) {
if (file.find (demo_sample_bible_name ()) != string::npos) {
if (file.find (demo_sample_bible_name ()) != std::string::npos) {
string data = filter_url_file_get_contents (file);
Database_Sample::store (file, data);
}
Expand Down
2 changes: 1 addition & 1 deletion developer/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void developer_logic_import_changes ()
bool passage_found {false};
if (book != book_id::_unknown) {
size_t pos = line.find (":");
if (pos != string::npos) {
if (pos != std::string::npos) {
vector <string> bits = filter::strings::explode(line.substr (0, pos), ".");
if (bits.size() == 2) {
chapter = filter::strings::convert_to_int(filter::strings::trim(bits[0]));
Expand Down
2 changes: 1 addition & 1 deletion dialog/list2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ string Options_To_Select::mark_selected (string value, string html)
size_t new_pos = html.find (new_value) + new_value.length ();
string mark = " selected";

if (html.find (mark) != string::npos) {
if (html.find (mark) != std::string::npos) {
html.erase (html.find (mark), mark.length ());
}

Expand Down
2 changes: 1 addition & 1 deletion email/send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ string email_send ([[maybe_unused]] string to_mail,
payload_text.push_back (payload);
string site = from_mail;
size_t pos = site.find ("@");
if (pos != string::npos) site = site.substr (pos);
if (pos != std::string::npos) site = site.substr (pos);
payload = "Message-ID: <" + md5 (filter::strings::convert_to_string (filter::strings::rand (0, 1000000))) + site + ">\n";
payload_text.push_back (payload);
payload = "Subject: " + subject + "\n";
Expand Down
2 changes: 1 addition & 1 deletion executable/bibledit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ int main ([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
for (auto & line : lines) {
Database_Logs::log (line);
// Set a flag if the backtrace appears to be caused while sending email.
if (line.find ("email_send") != string::npos) config_globals_has_crashed_while_mailing = true;
if (line.find ("email_send") != std::string::npos) config_globals_has_crashed_while_mailing = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion export/bibledropbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void export_bibledropbox (string user, string bible)
email_schedule (user, "Error submitting to the Bible Drop Box", error);
}
size_t pos = response.find ("<head>");
if (pos != string::npos) {
if (pos != std::string::npos) {
response.insert (pos + 6, R"(<base href="http://freely-given.org/Software/BibleDropBox/">)");
}
email_schedule (user, "Result of your submission to the Bible Drop Box", response);
Expand Down
8 changes: 4 additions & 4 deletions filter/git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ bool filter_git_commit (string repository, string user, string message,

// In case of Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean,
// git returns exit code 256. Yet this is not an error.
if (out.find ("nothing to commit") != string::npos) result = 0;
if (out.find ("nothing to commit") != std::string::npos) result = 0;

return (result == 0);
}
Expand Down Expand Up @@ -455,14 +455,14 @@ Passage filter_git_get_passage (string line)
vector <string> bits = filter::strings::explode (line, '/');
if (bits.size () == 3) {
size_t pos = bits [0].find (":");
if (pos != string::npos) bits [0].erase (0, pos + 1);
if (pos != std::string::npos) bits [0].erase (0, pos + 1);
string bookname = filter::strings::trim (bits [0]);
int book = static_cast<int>(database::books::get_id_from_english (bookname));
if (book) {
if (filter::strings::is_numeric (bits [1])) {
int chapter = filter::strings::convert_to_int (bits [1]);
string data = bits [2];
if (data.find ("data") != string::npos) {
if (data.find ("data") != std::string::npos) {
passage.m_book = book;
passage.m_chapter = chapter;
}
Expand Down Expand Up @@ -537,7 +537,7 @@ bool filter_git_resolve_conflicts (string repository, vector <string> & paths, s
vector <string> lines = filter_git_status (repository, true);
for (auto line : lines) {
size_t pos = line.find ("UU ");
if (pos != string::npos) {
if (pos != std::string::npos) {
line.erase (0, 3);
line = filter::strings::trim (line);
unmerged_paths.push_back (line);
Expand Down
4 changes: 2 additions & 2 deletions filter/mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ string filter_mail_remove_headers_internal (string contents)
vector <string> cleaned;
vector <string> inputlines = filter::strings::explode (contents, '\n');
for (auto line : inputlines) {
if (line.find ("Content-Type") != string::npos) continue;
if (line.find ("Content-Transfer-Encoding") != string::npos) continue;
if (line.find ("Content-Type") != std::string::npos) continue;
if (line.find ("Content-Transfer-Encoding") != std::string::npos) continue;
if (empty_line_encountered) cleaned.push_back (line);
if (filter::strings::trim (line).empty ()) empty_line_encountered = true;
}
Expand Down
Loading

0 comments on commit 3909d8b

Please sign in to comment.