Skip to content

Commit

Permalink
Use wxString::{starts,ends}_with()
Browse files Browse the repository at this point in the history
  • Loading branch information
vslavik committed Jan 31, 2024
1 parent e029d92 commit 36681c0
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ bool Catalog::HasSourcesAvailable() const
auto root = GetSourcesRootPath();
if (root == wxGetUserHome() ||
root == wxStandardPaths::Get().GetDocumentsDir() ||
root.EndsWith(wxString(wxFILE_SEP_PATH) + "Desktop" + wxFILE_SEP_PATH))
root.ends_with(wxString(wxFILE_SEP_PATH) + "Desktop" + wxFILE_SEP_PATH))
{
return false;
}
Expand Down Expand Up @@ -850,7 +850,7 @@ wxString CatalogItem::GetFormatFlag() const
auto format = (space == wxString::npos)
? m_moreFlags.substr(0, pos)
: m_moreFlags.substr(space+1, pos-space-1);
if (format.StartsWith("no-"))
if (format.starts_with("no-"))
return wxString();
return format;
}
Expand Down Expand Up @@ -977,9 +977,9 @@ wxString CatalogItem::GetOldMsgid() const
line.RemoveLast();
if (line[0] == '"')
line.Remove(0, 1);
if (line.StartsWith("msgid \""))
if (line.starts_with("msgid \""))
line.Remove(0, 7);
else if (line.StartsWith("msgid_plural \""))
else if (line.starts_with("msgid_plural \""))
line.replace(0, 14, "\n");
s += UnescapeCString(line);
}
Expand Down
8 changes: 4 additions & 4 deletions src/catalog_po.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,9 @@ wxString POCatalogParser::ReadTextLine()

