Skip to content

Commit

Permalink
Use wxString::utf8_string()
Browse files Browse the repository at this point in the history
  • Loading branch information
vslavik committed Jan 31, 2024
1 parent 174d66b commit e029d92
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 8 additions & 13 deletions src/crowdin_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand All @@ -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());
}
Expand All @@ -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 += '.';
Expand Down Expand Up @@ -537,14 +532,14 @@ std::shared_ptr<CrowdinClient::FileSyncMetadata> 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
Expand Down Expand Up @@ -573,8 +568,8 @@ std::shared_ptr<CrowdinClient::FileSyncMetadata> 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;
}

Expand Down Expand Up @@ -645,7 +640,7 @@ dispatch::future<void> CrowdinClient::DownloadFile(const std::wstring& output_fi
meta->lang = lang;
meta->projectId = std::get<int>(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);
Expand Down
9 changes: 5 additions & 4 deletions src/edapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LocalazyClient::ProjectInfo> projectToOpen){
if (projectToOpen)
{
Expand Down
2 changes: 1 addition & 1 deletion src/edframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/editing_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
2 changes: 1 addition & 1 deletion src/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
2 changes: 1 addition & 1 deletion src/fileviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ wxString FileToHTMLMarkup(const wxTextFile& file, const wxString& ext, size_t li
html += wxString::Format("<pre class=\"line-numbers\">"
"<code>"
"<code class=\"language-%s\">",
FilenameToLanguage(ext.Lower().ToStdString()));
FilenameToLanguage(ext.Lower().utf8_string()));

const size_t count = file.GetLineCount();
if (lineno && lineno <= count)
Expand Down
2 changes: 1 addition & 1 deletion src/http_client_casablanca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ class Language
static Language TryDetectFromText(const char *buffer, size_t len,
Language probableLanguage = Language());

template<typename T>
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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/propertiesdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/str_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e029d92

Please sign in to comment.