From e029d922b1bda4c331b631f89e7c211fd87aad0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Wed, 31 Jan 2024 16:09:09 +0100 Subject: [PATCH] Use wxString::utf8_string() --- src/catalog.cpp | 4 ++-- src/configuration.cpp | 2 +- src/crowdin_client.cpp | 21 ++++++++------------- src/edapp.cpp | 9 +++++---- src/edframe.cpp | 2 +- src/editing_area.cpp | 2 +- src/errors.h | 2 +- src/fileviewer.cpp | 2 +- src/http_client_casablanca.cpp | 2 +- src/language.h | 3 +-- src/propertiesdlg.cpp | 6 +++--- src/str_helpers.h | 2 +- 12 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/catalog.cpp b/src/catalog.cpp index 746d643890..a8664bc6d2 100644 --- a/src/catalog.cpp +++ b/src/catalog.cpp @@ -329,7 +329,7 @@ void Catalog::HeaderData::ParseDict() wxString X_Language = GetHeader("X-Poedit-Language"); wxString X_Country = GetHeader("X-Poedit-Country"); if ( !X_Language.empty() ) - Lang = Language::FromLegacyNames(X_Language.ToStdString(), X_Country.ToStdString()); + Lang = Language::FromLegacyNames(X_Language.utf8_string(), X_Country.utf8_string()); } DeleteHeader("X-Poedit-Language"); @@ -1063,7 +1063,7 @@ void Catalog::PostCreation() } if (!allText.empty()) { - lang = Language::TryDetectFromText(allText.utf8_str()); + lang = Language::TryDetectFromText(str::to_utf8(allText)); wxLogTrace("poedit", "detected translation language is '%s'", GetLanguage().Code()); } } diff --git a/src/configuration.cpp b/src/configuration.cpp index 8b4a510e61..bc83b32a49 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -220,7 +220,7 @@ bool Config::Read(const std::string& key, std::string *out) wxString s; if (!wxConfig::Get()->Read(key, &s)) return false; - *out = s.ToStdString(); + *out = s.utf8_string(); return true; } diff --git a/src/crowdin_client.cpp b/src/crowdin_client.cpp index c035419854..ddc6f63248 100644 --- a/src/crowdin_client.cpp +++ b/src/crowdin_client.cpp @@ -140,9 +140,7 @@ class CrowdinClient::crowdin_http_client : public http_client } catch (...) { - std::string msg; - msg = _("Unknown Crowdin error.").utf8_str(); - return msg; + return _("Unknown Crowdin error.").utf8_string(); } } } @@ -152,7 +150,7 @@ class CrowdinClient::crowdin_http_client : public http_client if (statusCode == 401/*Unauthorized*/) { // message is e.g. "The access token provided is invalid" - message = _("Not authorized, please sign in again.").utf8_str(); + message = _("Not authorized, please sign in again.").utf8_string(); } wxLogTrace("poedit.crowdin", "JSON error: %s", message.c_str()); } @@ -171,10 +169,7 @@ class CrowdinClient::crowdin_token if (jwt_token.empty()) return; - auto token_json = json::parse( - base64_decode_json_part(std::string( - wxString(jwt_token).AfterFirst('.').BeforeFirst('.').utf8_str() - ))); + auto token_json = json::parse(base64_decode_json_part(wxString(jwt_token).AfterFirst('.').BeforeFirst('.').utf8_string())); domain = get_value(token_json, "domain", ""); if (!domain.empty()) domain += '.'; @@ -537,14 +532,14 @@ std::shared_ptr CrowdinClient::DoExtractSyncMet meta->service = SERVICE_NAME; wxFileName fn(catalog.GetFileName()); - meta->extension = fn.GetExt().utf8_str(); + meta->extension = fn.GetExt().utf8_string(); auto& hdr = catalog.Header(); bool crowdinSpecificLangUsed = false; if (hdr.HasHeader("X-Crowdin-Language")) { - meta->lang = Language::FromLanguageTag(hdr.GetHeader("X-Crowdin-Language").ToStdString()); + meta->lang = Language::FromLanguageTag(hdr.GetHeader("X-Crowdin-Language").utf8_string()); crowdinSpecificLangUsed = true; } else @@ -573,8 +568,8 @@ std::shared_ptr CrowdinClient::DoExtractSyncMet if (hdr.HasHeader("X-Crowdin-Project-ID") && hdr.HasHeader("X-Crowdin-File-ID")) { - meta->projectId = std::stoi(hdr.GetHeader("X-Crowdin-Project-ID").ToStdString()); - meta->fileId = std::stoi(hdr.GetHeader("X-Crowdin-File-ID").ToStdString()); + meta->projectId = std::stoi(hdr.GetHeader("X-Crowdin-Project-ID").utf8_string()); + meta->fileId = std::stoi(hdr.GetHeader("X-Crowdin-File-ID").utf8_string()); return meta; } @@ -645,7 +640,7 @@ dispatch::future CrowdinClient::DownloadFile(const std::wstring& output_fi meta->lang = lang; meta->projectId = std::get(project.internalID); meta->fileId = internal->id; - meta->extension = wxFileName(internal->fileName, wxPATH_UNIX).GetExt().utf8_str(); + meta->extension = wxFileName(internal->fileName, wxPATH_UNIX).GetExt().utf8_string(); meta->xliffRemoteFilename.clear(); // -> forceExportAsXliff=false return DownloadFile(output_file, meta); diff --git a/src/edapp.cpp b/src/edapp.cpp index 5627d70b9a..fd7608f7b9 100644 --- a/src/edapp.cpp +++ b/src/edapp.cpp @@ -906,15 +906,16 @@ void PoeditApp::HandleCustomURI(const wxString& uri) return; #ifdef HAVE_HTTP_CLIENT - if (CrowdinClient::IsOAuthCallback(uri.ToStdString())) + auto uri_utf8 = uri.utf8_string(); + if (CrowdinClient::IsOAuthCallback(uri_utf8)) { - CrowdinClient::Get().HandleOAuthCallback(uri.ToStdString()); + CrowdinClient::Get().HandleOAuthCallback(uri_utf8); return; } - if (LocalazyClient::IsAuthCallback(uri.ToStdString())) + if (LocalazyClient::IsAuthCallback(uri_utf8)) { - LocalazyClient::Get().HandleAuthCallback(uri.ToStdString()) + LocalazyClient::Get().HandleAuthCallback(uri_utf8) .then_on_main([=](std::shared_ptr projectToOpen){ if (projectToOpen) { diff --git a/src/edframe.cpp b/src/edframe.cpp index e090fc48fc..c1f34e4991 100644 --- a/src/edframe.cpp +++ b/src/edframe.cpp @@ -2451,7 +2451,7 @@ void PoeditFrame::WarnAboutLanguageIssues() } // FIXME: make this part of global error checking - PluralFormsExpr plForms(po_cat->Header().GetHeader("Plural-Forms").ToStdString()); + PluralFormsExpr plForms(po_cat->Header().GetHeader("Plural-Forms").utf8_string()); if (!plForms) { if (plForms.str().empty()) diff --git a/src/editing_area.cpp b/src/editing_area.cpp index 6c0771abf2..f88f91d0a4 100644 --- a/src/editing_area.cpp +++ b/src/editing_area.cpp @@ -720,7 +720,7 @@ void EditingArea::RecreatePluralTextCtrls(CatalogPtr catalog) m_pluralNotebook->DeleteAllPages(); m_textTransSingularForm = NULL; - auto plurals = PluralFormsExpr(catalog->Header().GetHeader("Plural-Forms").ToStdString()); + auto plurals = PluralFormsExpr(catalog->Header().GetHeader("Plural-Forms").utf8_string()); int formsCount = catalog->GetPluralFormsCount(); for (int form = 0; form < formsCount; form++) diff --git a/src/errors.h b/src/errors.h index 0df1b9ce76..9cf33c080b 100644 --- a/src/errors.h +++ b/src/errors.h @@ -38,7 +38,7 @@ class Exception : public std::runtime_error { public: Exception(const wxString& what) - : std::runtime_error(std::string(what.utf8_str())), m_what(what) {} + : std::runtime_error(what.utf8_string()), m_what(what) {} const wxString& What() const { return m_what; } diff --git a/src/fileviewer.cpp b/src/fileviewer.cpp index 1d7cbfd7e7..18a1036e78 100644 --- a/src/fileviewer.cpp +++ b/src/fileviewer.cpp @@ -440,7 +440,7 @@ wxString FileToHTMLMarkup(const wxTextFile& file, const wxString& ext, size_t li html += wxString::Format("
"
                                  ""
                                      "",
-                             FilenameToLanguage(ext.Lower().ToStdString()));
+                             FilenameToLanguage(ext.Lower().utf8_string()));
 
     const size_t count = file.GetLineCount();
     if (lineno && lineno <= count)