// gettext tools don't include (extracted) comments in wrapping, so they can't
// be reliably used to detect file's wrapping either; just skip them.
if (!ln.StartsWith(wxS("#. ")) && !ln.StartsWith(wxS("# ")))
if (!ln.starts_with(wxS("#. ")) && !ln.starts_with(wxS("# ")))
{
if (ln.EndsWith(wxS("\\n\"")))
if (ln.ends_with(wxS("\\n\"")))
{
// Similarly, lines ending with \n are always wrapped, so skip that too.
m_lastLineHardWrapped = true;
Expand Down Expand Up @@ -737,7 +737,7 @@ bool POLoadParser::OnEntry(const wxString& msgid,
// https://groups.google.com/d/topic/poedit/j41KuvXtVUU/discussion
// As a workaround, just filter them out.
// FIXME: Fix this properly... but not using msgcat in the first place
if (i.StartsWith(MSGCAT_CONFLICT_MARKER) && i.EndsWith(MSGCAT_CONFLICT_MARKER))
if (i.starts_with(MSGCAT_CONFLICT_MARKER) && i.ends_with(MSGCAT_CONFLICT_MARKER))
continue;
d->AddExtractedComments(i);
}
Expand Down Expand Up @@ -1015,7 +1015,7 @@ void POCatalog::FixupCommonIssues()

if (!pluralForms.empty())
{
if (!pluralForms.EndsWith(";"))
if (!pluralForms.ends_with(";"))
{
pluralForms += ";";
m_header.SetHeader("Plural-Forms", pluralForms);
Expand Down
2 changes: 1 addition & 1 deletion src/cloud_accounts_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ bool ShouldSyncToCloudAutomatically(CatalogPtr catalog)
wxFileName f(catalog->GetFileName());
f.MakeAbsolute();

return f.GetFullPath().StartsWith(root.GetFullPath());
return f.GetFullPath().starts_with(root.GetFullPath());
}


Expand Down
4 changes: 2 additions & 2 deletions src/customcontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ ImageButton::ImageButton(wxWindow *parent, const wxString& bitmapName)
view.buttonType = NSButtonTypeMomentaryChange;
#else
// refresh template icons on theme change (macOS handles automatically):
if (bitmapName.EndsWith("Template"))
if (bitmapName.ends_with("Template"))
{
ColorScheme::SetupWindowColors(this, [=]
{
Expand All @@ -475,7 +475,7 @@ StaticBitmap::StaticBitmap(wxWindow *parent, const wxString& bitmapName)
{
#ifndef __WXOSX__
// refresh template icons on theme change (macOS handles automatically):
if (bitmapName.EndsWith("Template"))
if (bitmapName.ends_with("Template"))
{
ColorScheme::SetupWindowColors(this, [=]
{
Expand Down
12 changes: 6 additions & 6 deletions src/edapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ class PoeditApp::RemoteServer
});
return true;
}
if (data.StartsWith("OpenURI:", &payload))
if (data.starts_with("OpenURI:", &payload))
{
dispatch::on_main([=] {
m_app->HandleCustomURI(payload);
});
return true;
}
if (data.StartsWith("OpenFile:", &payload))
if (data.starts_with("OpenFile:", &payload))
{
long lineno = 0;
payload.BeforeFirst(':').ToLong(&lineno);
Expand Down Expand Up @@ -757,7 +757,7 @@ int PoeditApp::OpenFiles(const wxArrayString& names, int lineno)
// associated with it, so that the app can provide explanation to users
// not familiar with the MO/PO distinction.
auto n = name.Lower();
if (n.EndsWith(".mo") || n.EndsWith(".gmo"))
if (n.ends_with(".mo") || n.ends_with(".gmo"))
{
wxMessageDialog dlg(nullptr,
_(L"MO files can’t be directly edited in Poedit."),
Expand Down Expand Up @@ -852,7 +852,7 @@ bool PoeditApp::OnCmdLineParsed(wxCmdLineParser& parser)
for (size_t i = 0; i < parser.GetParamCount(); i++)
{
auto fn = parser.GetParam(i);
if (fn.StartsWith("poedit://"))
if (fn.starts_with("poedit://"))
client.HandleCustomURI(fn);
else
client.OpenFile(fn, (int)lineno);
Expand Down Expand Up @@ -880,7 +880,7 @@ bool PoeditApp::OnCmdLineParsed(wxCmdLineParser& parser)
for (size_t i = 0; i < parser.GetParamCount(); i++)
{
auto fn = parser.GetParam(i);
if (fn.StartsWith("poedit://"))
if (fn.starts_with("poedit://"))
{
gs_uriToHandle = fn;
}
Expand All @@ -902,7 +902,7 @@ bool PoeditApp::OnCmdLineParsed(wxCmdLineParser& parser)

void PoeditApp::HandleCustomURI(const wxString& uri)
{
if (!uri.StartsWith("poedit://"))
if (!uri.starts_with("poedit://"))
return;

#ifdef HAVE_HTTP_CLIENT
Expand Down
2 changes: 1 addition & 1 deletion src/edframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,7 @@ void PoeditFrame::FixDuplicatesIfPresent()
wxString generator = cat->Header().GetHeader("X-Generator");
wxString gversion;
if (generator.StartsWith("Poedit ", &gversion) &&
!gversion.StartsWith("1.7") && !gversion.StartsWith("1.6") && !gversion.StartsWith("1.5"))
!gversion.starts_with("1.7") && !gversion.starts_with("1.6") && !gversion.starts_with("1.5"))
return;

if (!cat->HasDuplicateItems())
Expand Down
2 changes: 1 addition & 1 deletion src/extractors/extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct PathToMatch
if (isWildcard)
return wxMatchWild(path, fn);
else
return fn == path || fn.StartsWith(path + "/");
return fn == path || fn.starts_with(path + "/");
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/extractors/extractor_gettext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void Extractor::CreateGettextExtractors(Extractor::ExtractorsList& into, const S

for (auto& m : sources.TypeMapping)
{
if (m.second.StartsWith("gettext:")) // e.g. gettext:php
if (m.second.starts_with("gettext:")) // e.g. gettext:php
{
auto e = std::make_shared<CustomGettextExtractor>(m.second.AfterFirst(':'));
if (wxIsWild(m.first))
Expand Down
2 changes: 1 addition & 1 deletion src/gexecute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void LogUnrecognizedError(const wxString& err)
// Warning: Failed to set locale category LC_NUMERIC to de.
// Warning: Failed to set locale category LC_TIME to de.
// ...etc...
if (err.StartsWith("Warning: Failed to set locale category"))
if (err.starts_with("Warning: Failed to set locale category"))
return;
#endif // __WXOSX__

Expand Down
2 changes: 1 addition & 1 deletion src/icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ wxBitmap PoeditArtProvider::CreateBitmap(const wxArtID& id_,
return wxNullBitmap;
}

if (id.EndsWith("Template"))
if (id.ends_with("Template"))
ProcessTemplateImage(icon.image, opaqueVariant, invertedVariant);

if (disabledVariant)
Expand Down
2 changes: 1 addition & 1 deletion src/propertiesdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ void PropertiesDialog::TransferFrom(const CatalogPtr& cat)
else
{
auto pluralForms = bidi::strip_control_chars(m_pluralFormsExpr->GetValue().Strip(wxString::both));
if (!pluralForms.empty() && !pluralForms.EndsWith(";"))
if (!pluralForms.empty() && !pluralForms.ends_with(";"))
pluralForms += ";";
cat->Header().SetHeaderNotEmpty("Plural-Forms", pluralForms);
}
Expand Down
4 changes: 2 additions & 2 deletions src/qa_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class PunctuationMismatch : public QACheck
}
else if (!s_punct && t_punct)
{
if (t_last == '.' && (source.EndsWith("st") || source.EndsWith("nd") || source.EndsWith("th")))
if (t_last == '.' && (source.ends_with("st") || source.ends_with("nd") || source.ends_with("th")))
{
// special-case English ordinals to languages that use [number].
}
Expand All @@ -380,7 +380,7 @@ class PunctuationMismatch : public QACheck
}
else if (s_punct && t_punct && s_last != t_last)
{
if (IsEquivalent(L'', t_last) && source.EndsWith("..."))
if (IsEquivalent(L'', t_last) && source.ends_with("..."))
{
// as a special case, allow translating ... (3 dots) as … (ellipsis)
}
Expand Down
4 changes: 2 additions & 2 deletions src/recent_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ wxString pretty_print_path(wxFileName f)

auto cloud = wxFileName::DirName(PoeditApp::GetCacheDir("Cloud"));
cloud.ReplaceHomeDir();
if (path.StartsWith(cloud.GetFullPath()))
if (path.starts_with(cloud.GetFullPath()))
path = _("Cloud") + L"" + path.substr(cloud.GetFullPath().length());

#ifdef __WXMSW__
// ReplaceHomeDir() puts tilde at the beginning to replace $HOME, but this is uncommon on Windows,
// so remove it and just use plain path:
if (path.StartsWith("~\\"))
if (path.starts_with("~\\"))
path = path.substr(2);
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/sidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ExtractedCommentSidebarBlock : public SidebarBlock
void Update(const CatalogItemPtr& item) override
{
auto comment = wxJoin(item->GetExtractedComments(), '\n', '\0');
if (comment.StartsWith("TRANSLATORS:") || comment.StartsWith("translators:"))
if (comment.starts_with("TRANSLATORS:") || comment.starts_with("translators:"))
{
comment.Remove(0, 12);
if (!comment.empty() && comment[0] == ' ')
Expand Down

0 comments on commit 36681c0

Please sign in to comment.