Use unicode_cast
This commit is contained in:
parent
f330080e37
commit
cad98a3278
8 changed files with 24 additions and 26 deletions
|
@ -911,7 +911,7 @@ void filter_textbox::delete_item(int selection) {
|
|||
}
|
||||
|
||||
void filter_textbox::handle_text_changed(const ucs4::string& text) {
|
||||
const std::vector<std::string> words = utils::split(utils::ucs4string_to_string(text),' ');
|
||||
const std::vector<std::string> words = utils::split(unicode_cast<utf8::string>(text),' ');
|
||||
if (words == last_words)
|
||||
return;
|
||||
last_words = words;
|
||||
|
|
|
@ -91,8 +91,7 @@ bool open_object(const std::string& path_or_url)
|
|||
|
||||
LOG_DU << "open_object(): on Win32, will use ShellExecute()\n";
|
||||
|
||||
ucs4::string u4path = utils::string_to_ucs4string(path_or_url);
|
||||
utf16::string u16path = utils::ucs4string_to_utf16string(u4path);
|
||||
utf16::string u16path = unicode_cast<utf16::string>(path_or_url);
|
||||
u16path.push_back(wchar_t(0)); // Make wpath NULL-terminated
|
||||
|
||||
const ptrdiff_t res = reinterpret_cast<ptrdiff_t>(ShellExecute(NULL, L"open", &u16path.front(), NULL, NULL, SW_SHOW));
|
||||
|
|
|
@ -360,7 +360,7 @@ void hotkey_item::load_from_config(const config& cfg)
|
|||
return;
|
||||
}
|
||||
|
||||
ucs4::string wkey = utils::string_to_ucs4string(key);
|
||||
ucs4::string wkey = unicode_cast<ucs4::string>(key);
|
||||
|
||||
// They may really want a specific key on the keyboard:
|
||||
// we assume that any single character keyname is a character.
|
||||
|
|
|
@ -60,7 +60,7 @@ static markov_prefix_map markov_prefixes(const std::vector<std::string>& items,
|
|||
markov_prefix_map res;
|
||||
|
||||
for(std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i) {
|
||||
add_prefixes(utils::string_to_ucs4string(*i),length,res);
|
||||
add_prefixes(unicode_cast<ucs4::string>(*i),length,res);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -203,7 +203,7 @@ unit_race::unit_race(const config& cfg) :
|
|||
std::string unit_race::generate_name(
|
||||
unit_race::GENDER gender, rand_rng::simple_rng* rng) const
|
||||
{
|
||||
return utils::ucs4string_to_string(
|
||||
return unicode_cast<utf8::string>(
|
||||
markov_generate_name(next_[gender], chain_size_, 12, rng));
|
||||
}
|
||||
|
||||
|
|
|
@ -47,29 +47,29 @@ BOOST_AUTO_TEST_CASE( utils_unicode_test )
|
|||
BOOST_CHECK( utf8::truncate(unicode,3) == "\xC3\xBCni"); // "üni"
|
||||
|
||||
utf8::string apple_u8("apple");
|
||||
ucs4::string apple_u4 = utils::string_to_ucs4string(apple_u8);
|
||||
utf16::string apple_u16 = utils::ucs4string_to_utf16string(apple_u4);
|
||||
ucs4::string apple_u4 = unicode_cast<ucs4::string>(apple_u8);
|
||||
utf16::string apple_u16 = unicode_cast<utf16::string>(apple_u4);
|
||||
|
||||
BOOST_CHECK( apple_u4.size() == 5 );
|
||||
BOOST_CHECK_EQUAL( apple_u8, utils::ucs4string_to_string(apple_u4) );
|
||||
BOOST_CHECK_EQUAL( apple_u8, unicode_cast<utf8::string>(apple_u4) );
|
||||
BOOST_CHECK_EQUAL( apple_u8.size(), apple_u16.size() );
|
||||
|
||||
ucs4::string water_u4;
|
||||
water_u4.push_back(0x6C34);
|
||||
utf8::string water_u8 = utils::ucs4string_to_string(water_u4);
|
||||
utf16::string water_u16 = utils::ucs4string_to_utf16string(water_u4);
|
||||
utf8::string water_u8 = unicode_cast<utf8::string>(water_u4);
|
||||
utf16::string water_u16 = unicode_cast<utf16::string>(water_u4);
|
||||
|
||||
BOOST_CHECK_EQUAL(water_u4[0], water_u16[0]);
|
||||
BOOST_CHECK_EQUAL(water_u8, "\u6C34");
|
||||
|
||||
utf8::string nonbmp_u8("\U00010000");
|
||||
ucs4::string nonbmp_u4 = utils::string_to_ucs4string(nonbmp_u8);
|
||||
utf16::string nonbmp_u16 = utils::ucs4string_to_utf16string(nonbmp_u4);
|
||||
ucs4::string nonbmp_u4 = unicode_cast<ucs4::string>(nonbmp_u8);
|
||||
utf16::string nonbmp_u16 = unicode_cast<utf16::string>(nonbmp_u4);
|
||||
|
||||
BOOST_CHECK_EQUAL(nonbmp_u8.size(), 4);
|
||||
BOOST_CHECK_EQUAL(nonbmp_u4[0], 0x10000);
|
||||
BOOST_CHECK_EQUAL(nonbmp_u16[0], 0xD800);
|
||||
BOOST_CHECK_EQUAL(nonbmp_u16[1], 0xDC00);
|
||||
BOOST_CHECK_EQUAL(nonbmp_u8, utils::ucs4string_to_string(nonbmp_u4));
|
||||
BOOST_CHECK_EQUAL(nonbmp_u8, unicode_cast<utf8::string>(nonbmp_u4));
|
||||
}
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ bool ttext::insert_unicode(const unsigned offset, ucs4::char_t unicode)
|
|||
|
||||
unsigned ttext::insert_unicode(const unsigned offset, const ucs4::string& unicode)
|
||||
{
|
||||
const utf8::string insert = utils::ucs4string_to_string(unicode);
|
||||
const utf8::string insert = unicode_cast<utf8::string>(unicode);
|
||||
return insert_text(offset, insert);
|
||||
}
|
||||
|
||||
|
@ -293,8 +293,8 @@ bool ttext::set_text(const std::string& text, const bool markedup)
|
|||
if(markedup != markedup_text_ || text != text_) {
|
||||
assert(layout_);
|
||||
|
||||
const ucs4::string wide = utils::string_to_ucs4string(text);
|
||||
const std::string narrow = utils::ucs4string_to_string(wide);
|
||||
const ucs4::string wide = unicode_cast<ucs4::string>(text);
|
||||
const std::string narrow = unicode_cast<utf8::string>(wide);
|
||||
if(text != narrow) {
|
||||
ERR_GUI_L << "ttext::" << __func__
|
||||
<< " text '" << text
|
||||
|
|
|
@ -30,7 +30,7 @@ static lg::log_domain log_display("display");
|
|||
namespace gui {
|
||||
|
||||
textbox::textbox(CVideo &video, int width, const std::string& text, bool editable, size_t max_size, int font_size, double alpha, double alpha_focus, const bool auto_join)
|
||||
: scrollarea(video, auto_join), max_size_(max_size), font_size_(font_size), text_(utils::string_to_ucs4string(text)),
|
||||
: scrollarea(video, auto_join), max_size_(max_size), font_size_(font_size), text_(unicode_cast<ucs4::string>(text)),
|
||||
cursor_(text_.size()), selstart_(-1), selend_(-1),
|
||||
grabmouse_(false), text_pos_(0), editable_(editable),
|
||||
show_cursor_(true), show_cursor_at_(0), text_image_(NULL),
|
||||
|
@ -66,14 +66,14 @@ void textbox::set_inner_location(SDL_Rect const &rect)
|
|||
|
||||
const std::string textbox::text() const
|
||||
{
|
||||
const std::string &ret = utils::ucs4string_to_string(text_);
|
||||
const std::string &ret = unicode_cast<utf8::string>(text_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// set_text does not respect max_size_
|
||||
void textbox::set_text(const std::string& text, const SDL_Color& color)
|
||||
{
|
||||
text_ = utils::string_to_ucs4string(text);
|
||||
text_ = unicode_cast<ucs4::string>(text);
|
||||
cursor_ = text_.size();
|
||||
text_pos_ = 0;
|
||||
selstart_ = -1;
|
||||
|
@ -95,7 +95,7 @@ void textbox::append_text(const std::string& text, bool auto_scroll, const SDL_C
|
|||
return;
|
||||
}
|
||||
const bool is_at_bottom = get_position() == get_max_position();
|
||||
const ucs4::string& wtext = utils::string_to_ucs4string(text);
|
||||
const ucs4::string& wtext = unicode_cast<ucs4::string>(text);
|
||||
|
||||
const surface new_text = add_text_line(wtext, color);
|
||||
surface new_surface = create_compatible_surface(text_image_,std::max<size_t>(text_image_->w,new_text->w),text_image_->h+new_text->h);
|
||||
|
@ -345,7 +345,7 @@ surface textbox::add_text_line(const ucs4::string& text, const SDL_Color& color)
|
|||
}
|
||||
}
|
||||
|
||||
const std::string s = utils::ucs4string_to_string(wrapped_text);
|
||||
const std::string s = unicode_cast<utf8::string>(wrapped_text);
|
||||
const surface res(font::get_rendered_text(s, font_size_, color));
|
||||
|
||||
return res;
|
||||
|
@ -615,7 +615,7 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
|
|||
//cut off anything after the first newline
|
||||
str.erase(std::find_if(str.begin(),str.end(),utils::isnewline),str.end());
|
||||
|
||||
ucs4::string s = utils::string_to_ucs4string(str);
|
||||
ucs4::string s = unicode_cast<ucs4::string>(str);
|
||||
|
||||
if(text_.size() < max_size_) {
|
||||
if(s.size() + text_.size() > max_size_) {
|
||||
|
@ -637,7 +637,7 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
|
|||
const size_t end = std::max<size_t>(size_t(selstart_),size_t(selend_));
|
||||
|
||||
ucs4::string ws(text_.begin() + beg, text_.begin() + end);
|
||||
std::string s = utils::ucs4string_to_string(ws);
|
||||
std::string s = unicode_cast<utf8::string>(ws);
|
||||
copy_to_clipboard(s, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,8 +179,7 @@ void windows_tray_notification::switch_to_wesnoth_window()
|
|||
|
||||
std::wstring windows_tray_notification::string_to_wstring(const std::string& string, size_t maxlength)
|
||||
{
|
||||
const ucs4::string u4_string = utils::string_to_ucs4string(string);
|
||||
utf16::string u16_string = utils::ucs4string_to_utf16string(u4_string);
|
||||
utf16::string u16_string = unicode_cast<utf16::string>(string);
|
||||
if(u16_string.size() > maxlength) {
|
||||
if((u16_string[maxlength-1] & 0xDC00) == 0xD800)
|
||||
u16_string.resize(maxlength - 1);
|
||||
|
|
Loading…
Add table
Reference in a new issue