Use UTF-8 instead of narrow
authorest31 <MTest31@outlook.com>
Tue, 7 Jul 2015 03:55:07 +0000 (05:55 +0200)
committerest31 <MTest31@outlook.com>
Wed, 8 Jul 2015 08:12:44 +0000 (10:12 +0200)
Use wide_to_utf8 and utf8_to_wide instead of wide_to_narrow and narrow_to_wide at almost all places.
Only exceptions: test functions for narrow conversion, and chat, which is done in a separate commit.

19 files changed:
src/client/clientlauncher.cpp
src/content_cao.cpp
src/fontengine.h
src/game.cpp
src/gettext.cpp
src/gettext.h
src/guiEngine.cpp
src/guiFileSelectMenu.cpp
src/guiPasswordChange.cpp
src/guiTable.cpp
src/hud.cpp
src/network/clientpackethandler.cpp
src/network/serverpackethandler.cpp
src/script/lua_api/l_mainmenu.cpp
src/script/lua_api/l_server.cpp
src/server.cpp
src/unittest/test_serialization.cpp
src/util/string.cpp
src/util/string.h

index 41ba4f3071f33685a59fc24c6abc429d2d8d00a9..50f0690d84677b9b352eb37f265e7040f480d151 100644 (file)
@@ -183,7 +183,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
        {
                // Set the window caption
                const wchar_t *text = wgettext("Main Menu");
-               device->setWindowCaption((narrow_to_wide(PROJECT_NAME_C) + L" [" + text + L"]").c_str());
+               device->setWindowCaption((utf8_to_wide(PROJECT_NAME_C) + L" [" + text + L"]").c_str());
                delete[] text;
 
                try {   // This is used for catching disconnects
index d38cb892a3bc1966de794af59fd1f2ef841b4b73..a16bd4efa5fd55c69ccc762f49fcaf7f342f1362 100644 (file)
@@ -970,7 +970,7 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
        if (node && m_is_player && !m_is_local_player) {
                // Add a text node for showing the name
                gui::IGUIEnvironment* gui = irr->getGUIEnvironment();
-               std::wstring wname = narrow_to_wide(m_name);
+               std::wstring wname = utf8_to_wide(m_name);
                m_textnode = smgr->addTextSceneNode(gui->getSkin()->getFont(),
                                wname.c_str(), m_nametag_color, node);
                m_textnode->grab();
index 9edde05f8f4aee50b31fb72d1bd719bc20ac115f..9f7266775ac944e515f77ee9bd12704966c3ba16 100644 (file)
@@ -59,7 +59,7 @@ public:
                        unsigned int font_size=FONT_SIZE_UNSPECIFIED,
                        FontMode mode=FM_Unspecified)
        {
-               return getTextWidth(narrow_to_wide(text));
+               return getTextWidth(utf8_to_wide(text));
        }
 
        /** get text width if a text for a specific font */
index 0189143b81f525e037d30624c60d54d8fd20dbd0..ef3cb9044aaae5b28c916dfa0b1f3f665bdcaa4d 100644 (file)
@@ -85,7 +85,7 @@ struct TextDestNodeMetadata : public TextDest {
        // This is deprecated I guess? -celeron55
        void gotText(std::wstring text)
        {
-               std::string ntext = wide_to_narrow(text);
+               std::string ntext = wide_to_utf8(text);
                infostream << "Submitting 'text' field of node at (" << m_p.X << ","
                           << m_p.Y << "," << m_p.Z << "): " << ntext << std::endl;
                StringMap fields;
@@ -183,7 +183,7 @@ struct LocalFormspecHandler : public TextDest {
                                        (fields.find("quit") != fields.end())) {
                                StringMap::const_iterator it = fields.find("f_text");
                                if (it != fields.end())
-                                       m_client->typeChatMessage(narrow_to_wide(it->second));
+                                       m_client->typeChatMessage(utf8_to_wide(it->second));
 
                                return;
                        }
@@ -445,7 +445,7 @@ void update_profiler_gui(gui::IGUIStaticText *guitext_profiler, FontEngine *fe,
 
                std::ostringstream os(std::ios_base::binary);
                g_profiler->printPage(os, show_profiler, show_profiler_max);
-               std::wstring text = narrow_to_wide(os.str());
+               std::wstring text = utf8_to_wide(os.str());
                guitext_profiler->setText(text.c_str());
                guitext_profiler->setVisible(true);
 
@@ -582,16 +582,16 @@ public:
                        s32 texth = 15;
                        char buf[10];
                        snprintf(buf, 10, "%.3g", show_max);
-                       font->draw(narrow_to_wide(buf).c_str(),
+                       font->draw(utf8_to_wide(buf).c_str(),
                                        core::rect<s32>(textx, y - graphh,
                                                   textx2, y - graphh + texth),
                                        meta.color);
                        snprintf(buf, 10, "%.3g", show_min);
-                       font->draw(narrow_to_wide(buf).c_str(),
+                       font->draw(utf8_to_wide(buf).c_str(),
                                        core::rect<s32>(textx, y - texth,
                                                   textx2, y),
                                        meta.color);
-                       font->draw(narrow_to_wide(id).c_str(),
+                       font->draw(utf8_to_wide(id).c_str(),
                                        core::rect<s32>(textx, y - graphh / 2 - texth / 2,
                                                   textx2, y - graphh / 2 + texth / 2),
                                        meta.color);
@@ -1049,7 +1049,7 @@ static void show_chat_menu(GUIFormSpecMenu **cur_formspec,
                FORMSPEC_VERSION_STRING
                SIZE_TAG
                "field[3,2.35;6,0.5;f_text;;" + text + "]"
-               "button_exit[4,3;3,0.5;btn_send;" + wide_to_narrow(wstrgettext("Proceed")) + "]"
+               "button_exit[4,3;3,0.5;btn_send;" + wide_to_utf8(wstrgettext("Proceed")) + "]"
                ;
 
        /* Create menu */
@@ -1089,7 +1089,7 @@ static void show_pause_menu(GUIFormSpecMenu **cur_formspec,
                bool singleplayermode)
 {
 #ifdef __ANDROID__
-       std::string control_text = wide_to_narrow(wstrgettext("Default Controls:\n"
+       std::string control_text = wide_to_utf8(wstrgettext("Default Controls:\n"
                                   "No menu visible:\n"
                                   "- single tap: button activate\n"
                                   "- double tap: place/use\n"
@@ -1103,7 +1103,7 @@ static void show_pause_menu(GUIFormSpecMenu **cur_formspec,
                                   " --> place single item to slot\n"
                                                             ));
 #else
-       std::string control_text = wide_to_narrow(wstrgettext("Default Controls:\n"
+       std::string control_text = wide_to_utf8(wstrgettext("Default Controls:\n"
                                   "- WASD: move\n"
                                   "- Space: jump/climb\n"
                                   "- Shift: sneak/go down\n"
@@ -1122,23 +1122,23 @@ static void show_pause_menu(GUIFormSpecMenu **cur_formspec,
 
        os << FORMSPEC_VERSION_STRING  << SIZE_TAG
           << "button_exit[4," << (ypos++) << ";3,0.5;btn_continue;"
-          << wide_to_narrow(wstrgettext("Continue"))     << "]";
+          << wide_to_utf8(wstrgettext("Continue"))     << "]";
 
        if (!singleplayermode) {
                os << "button_exit[4," << (ypos++) << ";3,0.5;btn_change_password;"
-                  << wide_to_narrow(wstrgettext("Change Password")) << "]";
+                  << wide_to_utf8(wstrgettext("Change Password")) << "]";
        }
 
 #ifndef __ANDROID__
        os              << "button_exit[4," << (ypos++) << ";3,0.5;btn_sound;"
-                       << wide_to_narrow(wstrgettext("Sound Volume")) << "]";
+                       << wide_to_utf8(wstrgettext("Sound Volume")) << "]";
        os              << "button_exit[4," << (ypos++) << ";3,0.5;btn_key_config;"
-                       << wide_to_narrow(wstrgettext("Change Keys"))  << "]";
+                       << wide_to_utf8(wstrgettext("Change Keys"))  << "]";
 #endif
        os              << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_menu;"
-                       << wide_to_narrow(wstrgettext("Exit to Menu")) << "]";
+                       << wide_to_utf8(wstrgettext("Exit to Menu")) << "]";
        os              << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_os;"
-                       << wide_to_narrow(wstrgettext("Exit to OS"))   << "]"
+                       << wide_to_utf8(wstrgettext("Exit to OS"))   << "]"
                        << "textarea[7.5,0.25;3.9,6.25;;" << control_text << ";]"
                        << "textarea[0.4,0.25;3.5,6;;" << PROJECT_NAME_C "\n"
                        << g_build_info << "\n"
@@ -1167,7 +1167,7 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
 
        // Get new messages from error log buffer
        while (!chat_log_error_buf.empty()) {
-               chat_backend.addMessage(L"", narrow_to_wide(chat_log_error_buf.get()));
+               chat_backend.addMessage(L"", utf8_to_wide(chat_log_error_buf.get()));
        }
 
        // Get new messages from client
@@ -2059,7 +2059,7 @@ bool Game::createClient(const std::string &playername,
 
        /* Set window caption
         */
-       std::wstring str = narrow_to_wide(PROJECT_NAME_C);
+       std::wstring str = utf8_to_wide(PROJECT_NAME_C);
        str += L" [";
        str += driver->getName();
        str += L"]";
@@ -2087,7 +2087,7 @@ bool Game::initGui()
 {
        // First line of debug text
        guitext = guienv->addStaticText(
-                       narrow_to_wide(PROJECT_NAME_C).c_str(),
+                       utf8_to_wide(PROJECT_NAME_C).c_str(),
                        core::rect<s32>(0, 0, 0, 0),
                        false, false, guiroot);
 
@@ -2342,7 +2342,7 @@ bool Game::getServerContent(bool *aborted)
                        }
 
                        progress = 30 + client->mediaReceiveProgress() * 35 + 0.5;
-                       draw_load_screen(narrow_to_wide(message.str()), device,
+                       draw_load_screen(utf8_to_wide(message.str()), device,
                                        guienv, dtime, progress);
                }
        }
@@ -2660,7 +2660,7 @@ void Game::processKeyboardInput(VolatileRunFlags *flags,
 
        if (quicktune->hasMessage()) {
                std::string msg = quicktune->getMessage();
-               statustext = narrow_to_wide(msg);
+               statustext = utf8_to_wide(msg);
                *statustext_time = 0;
        }
 }
@@ -2947,7 +2947,7 @@ void Game::increaseViewRange(float *statustext_time)
        s16 range = g_settings->getS16("viewing_range_nodes_min");
        s16 range_new = range + 10;
        g_settings->set("viewing_range_nodes_min", itos(range_new));
-       statustext = narrow_to_wide("Minimum viewing range changed to "
+       statustext = utf8_to_wide("Minimum viewing range changed to "
                        + itos(range_new));
        *statustext_time = 0;
 }
@@ -2962,7 +2962,7 @@ void Game::decreaseViewRange(float *statustext_time)
                range_new = range;
 
        g_settings->set("viewing_range_nodes_min", itos(range_new));
-       statustext = narrow_to_wide("Minimum viewing range changed to "
+       statustext = utf8_to_wide("Minimum viewing range changed to "
                        + itos(range_new));
        *statustext_time = 0;
 }
@@ -3577,13 +3577,13 @@ void Game::handlePointingAtNode(GameRunData *runData,
        NodeMetadata *meta = map.getNodeMetadata(nodepos);
 
        if (meta) {
-               infotext = narrow_to_wide(meta->getString("infotext"));
+               infotext = utf8_to_wide(meta->getString("infotext"));
        } else {
                MapNode n = map.getNodeNoEx(nodepos);
 
                if (nodedef_manager->get(n).tiledef[0].name == "unknown_node.png") {
                        infotext = L"Unknown node: ";
-                       infotext += narrow_to_wide(nodedef_manager->get(n).name);
+                       infotext += utf8_to_wide(nodedef_manager->get(n).name);
                }
        }
 
@@ -3649,10 +3649,10 @@ void Game::handlePointingAtObject(GameRunData *runData,
                const v3f &player_position,
                bool show_debug)
 {
-       infotext = narrow_to_wide(runData->selected_object->infoText());
+       infotext = utf8_to_wide(runData->selected_object->infoText());
 
        if (infotext == L"" && show_debug) {
-               infotext = narrow_to_wide(runData->selected_object->debugInfoText());
+               infotext = utf8_to_wide(runData->selected_object->debugInfoText());
        }
 
        if (input->getLeftState()) {
@@ -4117,12 +4117,12 @@ void Game::updateGui(float *statustext_time, const RunStats &stats,
                   << ", v_range = " << draw_control->wanted_range
                   << std::setprecision(3)
                   << ", RTT = " << client->getRTT();
-               guitext->setText(narrow_to_wide(os.str()).c_str());
+               guitext->setText(utf8_to_wide(os.str()).c_str());
                guitext->setVisible(true);
        } else if (flags.show_hud || flags.show_chat) {
                std::ostringstream os(std::ios_base::binary);
                os << PROJECT_NAME_C " " << g_version_hash;
-               guitext->setText(narrow_to_wide(os.str()).c_str());
+               guitext->setText(utf8_to_wide(os.str()).c_str());
                guitext->setVisible(true);
        } else {
                guitext->setVisible(false);
@@ -4159,7 +4159,7 @@ void Game::updateGui(float *statustext_time, const RunStats &stats,
                        }
                }
 
-               guitext2->setText(narrow_to_wide(os.str()).c_str());
+               guitext2->setText(utf8_to_wide(os.str()).c_str());
                guitext2->setVisible(true);
 
                core::rect<s32> rect(
index 509d506d42239230da033fda148931a08e67a786..0fd6b574e2bab4397953f84d0b2eb1f13f20fc33 100644 (file)
@@ -102,8 +102,9 @@ const char* MSVC_LocaleLookup(const char* raw_shortname) {
 
        last_raw_value = shortname;
 
-       if (glb_supported_locales.find(narrow_to_wide(shortname)) != glb_supported_locales.end()) {
-               last_full_name = wide_to_narrow(glb_supported_locales[narrow_to_wide(shortname)]);
+       if (glb_supported_locales.find(utf8_to_wide(shortname)) != glb_supported_locales.end()) {
+               last_full_name = wide_to_utf8(
+                       glb_supported_locales[utf8_to_wide(shortname)]);
                return last_full_name.c_str();
        }
 
index 8235efa8ac0b3ef7f998d7dd364860610810060c..9b4e801f7553901b826a3280f22853356f9d99a3 100644 (file)
@@ -39,13 +39,13 @@ void init_gettext(const char *path, const std::string &configured_language,
 void init_gettext(const char *path, const std::string &configured_language);
 #endif
 
-extern wchar_t *narrow_to_wide_c(const char *str);
+extern wchar_t *utf8_to_wide_c(const char *str);
 
 // You must free the returned string!
 // The returned string is allocated using new
 inline const wchar_t *wgettext(const char *str)
 {
-       return narrow_to_wide_c(gettext(str));
+       return utf8_to_wide_c(gettext(str));
 }
 
 inline std::wstring wstrgettext(const std::string &text)
index 3248ef1124e546d9277fd6bf4825bea00c70fcc3..eac9db0c6fceb9908fb2ab200ce2836457bfed0f 100644 (file)
@@ -61,7 +61,7 @@ void TextDestGuiEngine::gotText(const StringMap &fields)
 /******************************************************************************/
 void TextDestGuiEngine::gotText(std::wstring text)
 {
-       m_engine->getScriptIface()->handleMainMenuEvent(wide_to_narrow(text));
+       m_engine->getScriptIface()->handleMainMenuEvent(wide_to_utf8(text));
 }
 
 /******************************************************************************/
@@ -172,7 +172,7 @@ GUIEngine::GUIEngine(       irr::IrrlichtDevice* dev,
                m_sound_manager = &dummySoundManager;
 
        //create topleft header
-       std::wstring t = narrow_to_wide(std::string(PROJECT_NAME_C " ") +
+       std::wstring t = utf8_to_wide(std::string(PROJECT_NAME_C " ") +
                        g_version_hash);
 
        core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(t), g_fontengine->getTextHeight());
@@ -572,13 +572,13 @@ bool GUIEngine::downloadFile(std::string url, std::string target)
 /******************************************************************************/
 void GUIEngine::setTopleftText(std::string append)
 {
-       std::wstring toset = narrow_to_wide(std::string(PROJECT_NAME_C " ") +
-                       g_version_hash);
+       std::wstring toset = utf8_to_wide(std::string(PROJECT_NAME_C " ") +
+               g_version_hash);
 
        if (append != "")
        {
                toset += L" / ";
-               toset += narrow_to_wide(append);
+               toset += utf8_to_wide(append);
        }
 
        m_irr_toplefttext->setText(toset.c_str());
index 9b43ab60295b731d12a439e7d8a3af8219bb94e7..e02407427f51907ae9e88ce3a001f572578cf9a0 100644 (file)
@@ -26,7 +26,7 @@ GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env,
                                std::string title, std::string formname) :
 GUIModalMenu(env, parent, id, menumgr)
 {
-       m_title = narrow_to_wide(title);
+       m_title = utf8_to_wide(title);
        m_parent = parent;
        m_formname = formname;
        m_text_dst = 0;
@@ -87,7 +87,7 @@ void GUIFileSelectMenu::acceptInput() {
                StringMap fields;
 
                if (m_accepted)
-                       fields[m_formname + "_accepted"] = wide_to_narrow(m_fileOpenDialog->getFileName());
+                       fields[m_formname + "_accepted"] = wide_to_utf8(m_fileOpenDialog->getFileName());
                else
                        fields[m_formname + "_canceled"] = m_formname;
 
index 1c1a1f06e7c47c437b976cd73e63b253a3ecb2fe..e2f9994be29cf0fe9926dc9350e616e1ea3a22e7 100644 (file)
@@ -203,8 +203,8 @@ bool GUIPasswordChange::acceptInput()
                                e->setVisible(true);
                        return false;
                }
-               m_client->sendChangePassword(wide_to_narrow(oldpass),
-                       wide_to_narrow(newpass));
+               m_client->sendChangePassword(wide_to_utf8(oldpass),
+                       wide_to_utf8(newpass));
                return true;
 }
 
index e915770a412da09dec79233c745cfde581b1ad45..ed5b0d87b0e07ee27d1fd2a276fcd00354a8fb8a 100644 (file)
@@ -929,7 +929,7 @@ s32 GUITable::allocString(const std::string &text)
        std::map<std::string, s32>::iterator it = m_alloc_strings.find(text);
        if (it == m_alloc_strings.end()) {
                s32 id = m_strings.size();
-               std::wstring wtext = narrow_to_wide(text);
+               std::wstring wtext = utf8_to_wide(text);
                m_strings.push_back(core::stringw(wtext.c_str()));
                m_alloc_strings.insert(std::make_pair(text, id));
                return id;
index 02b69a12cb9c7104c5758f7af87fce843ef2fdfb..dbc4a01a3a63093652442883e7a8dc15547c8098 100644 (file)
@@ -275,7 +275,7 @@ void Hud::drawLuaElements(v3s16 camera_offset) {
                                                                                 (e->number >> 8)  & 0xFF,
                                                                                 (e->number >> 0)  & 0xFF);
                                core::rect<s32> size(0, 0, e->scale.X, text_height * e->scale.Y);
-                               std::wstring text = narrow_to_wide(e->text);
+                               std::wstring text = utf8_to_wide(e->text);
                                core::dimension2d<u32> textsize = font->getDimension(text.c_str());
                                v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2),
                                             (e->align.Y - 1.0) * (textsize.Height / 2));
@@ -310,11 +310,11 @@ void Hud::drawLuaElements(v3s16 camera_offset) {
                                                                                 (e->number >> 8)  & 0xFF,
                                                                                 (e->number >> 0)  & 0xFF);
                                core::rect<s32> size(0, 0, 200, 2 * text_height);
-                               std::wstring text = narrow_to_wide(e->name);
+                               std::wstring text = utf8_to_wide(e->name);
                                font->draw(text.c_str(), size + pos, color);
                                std::ostringstream os;
-                               os<<distance<<e->text;
-                               text = narrow_to_wide(os.str());
+                               os << distance << e->text;
+                               text = utf8_to_wide(os.str());
                                pos.Y += text_height;
                                font->draw(text.c_str(), size + pos, color);
                                break; }
@@ -552,7 +552,7 @@ void drawItemStack(video::IVideoDriver *driver,
        {
                // Get the item count as a string
                std::string text = itos(item.count);
-               v2u32 dim = font->getDimension(narrow_to_wide(text).c_str());
+               v2u32 dim = font->getDimension(utf8_to_wide(text).c_str());
                v2s32 sdim(dim.X,dim.Y);
 
                core::rect<s32> rect2(
index 1ec6a2a1ae603ad71530eee7a1dfce1a90f42392..4cebb2184414915357ce064654c85b6eda41e546 100644 (file)
@@ -228,7 +228,7 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
                if (pkt->getSize() >= 2) {
                        std::wstring wide_reason;
                        *pkt >> wide_reason;
-                       m_access_denied_reason = wide_to_narrow(wide_reason);
+                       m_access_denied_reason = wide_to_utf8(wide_reason);
                }
        }
 }
index 0a6ef4fa85f0837a0cdc6f086d36a10c56f82877..92dfe1020710ea1fdd4437eed16e0bf67397d8c0 100644 (file)
@@ -356,7 +356,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
                DenyAccess_Legacy(pkt->getPeerId(), std::wstring(
                                L"Your client's version is not supported.\n"
                                L"Server version is ")
-                               + narrow_to_wide(g_version_string) + L"."
+                               + utf8_to_wide(g_version_string) + L"."
                );
                return;
        }
@@ -408,15 +408,15 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
                DenyAccess_Legacy(pkt->getPeerId(), std::wstring(
                                L"Your client's version is not supported.\n"
                                L"Server version is ")
-                               + narrow_to_wide(g_version_string) + L",\n"
+                               + utf8_to_wide(g_version_string) + L",\n"
                                + L"server's PROTOCOL_VERSION is "
-                               + narrow_to_wide(itos(SERVER_PROTOCOL_VERSION_MIN))
+                               + utf8_to_wide(itos(SERVER_PROTOCOL_VERSION_MIN))
                                + L"..."
-                               + narrow_to_wide(itos(SERVER_PROTOCOL_VERSION_MAX))
+                               + utf8_to_wide(itos(SERVER_PROTOCOL_VERSION_MAX))
                                + L", client's PROTOCOL_VERSION is "
-                               + narrow_to_wide(itos(min_net_proto_version))
+                               + utf8_to_wide(itos(min_net_proto_version))
                                + L"..."
-                               + narrow_to_wide(itos(max_net_proto_version))
+                               + utf8_to_wide(itos(max_net_proto_version))
                );
                return;
        }
@@ -428,13 +428,13 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
                        DenyAccess_Legacy(pkt->getPeerId(), std::wstring(
                                        L"Your client's version is not supported.\n"
                                        L"Server version is ")
-                                       + narrow_to_wide(g_version_string) + L",\n"
+                                       + utf8_to_wide(g_version_string) + L",\n"
                                        + L"server's PROTOCOL_VERSION (strict) is "
-                                       + narrow_to_wide(itos(LATEST_PROTOCOL_VERSION))
+                                       + utf8_to_wide(itos(LATEST_PROTOCOL_VERSION))
                                        + L", client's PROTOCOL_VERSION is "
-                                       + narrow_to_wide(itos(min_net_proto_version))
+                                       + utf8_to_wide(itos(min_net_proto_version))
                                        + L"..."
-                                       + narrow_to_wide(itos(max_net_proto_version))
+                                       + utf8_to_wide(itos(max_net_proto_version))
                        );
                        return;
                }
@@ -487,7 +487,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
                                        << "tried to connect from " << addr_s << " "
                                        << "but it was disallowed for the following reason: "
                                        << reason << std::endl;
-                       DenyAccess_Legacy(pkt->getPeerId(), narrow_to_wide(reason.c_str()));
+                       DenyAccess_Legacy(pkt->getPeerId(), utf8_to_wide(reason.c_str()));
                        return;
                }
        }
index 111eba5186854ff8311204adbf56feedf8ada81d..d209582e9872c480d145b46c47085b9576b42843 100644 (file)
@@ -1057,7 +1057,7 @@ int ModApiMainMenu::l_get_video_modes(lua_State *L)
 int ModApiMainMenu::l_gettext(lua_State *L)
 {
        std::wstring wtext = wstrgettext((std::string) luaL_checkstring(L, 1));
-       lua_pushstring(L, wide_to_narrow(wtext).c_str());
+       lua_pushstring(L, wide_to_utf8(wtext).c_str());
 
        return 1;
 }
index 0d892631702d5509ef13f8670351c619f04f8fe6..558cc0885f83228f867a072c6f9128d1ff8f56f3 100644 (file)
@@ -307,7 +307,7 @@ int ModApiServer::l_kick_player(lua_State *L)
                lua_pushboolean(L, false); // No such player
                return 1;
        }
-       getServer(L)->DenyAccess_Legacy(player->peer_id, narrow_to_wide(message));
+       getServer(L)->DenyAccess_Legacy(player->peer_id, utf8_to_wide(message));
        lua_pushboolean(L, true);
        return 1;
 }
index e9aee47b2dd1b8dbe1a271f79bce0edaecba18d7..19aaa3e7ab79f7e6fc01a0c5d5e9fdc197289adc 100644 (file)
@@ -1183,7 +1183,7 @@ void Server::ProcessData(NetworkPacket *pkt)
                                        << ban_name << std::endl;
                        // This actually doesn't seem to transfer to the client
                        DenyAccess_Legacy(peer_id, L"Your ip is banned. Banned name was "
-                                       + narrow_to_wide(ban_name));
+                                       + utf8_to_wide(ban_name));
                        return;
                }
        }
index 857b9f0a5ea2ec2de0176e73b06a4161df1e9199..7df4106e8f8a31b5596af9b41dce2a572b4a7ed7 100644 (file)
@@ -102,7 +102,7 @@ void TestSerialization::testSerializeWideString()
        UASSERT(serializeWideString(L"") == mkstr("\0\0"));
 
        // Test basic string
-       UASSERT(serializeWideString(narrow_to_wide("Hello world!")) ==
+       UASSERT(serializeWideString(utf8_to_wide("Hello world!")) ==
                mkstr("\0\14\0H\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d\0!"));
 
        // Test character range
index 187d2a078c5025b1b2c61e0c00adddcece6eac88..60ccc9300061829e35a3c198b93a1688f66f9312 100644 (file)
@@ -168,6 +168,16 @@ std::string wide_to_utf8(const std::wstring &input)
 
 #endif // _WIN32
 
+wchar_t *utf8_to_wide_c(const char *str)
+{
+       std::wstring ret = utf8_to_wide(std::string(str)).c_str();
+       size_t len = ret.length();
+       wchar_t *ret_c = new wchar_t[len + 1];
+       memset(ret_c, 0, (len + 1) * sizeof(wchar_t));
+       memcpy(ret_c, ret.c_str(), len * sizeof(wchar_t));
+       return ret_c;
+}
+
 // You must free the returned string!
 // The returned string is allocated using new
 wchar_t *narrow_to_wide_c(const char *str)
index 6980060e43b060756c760f0cdff0f5cf2495a83c..793baad0ea729f90c3731ea741bca26f2ca3fccf 100644 (file)
@@ -47,6 +47,8 @@ struct FlagDesc {
 std::wstring utf8_to_wide(const std::string &input);
 std::string wide_to_utf8(const std::wstring &input);
 
+wchar_t *utf8_to_wide_c(const char *str);
+
 // NEVER use those two functions unless you have a VERY GOOD reason to
 // they just convert between wide and multibyte encoding
 // multibyte encoding depends on current locale, this is no good, especially on Windows