diff --git a/src/http_client_casablanca.cpp b/src/http_client_casablanca.cpp
index ddd4f01f70..d3fd9d30ae 100644
--- a/src/http_client_casablanca.cpp
+++ b/src/http_client_casablanca.cpp
@@ -76,7 +76,7 @@ using utility::conversions::to_string_t;
 #ifdef _UTF16_STRINGS
 inline string_t to_string_t(const wxString& s) { return s.ToStdWstring(); }
 #else
-inline string_t to_string_t(const wxString& s) { return s.ToStdString(); }
+inline string_t to_string_t(const wxString& s) { return str::to_utf8(s); }
 inline string_t to_string_t(const std::wstring& s) { return str::to_utf8(s); }
 #endif
 
diff --git a/src/language.h b/src/language.h
index 20c28efaeb..9a1afd73e0 100644
--- a/src/language.h
+++ b/src/language.h
@@ -173,8 +173,7 @@ class Language
     static Language TryDetectFromText(const char *buffer, size_t len,
                                       Language probableLanguage = Language());
 
-    template
-    static Language TryDetectFromText(const T& str, Language probableLanguage = Language())
+    static Language TryDetectFromText(const std::string& str, Language probableLanguage = Language())
     {
         return TryDetectFromText(str.data(), str.length(), probableLanguage);
     }
