diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index 069545cb..0f7cb8c9 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -119,6 +119,12 @@ namespace nana void throw_not_utf8(const char*, unsigned len); void throw_not_utf8(const char*); + /// this text needed change, it needed review ?? + bool review_utf8(const std::string& text); + + /// this text needed change, it needed review ?? + bool review_utf8(std::string& text); + const std::string& to_utf8(const std::string&); std::string to_utf8(const std::wstring&); diff --git a/source/deploy.cpp b/source/deploy.cpp index ba6a0907..0e6b0faf 100644 --- a/source/deploy.cpp +++ b/source/deploy.cpp @@ -513,19 +513,13 @@ namespace nana return true; } + /// move to *.h ?? struct utf8_Error : std::runtime_error { static bool use_throw; ///< def { true }; use carefully - it is a global variable !! \todo initialize from a #define ? - - utf8_Error(const std::string& what_arg) - :std::runtime_error{ std::string("\nRun-time utf8 Error: ") + what_arg } - {} - - utf8_Error(const char * what_arg) - :utf8_Error{ std::string(what_arg) } - {} - - + + using std::runtime_error::runtime_error; + void emit() { if (use_throw) @@ -541,8 +535,6 @@ namespace nana { if (!is_utf8(text.c_str(), text.length())) return utf8_Error(std::string("The text is not encoded in UTF8: ") + text).emit(); - - //throw std::invalid_argument( std::string("The text is not encoded in UTF8: ")+text ) ; } void throw_not_utf8(const char* text, unsigned len) @@ -562,6 +554,38 @@ namespace nana } + std::string recode_to_utf8(std::string no_utf8) + { + return nana::charset(no_utf8).to_bytes(nana::unicode::utf8); + } + + /// this text needed change, it needed review ?? + bool review_utf8(const std::string& text) + { + if (!is_utf8(text.c_str(), text.length())) + { + utf8_Error(std::string("The text is not encoded in UTF8: ") + text).emit(); + return true; /// it needed change, it needed review !! + } + else + return false; + } + + /// this text needed change, it needed review ?? + bool review_utf8(std::string& text) + { + if (!is_utf8(text.c_str(), text.length())) + { + utf8_Error(std::string("The text is not encoded in UTF8: ") + text).emit(); + text.swap(recode_to_utf8(text)); + return true; /// it needed change, it needed review !! + } + else + return false; + } + + + const std::string& to_utf8(const std::string& str) { return str; diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index 8d4914f6..e3accf06 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -355,13 +355,15 @@ namespace nana msgbox::msgbox(const std::string& title) : wd_(nullptr), title_(title), button_(ok), icon_(icon_none) { - throw_not_utf8(title_); + // throw_not_utf8(title_); + review_utf8(title_); } msgbox::msgbox(window wd, const std::string& title, button_t b) : wd_(wd), title_(title), button_(b), icon_(icon_none) { - throw_not_utf8(title_); + // throw_not_utf8(title_); + review_utf8(title_); } msgbox& msgbox::icon(icon_t ic) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 56eff953..405e88a4 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -3148,6 +3148,7 @@ namespace nana { auto cell_txtcolor = fgcolor; auto & m_cell = item.cells[column_pos]; + review_utf8(m_cell.text); nana::size ts = graph->text_extent_size(m_cell.text); // precalcule text geometry if (m_cell.custom_format && (!m_cell.custom_format->bgcolor.invisible())) // adapt to costum format if need