[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master d7c4f5d 5/5: Convert from wxString to std::st
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master d7c4f5d 5/5: Convert from wxString to std::string explicitly (VZ) |
Date: |
Tue, 21 Feb 2017 11:44:27 -0500 (EST) |
branch: master
commit d7c4f5d3dbc0858405ea2eb1ec709eca7b19ae73
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Convert from wxString to std::string explicitly (VZ)
Don't rely on implicit conversion from wxString to std::string and call
ToStdString(wxConvUTF8) explicitly instead.
The main advantage of doing this is that it avoids silent data loss if
wxString contains any Unicode characters not representable in the
current locale.
Another advantage is that it makes the boundary between GUI and non-GUI
code more clear, albeit at the price of brevity.
---
input_sequence_entry.cpp | 2 +-
multidimgrid_any.cpp | 4 ++--
policy_document.cpp | 2 +-
product_editor.cpp | 4 ++--
transferor.cpp | 6 +++---
view_ex.cpp | 2 +-
wx_utility.cpp | 10 +++++++---
7 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/input_sequence_entry.cpp b/input_sequence_entry.cpp
index acafe90..071c1fd 100644
--- a/input_sequence_entry.cpp
+++ b/input_sequence_entry.cpp
@@ -1557,7 +1557,7 @@ void InputSequenceEntry::DoOpenEditor()
// UponChildKillFocus() would need to be updated.
InputSequenceEditor editor(button_, title_, in);
- std::string sequence_string = std::string(text_->GetValue());
+ std::string sequence_string = text_->GetValue().ToStdString(wxConvUTF8);
datum_sequence const& ds = *member_cast<datum_sequence>(in[field_name()]);
std::map<std::string,std::string> const kwmap = ds.allowed_keywords();
diff --git a/multidimgrid_any.cpp b/multidimgrid_any.cpp
index 514872f..0d8d9aa 100644
--- a/multidimgrid_any.cpp
+++ b/multidimgrid_any.cpp
@@ -1170,7 +1170,7 @@ void MultiDimGrid::SetValue(int row, int col, wxString
const& value)
DoSetValue
(EnsureIndexIsPositive(row)
,EnsureIndexIsPositive(col)
- ,std::string(value)
+ ,value.ToStdString(wxConvUTF8)
);
}
catch(std::exception const& e)
@@ -1376,7 +1376,7 @@ void MultiDimAxisAnyChoice::PopulateChoiceList()
int const selection = GetSelection();
std::string const selected_label =
selection != wxNOT_FOUND
- ? std::string(GetString(selection))
+ ? GetString(selection).ToStdString(wxConvUTF8)
: std::string()
;
diff --git a/policy_document.cpp b/policy_document.cpp
index e1c2b0e..c3d72d3 100644
--- a/policy_document.cpp
+++ b/policy_document.cpp
@@ -110,7 +110,7 @@ void PolicyDocument::WriteDocument(std::string const&
filename)
PolicyView& view = PredominantView();
for(auto const& i : values_)
{
- *i.second = view.controls()[i.first]->GetValue();
+ *i.second =
view.controls()[i.first]->GetValue().ToStdString(wxConvUTF8);
}
}
save(product_data_, filename);
diff --git a/product_editor.cpp b/product_editor.cpp
index ed7d07e..a579385 100644
--- a/product_editor.cpp
+++ b/product_editor.cpp
@@ -73,7 +73,7 @@ bool ProductEditorDocument::DoOpenDocument(wxString const&
filename)
{
try
{
- ReadDocument(std::string(filename));
+ ReadDocument(filename.ToStdString(wxConvUTF8));
return true;
}
catch(std::exception const& e)
@@ -95,7 +95,7 @@ bool ProductEditorDocument::DoSaveDocument(wxString const&
filename)
{
try
{
- WriteDocument(std::string(filename));
+ WriteDocument(filename.ToStdString(wxConvUTF8));
return true;
}
catch(std::exception const& e)
diff --git a/transferor.cpp b/transferor.cpp
index f264536..ded43e2 100644
--- a/transferor.cpp
+++ b/transferor.cpp
@@ -222,7 +222,7 @@ namespace
}
else
{
- data = control.GetLabel();
+ data = control.GetLabel().ToStdString(wxConvUTF8);
}
return true;
}
@@ -303,7 +303,7 @@ namespace
// suppressed if living with that problem is acceptable.
# error Outdated library: wx-2.6.2 or greater is required.
#endif // !wxCHECK_VERSION(2,6,2)
- data = control.GetStringSelection();
+ data = control.GetStringSelection().ToStdString(wxConvUTF8);
}
return true;
}
@@ -462,7 +462,7 @@ namespace
}
else
{
- data = control.GetValue();
+ data = control.GetValue().ToStdString(wxConvUTF8);
}
return true;
}
diff --git a/view_ex.cpp b/view_ex.cpp
index 18e16b3..5be4c42 100644
--- a/view_ex.cpp
+++ b/view_ex.cpp
@@ -214,7 +214,7 @@ void ViewEx::OnDraw(wxDC*)
std::string ViewEx::base_filename() const
{
- std::string t(GetDocument()->GetUserReadableName());
+ std::string
t(GetDocument()->GetUserReadableName().ToStdString(wxConvUTF8));
fs::path path(t);
return path.has_leaf() ? path.leaf() : std::string("Hastur");
}
diff --git a/wx_utility.cpp b/wx_utility.cpp
index 23cd3c8..54edb78 100644
--- a/wx_utility.cpp
+++ b/wx_utility.cpp
@@ -58,7 +58,7 @@ std::string ClipboardEx::GetText()
wxTextDataObject z;
wxTheClipboard->GetData(z);
- std::string s(z.GetText());
+ std::string s(z.GetText().ToStdString(wxConvUTF8));
static std::string const crlf("\r\n");
static std::string const lf( "\n");
@@ -187,7 +187,11 @@ void TestDateConversions()
}
std::string const lmi_str(lmi_date0.str());
- std::string const wx_str(ConvertDateToWx(lmi_date0).FormatISODate());
+ std::string const wx_str
+ (ConvertDateToWx(lmi_date0)
+ .FormatISODate()
+ .ToStdString(wxConvUTF8)
+ );
if(lmi_str != wx_str)
{
fatal_error()
@@ -213,7 +217,7 @@ std::vector<std::string>
EnumerateBookPageNames(wxBookCtrlBase const& book)
std::vector<std::string> z;
for(std::size_t j = 0; j < book.GetPageCount(); ++j)
{
- std::string name(book.GetPageText(j));
+ std::string name(book.GetPageText(j).ToStdString(wxConvUTF8));
LMI_ASSERT(!contains(z, name));
z.push_back(name);
}