diff --git a/src/propertiesdlg.cpp b/src/propertiesdlg.cpp
index e700e37b39..b35f54f361 100644
--- a/src/propertiesdlg.cpp
+++ b/src/propertiesdlg.cpp
@@ -884,7 +884,7 @@ void PropertiesDialog::TransferTo(const CatalogPtr& cat)
         if (m_hasPlurals)
         {
             PluralFormsExpr pf_def(cat->Header().Lang.DefaultPluralFormsExpr());
-            PluralFormsExpr pf_cat(cat->Header().GetHeader("Plural-Forms").ToStdString());
+            PluralFormsExpr pf_cat(cat->Header().GetHeader("Plural-Forms").utf8_string());
             if (pf_cat.str() == "nplurals=INTEGER; plural=EXPRESSION;")
                 pf_cat = pf_def;
 
@@ -937,7 +937,7 @@ void PropertiesDialog::TransferFrom(const CatalogPtr& cat)
                 // make sure we don't overwrite catalog's expression if the user didn't modify and
                 // it differs only cosmetically from the default
                 PluralFormsExpr pf_def(cat->Header().Lang.DefaultPluralFormsExpr());
-                PluralFormsExpr pf_cat(cat->Header().GetHeader("Plural-Forms").ToStdString());
+                PluralFormsExpr pf_cat(cat->Header().GetHeader("Plural-Forms").utf8_string());
                 if (langChanged || pf_def != pf_cat)
                     cat->Header().SetHeaderNotEmpty("Plural-Forms", pf_def.str());
             }
@@ -1044,7 +1044,7 @@ bool PropertiesDialog::Validate()
             auto form = bidi::strip_control_chars(m_pluralFormsExpr->GetValue());
             if (!form.empty())
             {
-                PluralFormsExpr expr(form.ToStdString());
+                PluralFormsExpr expr(form.utf8_string());
                 if (!expr)
                     m_validatedPlural = 0;
             }
diff --git a/src/str_helpers.h b/src/str_helpers.h
index 346a264bd9..60107f3dbf 100644
--- a/src/str_helpers.h
+++ b/src/str_helpers.h
@@ -85,7 +85,7 @@ inline std::wstring to_wstring(const unsigned char *utf8str)
 
 inline std::string to_utf8(const wxString& str)
 {
-    return std::string(str.utf8_str());
+    return str.utf8_string();
 }
 
 inline std::wstring to_wstring(const wxString& str)