experimenting with review_utf8

This commit is contained in:
qPCR4vir 2016-03-18 22:20:48 +01:00
parent a9ef23d8d8
commit 10eaa91c3c
4 changed files with 47 additions and 14 deletions

View File

@ -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&);

View File

@ -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;

View File

@ -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)

View File

@ -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