diff --git a/include/nana/basic_types.hpp b/include/nana/basic_types.hpp index 7eaa4a6b..e990a681 100644 --- a/include/nana/basic_types.hpp +++ b/include/nana/basic_types.hpp @@ -67,7 +67,8 @@ namespace nana } }; - typedef std::basic_string > cistring; + using cistring = std::basic_string>; + using ciwstring = std::basic_string>; namespace detail diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index 3d1fe4d0..68bb38f3 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -20,7 +20,6 @@ #include #include - //Implement workarounds for GCC/MinGW which version is below 4.8.2 #if defined(STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED) namespace std @@ -91,6 +90,7 @@ namespace nana bool is_utf8(const char* str, unsigned len); void throw_not_utf8(const std::string& text); void throw_not_utf8(const char*, unsigned len); + void throw_not_utf8(const char*); std::wstring utf8_cast(const std::string&); std::string utf8_cast(const std::wstring&); @@ -105,7 +105,7 @@ namespace nana #if defined(NANA_WINDOWS) std::string to_osmbstr(const std::string& text_utf8); #else - std::string to_osmbstr(std::string text_utf8) + std::string to_osmbstr(std::string text_utf8); #endif diff --git a/include/nana/filesystem/file_iterator.hpp b/include/nana/filesystem/file_iterator.hpp index dd06a45b..26df3f10 100644 --- a/include/nana/filesystem/file_iterator.hpp +++ b/include/nana/filesystem/file_iterator.hpp @@ -1,12 +1,12 @@ /* * A File Iterator Implementation - * Copyright(C) 2003 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * - * @file: stdex/filesystem/file_iterator.hpp + * @file: filesystem/file_iterator.hpp * @description: * file_iterator is a toolkit for applying each file and directory in a * specified path. @@ -39,7 +39,7 @@ namespace filesystem #ifdef NANA_WINDOWS fileinfo(const WIN32_FIND_DATA& wfd); #elif defined(NANA_POSIX) - fileinfo(const nana::string& filename, const struct stat &); + fileinfo(const std::string& filename, const struct stat &); #endif ::std::string name; @@ -119,10 +119,10 @@ namespace filesystem } value_ = value_type(wfd_); #elif defined(NANA_LINUX) || defined(NANA_MACOS) - auto path = file_path; - if(path.size() && path.back() != '/') - path += '/'; - auto handle = opendir(path.c_str()); + path_ = file_path; + if(path_.size() && path_.back() != '/') + path_ += '/'; + auto handle = opendir(path_.c_str()); end_ = true; if(handle) @@ -141,9 +141,9 @@ namespace filesystem } struct stat fst; - if(stat((path + dnt->d_name).c_str(), &fst) == 0) + if(stat((path_ + dnt->d_name).c_str(), &fst) == 0) { - value_ = value_type(nana::charset(dnt->d_name), fst); + value_ = value_type(dnt->d_name, fst); } else { @@ -226,6 +226,8 @@ namespace filesystem #if defined(NANA_WINDOWS) WIN32_FIND_DATA wfd_; +#else + std::string path_; #endif std::shared_ptr find_ptr_; diff --git a/include/nana/filesystem/filesystem.hpp b/include/nana/filesystem/filesystem.hpp index f25d3b06..864f9608 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -448,17 +448,16 @@ namespace filesystem //bool create_directory(const path& p, error_code& ec) noexcept; bool create_directory(const path& p, const path& attributes); //bool create_directory(const path& p, const path& attributes, error_code& ec) noexcept; - bool create_directory(const nana::string& dir, bool & if_exist); + bool create_directory(const std::wstring& p, bool & if_exist); inline bool create_directory(const path& p, bool & if_exist) - { - return create_directory(p.filename(), if_exist); - }; + { + return create_directory(p.filename(), if_exist); + }; - - bool modified_file_time(const nana::string& file, struct tm&); + bool modified_file_time(const std::wstring& file, struct tm&); - nana::string path_user(); + path path_user(); path current_path(); @@ -468,14 +467,14 @@ namespace filesystem //nana::string path_current(); - //bool remove(const path& p); - //bool remove(const path& p, error_code& ec) noexcept; - bool rmfile(const char* file); + //bool remove(const path& p); + //bool remove(const path& p, error_code& ec) noexcept; + bool rmfile(const path& p); - //uintmax_t remove_all(const path& p); - //uintmax_t remove_all(const path& p, error_code& ec) noexcept; - bool rmdir(const char* dir, bool fails_if_not_empty); - bool rmdir(const wchar_t* dir, bool fails_if_not_empty); + //uintmax_t remove_all(const path& p); + //uintmax_t remove_all(const path& p, error_code& ec) noexcept; + + bool rmdir(const path& p, bool fails_if_not_empty); template std::basic_string parent_path(const std::basic_string& path) diff --git a/include/nana/filesystem/fs_utility.hpp b/include/nana/filesystem/fs_utility.hpp index 6870fce7..fa961dce 100644 --- a/include/nana/filesystem/fs_utility.hpp +++ b/include/nana/filesystem/fs_utility.hpp @@ -28,10 +28,10 @@ namespace filesystem long long filesize(const nana::string& file); bool mkdir(const ::std::string& dir, bool & if_exist); - bool modified_file_time(const nana::string& file, struct tm&); + bool modified_file_time(const ::std::string& file, struct tm&); - nana::string path_user(); - nana::string path_current(); + std::wstring path_user(); + std::wstring path_current(); bool rmfile(const char* file_utf8); bool rmdir(const char* dir, bool fails_if_not_empty); @@ -59,6 +59,7 @@ namespace filesystem std::string text_; #endif }; + }//end namespace filesystem }//end namespace nana diff --git a/include/nana/gui/widgets/categorize.hpp b/include/nana/gui/widgets/categorize.hpp index 43c115f6..c460562a 100644 --- a/include/nana/gui/widgets/categorize.hpp +++ b/include/nana/gui/widgets/categorize.hpp @@ -155,8 +155,9 @@ namespace nana : public widget_object> { public: - typedef T value_type; ///< The type of objects stored - typedef drawerbase::categorize::renderer renderer; ///< The interface for user-defined renderer. + using native_string_type = widget::native_string_type; + using value_type = T; ///< The type of objects stored + using renderer = drawerbase::categorize::renderer; ///< The interface for user-defined renderer. categorize() { @@ -177,13 +178,13 @@ namespace nana categorize(window wd, const std::string& text_utf8, bool visible = true) : categorize(wd, ::nana::rectangle(), visible) { - this->caption(text); + this->caption(text_utf8); } categorize(window wd, const char* text_utf8, bool visible = true) : categorize(wd, ::nana::rectangle(), visible) { - this->caption(text); + this->caption(text_utf8); } categorize(window wd, const std::wstring& text, bool visible = true) diff --git a/source/deploy.cpp b/source/deploy.cpp index 980ad5e9..0f176f63 100644 --- a/source/deploy.cpp +++ b/source/deploy.cpp @@ -14,6 +14,7 @@ #include #include +#include //std::strlen #include #if defined(NANA_WINDOWS) @@ -472,6 +473,13 @@ namespace nana throw std::invalid_argument("The text is not encoded in UTF8"); } + void throw_not_utf8(const char* text) + { + if (!is_utf8(text, std::strlen(text))) + throw std::invalid_argument("The text is not encoded in UTF8"); + + } + std::wstring utf8_cast(const std::string& text) { return ::nana::charset(text, ::nana::unicode::utf8); diff --git a/source/detail/platform_spec_posix.cpp b/source/detail/platform_spec_posix.cpp index 43cdfccd..4f277518 100644 --- a/source/detail/platform_spec_posix.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -555,12 +555,11 @@ namespace detail font_ptr_t ref; #if 1 //Xft if(0 == name || *name == 0) - name = STR("*"); + name = "*"; - std::string nmstr = nana::charset(name); XftFont* handle = 0; std::stringstream ss; - ss< * files = new std::vector; + auto files = new std::vector; std::stringstream ss(reinterpret_cast(data)); while(true) { @@ -1235,7 +1234,7 @@ namespace detail break; } - files->push_back(nana::charset(file)); + files->push_back(file); } if(files->size()) { @@ -1244,6 +1243,8 @@ namespace detail msg.u.mouse_drop.y = self.xdnd_.pos.y; msg.u.mouse_drop.files = files; } + else + delete files; accepted = true; ::XFree(data); diff --git a/source/filesystem/filesystem.cpp b/source/filesystem/filesystem.cpp index 08c46e2b..69270d73 100644 --- a/source/filesystem/filesystem.cpp +++ b/source/filesystem/filesystem.cpp @@ -327,7 +327,7 @@ namespace nana { #endif } - bool modified_file_time(const nana::string& file, struct tm& t) + bool modified_file_time(const std::wstring& file, struct tm& t) { #if defined(NANA_WINDOWS) WIN32_FILE_ATTRIBUTE_DATA attr; @@ -361,17 +361,17 @@ namespace nana { return false; } - bool create_directory(const nana::string& path, bool & if_exist) + bool create_directory(const std::wstring& path, bool & if_exist) { if_exist = false; if (path.size() == 0) return false; - nana::string root; + std::wstring root; #if defined(NANA_WINDOWS) if (path.size() > 3 && path[1] == L':') root = path.substr(0, 3); #elif defined(NANA_LINUX) || defined(NANA_MACOS) - if (path[0] == STR('/')) + if (path[0] == L'/') root = '/'; #endif bool mkstat = false; @@ -412,107 +412,86 @@ namespace nana { return mkstat; } - bool rmfile(const nana::char_t* file) - { -#if defined(NANA_WINDOWS) - bool ret = false; - if (file) - { - ret = (::DeleteFile(file) == TRUE); - if (!ret) - ret = (ERROR_FILE_NOT_FOUND == ::GetLastError()); - } - return ret; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - if (std::remove(static_cast(nana::charset(file)).c_str())) + bool rmfile(const path& p) + { + if(p.empty()) + return false; +#if defined(NANA_WINDOWS) + if (FALSE == ::DeleteFileW(p.c_str())) + return (ERROR_FILE_NOT_FOUND == ::GetLastError()); + + return true; +#elif defined(NANA_POSIX) + if (std::remove(p.c_str())) return (errno == ENOENT); return true; #endif } - bool rmdir(const char* dir_utf8, bool fails_if_not_empty) + + bool rmdir(const path& p, bool fails_if_not_empty) { - bool ret = false; - if (dir_utf8) - { + if(p.empty()) + return false; + #if defined(NANA_WINDOWS) - auto dir = utf8_cast(dir_utf8); - ret = (::RemoveDirectory(dir.c_str()) == TRUE); - if (!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY)) - ret = detail::rm_dir_recursive(dir.c_str()); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - if (::rmdir(dir_utf8)) - { - if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY)) - ret = detail::rm_dir_recursive(dir); - } - else - ret = true; -#endif + if(FALSE != ::RemoveDirectoryW(p.c_str())) + return true; + + if(!fails_if_not_empty && (ERROR_DIR_NOT_EMPTY == ::GetLastError())) + return detail::rm_dir_recursive(p.c_str()); + + return false; +#elif defined(NANA_POSIX) + if(::rmdir(p.c_str())) + { + if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY)) + return detail::rm_dir_recursive(p.c_str()); + + return false; } - return ret; + return true; +#endif } - bool rmdir(const wchar_t* dir, bool fails_if_not_empty) - { - bool ret = false; - if (dir) - { -#if defined(NANA_WINDOWS) - ret = (::RemoveDirectory(dir) == TRUE); - if (!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY)) - ret = detail::rm_dir_recursive(dir); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - if (::rmdir(utf8_cast(dir).c_str())) - { - if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY)) - ret = detail::rm_dir_recursive(dir); - } - else - ret = true; -#endif - } - return ret; - } - - nana::string path_user() + path path_user() { #if defined(NANA_WINDOWS) - nana::char_t path[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, path))) - return path; + wchar_t pstr[MAX_PATH]; + if (SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, pstr))) + return pstr; #elif defined(NANA_LINUX) || defined(NANA_MACOS) - const char * s = ::getenv("HOME"); - if (s) - return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8); + const char * pstr = ::getenv("HOME"); + if (pstr) + return pstr; #endif - return nana::string(); + return path(); } path current_path() { #if defined(NANA_WINDOWS) - nana::char_t buf[MAX_PATH]; - DWORD len = ::GetCurrentDirectory(MAX_PATH, buf); + wchar_t buf[MAX_PATH]; + DWORD len = ::GetCurrentDirectoryW(MAX_PATH, buf); if (len) { if (len > MAX_PATH) { - nana::char_t * p = new nana::char_t[len + 1]; - ::GetCurrentDirectory(len + 1, p); - nana::string s = p; + wchar_t * p = new wchar_t[len + 1]; + ::GetCurrentDirectoryW(len + 1, p); + std::wstring s = p; delete[] p; return s; } - return nana::string(buf); + return buf; } #elif defined(NANA_LINUX) || defined(NANA_MACOS) - const char * s = ::getenv("PWD"); - if (s) - return static_cast(nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8)); + auto pstr = ::getenv("PWD"); + if (pstr) + return pstr; #endif - return nana::string(); + return path(); } }//end namespace filesystem } //end namespace experimental diff --git a/source/filesystem/fs_utility.cpp b/source/filesystem/fs_utility.cpp index fc8b5992..885c9305 100644 --- a/source/filesystem/fs_utility.cpp +++ b/source/filesystem/fs_utility.cpp @@ -257,11 +257,11 @@ namespace filesystem #endif } - bool modified_file_time(const nana::string& file, struct tm& t) + bool modified_file_time(const ::std::string& file, struct tm& t) { #if defined(NANA_WINDOWS) WIN32_FILE_ATTRIBUTE_DATA attr; - if(::GetFileAttributesEx(file.c_str(), GetFileExInfoStandard, &attr)) + if(::GetFileAttributesExW(to_nstring(file).c_str(), GetFileExInfoStandard, &attr)) { FILETIME local_file_time; if(::FileTimeToLocalFileTime(&attr.ftLastWriteTime, &local_file_time)) @@ -282,7 +282,7 @@ namespace filesystem } #elif defined(NANA_LINUX) || defined(NANA_MACOS) struct stat attr; - if(0 == ::stat(static_cast(nana::charset(file)).c_str(), &attr)) + if(0 == ::stat(file.c_str(), &attr)) { t = *(::localtime(&attr.st_ctime)); return true; @@ -301,7 +301,7 @@ namespace filesystem if(path.size() > 3 && path[1] == ':') root = path.substr(0, 3); #elif defined(NANA_LINUX) || defined(NANA_MACOS) - if(path[0] == STR('/')) + if(path[0] == '/') root = '/'; #endif bool mkstat = false; diff --git a/source/gui/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index 74dbeba1..dbfe6c46 100644 --- a/source/gui/detail/native_window_interface.cpp +++ b/source/gui/detail/native_window_interface.cpp @@ -1096,7 +1096,7 @@ namespace nana{ ::XSetWMName(restrict::spec.open_display(), reinterpret_cast(wd), &name); ::XChangeProperty(restrict::spec.open_display(), reinterpret_cast(wd), restrict::spec.atombase().net_wm_name, restrict::spec.atombase().utf8_string, 8, - PropModeReplace, reinterpret_cast(text), mbstr.size()); + PropModeReplace, reinterpret_cast(text), title.size()); #endif } diff --git a/source/gui/filebox.cpp b/source/gui/filebox.cpp index c6770e5c..22a322ae 100644 --- a/source/gui/filebox.cpp +++ b/source/gui/filebox.cpp @@ -38,16 +38,16 @@ namespace nana { struct item_fs { - nana::string name; + std::string name; ::tm modified_time; bool directory; nana::long_long_t bytes; friend listbox::iresolver& operator>>(listbox::iresolver& ires, item_fs& m) { - nana::string type; + std::wstring type; ires>>m.name>>type>>type; - m.directory = (type == STR("Directory")); + m.directory = (type == L"Directory"); return ires; } @@ -65,16 +65,16 @@ namespace nana ores<= 1024) { @@ -108,10 +108,11 @@ namespace nana if(pos + 2 < s.size()) s.erase(pos + 2); } - return static_cast(nana::charset(s)) + ustr[uid]; + + return s + ustr[uid]; } ss<&) { auto path = path_.caption(); - auto root = path.substr(0, path.find(STR('/'))); - if(root == STR("HOME")) - path.replace(0, 4, nana::filesystem::path_user()); - else if(root == STR("FILESYSTEM")) + auto root = path.substr(0, path.find('/')); + if(root == "HOME") + path.replace(0, 4, to_nstring(nana::filesystem::path_user())); + else if(root == "FILESYSTEM") path.erase(0, 10); else throw std::runtime_error("Nana.GUI.Filebox: Wrong categorize path"); - if(path.size() == 0) path = STR("/"); + if(path.size() == 0) path = "/"; _m_load_cat_path(path); }); filter_.create(*this); filter_.multi_lines(false); - filter_.tip_string(STR("Filter")); + filter_.tip_string("Filter"); filter_.events().key_release.connect_unignorable([this](const arg_keyboard&) { @@ -161,23 +162,23 @@ namespace nana }); btn_folder_.create(*this); - btn_folder_.caption(STR("&New Folder")); + btn_folder_.caption("&New Folder"); btn_folder_.events().click.connect_unignorable([this](const arg_click&) { form fm(this->handle(), API::make_center(*this, 300, 35)); - fm.caption(STR("Name the new folder")); + fm.caption("Name the new folder"); textbox folder(fm, nana::rectangle(5, 5, 160, 25)); folder.multi_lines(false); button btn(fm, nana::rectangle(170, 5, 60, 25)); - btn.caption(STR("Create")); + btn.caption("Create"); btn.events().click.connect_unignorable(folder_creator(*this, fm, folder)); button btn_cancel(fm, nana::rectangle(235, 5, 60, 25)); - btn_cancel.caption(STR("Cancel")); + btn_cancel.caption("Cancel"); btn_cancel.events().click.connect_unignorable([&fm](const arg_click&) { @@ -189,17 +190,17 @@ namespace nana tree_.create(*this); ls_file_.create(*this); - ls_file_.append_header(STR("Name"), 190); - ls_file_.append_header(STR("Modified"), 145); - ls_file_.append_header(STR("Type"), 80); - ls_file_.append_header(STR("Size"), 70); + ls_file_.append_header("Name", 190); + ls_file_.append_header("Modified", 145); + ls_file_.append_header("Type", 80); + ls_file_.append_header("Size", 70); auto fn_sel_file = [this](const arg_mouse& arg){ _m_sel_file(arg); }; ls_file_.events().dbl_click.connect_unignorable(fn_sel_file); ls_file_.events().mouse_down.connect_unignorable(fn_sel_file); - ls_file_.set_sort_compare(0, [](const nana::string& a, nana::any* fs_a, const nana::string& b, nana::any* fs_b, bool reverse) -> bool + ls_file_.set_sort_compare(0, [](const std::string& a, nana::any* fs_a, const std::string& b, nana::any* fs_b, bool reverse) -> bool { int dira = fs_a->get()->directory ? 1 : 0; int dirb = fs_b->get()->directory ? 1 : 0; @@ -211,8 +212,8 @@ namespace nana while(true) { - std::size_t pos_a = a.find_first_of(STR("0123456789"), seek_a); - std::size_t pos_b = b.find_first_of(STR("0123456789"), seek_b); + std::size_t pos_a = a.find_first_of("0123456789", seek_a); + std::size_t pos_b = b.find_first_of("0123456789", seek_b); if((pos_a != a.npos) && (pos_a == pos_b)) { @@ -222,11 +223,11 @@ namespace nana if(text_a != text_b) return (reverse ? text_a > text_b : text_a < text_b); - std::size_t end_a = a.find_first_not_of(STR("0123456789"), pos_a + 1); - std::size_t end_b = b.find_first_not_of(STR("0123456789"), pos_b + 1); + std::size_t end_a = a.find_first_not_of("0123456789", pos_a + 1); + std::size_t end_b = b.find_first_not_of("0123456789", pos_b + 1); - nana::string num_a = a.substr(pos_a, end_a != a.npos ? end_a - pos_a : a.npos); - nana::string num_b = b.substr(pos_b, end_b != b.npos ? end_b - pos_b : b.npos); + auto num_a = a.substr(pos_a, end_a != a.npos ? end_a - pos_a : a.npos); + auto num_b = b.substr(pos_b, end_b != b.npos ? end_b - pos_b : b.npos); if(num_a != num_b) { @@ -253,7 +254,7 @@ namespace nana return (reverse ? cia > cib : cia < cib); return (reverse ? cia.substr(seek_a) > cib.substr(seek_b) : cia.substr(seek_a) < cib.substr(seek_b)); }); - ls_file_.set_sort_compare(2, [](const nana::string& a, nana::any* anyptr_a, const nana::string& b, nana::any* anyptr_b, bool reverse) -> bool + ls_file_.set_sort_compare(2, [](const std::string& a, nana::any* anyptr_a, const std::string& b, nana::any* anyptr_b, bool reverse) -> bool { int dir1 = anyptr_a->get()->directory ? 1 : 0; int dir2 = anyptr_b->get()->directory ? 1 : 0; @@ -262,7 +263,7 @@ namespace nana return (reverse ? a > b : a < b); }); - ls_file_.set_sort_compare(3, [this](const nana::string&, nana::any* anyptr_a, const nana::string&, nana::any* anyptr_b, bool reverse) -> bool + ls_file_.set_sort_compare(3, [this](const std::string&, nana::any* anyptr_a, const std::string&, nana::any* anyptr_b, bool reverse) -> bool { item_fs * fsa = anyptr_a->get(); item_fs * fsb = anyptr_b->get(); @@ -270,7 +271,7 @@ namespace nana }); lb_file_.create(*this); - lb_file_.caption(STR("File:")); + lb_file_.caption("File:"); tb_file_.create(*this); tb_file_.multi_lines(false); @@ -286,14 +287,14 @@ namespace nana cb_types_.events().selected.connect_unignorable([this](const arg_combox&){ _m_list_fs(); }); btn_ok_.create(*this); - btn_ok_.caption(STR("&OK")); + btn_ok_.caption("&OK"); btn_ok_.events().click.connect_unignorable([this](const arg_click&) { _m_ok(); }); btn_cancel_.create(*this); - btn_cancel_.caption(STR("&Cancel")); + btn_cancel_.caption("&Cancel"); btn_cancel_.events().click.connect_unignorable([this](const arg_click&) { @@ -305,25 +306,25 @@ namespace nana _m_init_tree(); if(0 == title.size()) - caption(io_read ? STR("Open") : STR("Save As")); + caption(io_read ? "Open" : "Save As"); else caption(title); } - void def_extension(const nana::string& ext) + void def_extension(const std::string& ext) { def_ext_ = ext; } - void load_fs(const nana::string& init_path, const nana::string& init_file) + void load_fs(const std::string& init_path, const std::string& init_file) { //Simulate the behavior like Windows7's lpstrInitialDir(http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx) //Phase 1 - nana::string dir; + std::string dir; - auto pos = init_file.find_last_of(STR("\\/")); - nana::string file_with_path_removed = (pos != init_file.npos ? init_file.substr(pos + 1) : init_file); + auto pos = init_file.find_last_of("\\/"); + auto file_with_path_removed = (pos != init_file.npos ? init_file.substr(pos + 1) : init_file); if(saved_init_path != init_path) { @@ -343,29 +344,29 @@ namespace nana else dir = saved_selected_path; - _m_load_cat_path(dir.size() ? dir : nana::filesystem::path_user()); + _m_load_cat_path(dir.size() ? dir : to_nstring(nana::filesystem::path_user())); tb_file_.caption(file_with_path_removed); } - void add_filter(const nana::string& desc, const nana::string& type) + void add_filter(const std::string& desc, const std::string& type) { std::size_t i = cb_types_.the_number_of_options(); cb_types_.push_back(desc); if(0 == i) cb_types_.option(0); - std::vector v; + std::vector v; std::size_t beg = 0; while(true) { - auto pos = type.find(STR(';'), beg); + auto pos = type.find(';', beg); auto ext = type.substr(beg, pos == type.npos ? type.npos : pos - beg); - auto dot = ext.find(STR('.')); + auto dot = ext.find('.'); if((dot != ext.npos) && (dot + 1 < ext.size())) { ext.erase(0, dot + 1); - if(ext == STR("*")) + if(ext == "*") { v.clear(); break; @@ -381,12 +382,12 @@ namespace nana cb_types_.anyobj(i, v); } - bool file(nana::string& fs) const + bool file(std::string& fs) const { if(selection_.type == kind::none) return false; - auto pos = selection_.target.find_last_of(STR("\\/")); + auto pos = selection_.target.find_last_of("\\/"); if(pos != selection_.target.npos) saved_selected_path = selection_.target.substr(0, pos); else @@ -423,13 +424,13 @@ namespace nana //The path in linux is starting with the character '/', the name of root key should be //"FS.HOME", "FS.ROOT". Because a key of the tree widget should not be '/' - nodes_.home = tree_.insert(STR("FS.HOME"), STR("Home")); + nodes_.home = tree_.insert("FS.HOME", "Home"); nodes_.home.value(kind::filesystem); - nodes_.filesystem = tree_.insert(STR("FS.ROOT"), STR("Filesystem")); + nodes_.filesystem = tree_.insert("FS.ROOT", "Filesystem"); nodes_.filesystem.value(kind::filesystem); file_iterator end; - for(file_iterator i(path_user()); i != end; ++i) + for(file_iterator i(to_nstring(path_user())); i != end; ++i) { if((false == i->directory) || (i->name.size() && i->name[0] == '.')) continue; @@ -441,7 +442,7 @@ namespace nana } } - for(file_iterator i(STR("/")); i != end; ++i) + for(file_iterator i("/"); i != end; ++i) { if((false == i->directory) || (i->name.size() && i->name[0] == '.')) continue; @@ -462,33 +463,33 @@ namespace nana { if(arg.operated && (arg.item.value() == kind::filesystem)) { - auto path = tree_.make_key_path(arg.item, STR("/")) + STR("/"); + auto path = tree_.make_key_path(arg.item, "/") + "/"; _m_resolute_path(path); _m_load_cat_path(path); } }); } - nana::string _m_resolute_path(nana::string& path) + std::string _m_resolute_path(std::string& path) { - auto pos = path.find(STR('/')); + auto pos = path.find('/'); if(pos != path.npos) { auto begstr = path.substr(0, pos); - if(begstr == STR("FS.HOME")) - path.replace(0, 7, nana::filesystem::path_user()); + if(begstr == "FS.HOME") + path.replace(0, 7, to_nstring(nana::filesystem::path_user())); else path.erase(0, pos); return begstr; } - return nana::string(); + return std::string(); } - void _m_load_path(const nana::string& path) + void _m_load_path(const std::string& path) { addr_.filesystem = path; - if(addr_.filesystem.size() && addr_.filesystem[addr_.filesystem.size() - 1] != STR('/')) - addr_.filesystem += STR('/'); + if(addr_.filesystem.size() && addr_.filesystem[addr_.filesystem.size() - 1] != '/') + addr_.filesystem += '/'; file_container_.clear(); @@ -497,7 +498,7 @@ namespace nana file_iterator end; for(file_iterator i(path); i != end; ++i) { - if((i->name.size() == 0) || (i->name[0] == STR('.'))) + if((i->name.size() == 0) || (i->name[0] == '.')) continue; item_fs m; m.name = i->name; @@ -522,32 +523,32 @@ namespace nana std::sort(file_container_.begin(), file_container_.end(), pred_sort_fs()); } - void _m_load_cat_path(nana::string path) + void _m_load_cat_path(std::string path) { - if((path.size() == 0) || (path[path.size() - 1] != STR('/'))) - path += STR('/'); + if((path.size() == 0) || (path[path.size() - 1] != '/')) + path += '/'; auto beg_node = tree_.selected(); while(!beg_node.empty() && (beg_node != nodes_.home) && (beg_node != nodes_.filesystem)) beg_node = beg_node.owner(); - auto head = nana::filesystem::path_user(); + auto head = to_nstring(nana::filesystem::path_user()); if(path.size() >= head.size() && (path.substr(0, head.size()) == head)) {//This is HOME - path_.caption(STR("HOME")); + path_.caption("HOME"); if(beg_node != nodes_.home) nodes_.home->select(true); } else { //Redirect to '/' - path_.caption(STR("FILESYSTEM")); + path_.caption("FILESYSTEM"); if(beg_node != nodes_.filesystem) nodes_.filesystem->select(true); head.clear(); } - if(head.size() == 0 || head[head.size() - 1] != STR('/')) - head += STR('/'); + if(head.size() == 0 || head[head.size() - 1] != '/') + head += '/'; nana::filesystem::file_iterator end; for(nana::filesystem::file_iterator i(head); i != end; ++i) @@ -556,17 +557,17 @@ namespace nana path_.childset(i->name, 0); } auto cat_path = path_.caption(); - if(cat_path.size() && cat_path[cat_path.size() - 1] != STR('/')) - cat_path += STR('/'); + if(cat_path.size() && cat_path[cat_path.size() - 1] != '/') + cat_path += '/'; auto beg = head.size(); while(true) { - auto pos = path.find(STR('/'), beg); + auto pos = path.find('/', beg); auto folder = path.substr(beg, pos != path.npos ? pos - beg: path.npos); if(folder.size() == 0) break; - (cat_path += folder) += STR('/'); - (head += folder) += STR('/'); + (cat_path += folder) += '/'; + (head += folder) += '/'; path_.caption(cat_path); for(nana::filesystem::file_iterator i(head); i != end; ++i) @@ -583,7 +584,7 @@ namespace nana _m_list_fs(); } - bool _m_filter_allowed(const nana::string& name, bool is_dir, const nana::string& filter, const std::vector* extension) const + bool _m_filter_allowed(const std::string& name, bool is_dir, const std::string& filter, const std::vector* extension) const { if(filter.size() && (name.find(filter) == filter.npos)) return false; @@ -601,12 +602,12 @@ namespace nana void _m_list_fs() { - nana::string filter = filter_.caption(); + auto filter = filter_.caption(); ls_file_.auto_draw(false); ls_file_.clear(); - std::vector* ext_types = cb_types_.anyobj >(cb_types_.option()); + auto ext_types = cb_types_.anyobj >(cb_types_.option()); auto cat = ls_file_.at(0); for(auto & fs: file_container_) { @@ -618,7 +619,7 @@ namespace nana ls_file_.auto_draw(true); } - void _m_finish(kind::t type, const nana::string& tar) + void _m_finish(kind::t type, const std::string& tar) { selection_.target = tar; selection_.type = type; @@ -635,11 +636,11 @@ namespace nana { auto path = tx_path_.caption(); - msgbox mb(fm_, STR("Create Folder")); + msgbox mb(fm_, "Create Folder"); mb.icon(msgbox::icon_warning); - if(0 == path.size() || path[0] == STR('.') || path[0] == STR('/')) + if(0 == path.size() || path[0] == '.' || path[0] == '/') { - mb< * exts = cb_types_.anyobj >(cb_types_.option()); + auto exts = cb_types_.anyobj >(cb_types_.option()); if(0 == exts || exts->size() == 0) return false; auto & ext = exts->at(0); - if(def_ext_[0] != STR('.')) - tar += STR('.'); + if(def_ext_[0] != '.') + tar += '.'; tar += ext; return true; } @@ -703,7 +704,7 @@ namespace nana if(event_code::dbl_click == arg.evt_code) { if(m.directory) - _m_load_cat_path(addr_.filesystem + m.name + STR("/")); + _m_load_cat_path(addr_.filesystem + m.name + "/"); else _m_finish(kind::filesystem, addr_.filesystem + m.name); } @@ -724,16 +725,16 @@ namespace nana auto file = tb_file_.caption(); if(file.size()) { - if(file[0] == STR('.')) + if(file[0] == L'.') { msgbox mb(*this, caption()); mb.icon(msgbox::icon_warning); - mb<()) { - nana::string path = tree_.make_key_path(node, STR("/")) + STR("/"); + auto path = tree_.make_key_path(node, "/") + "/"; _m_resolute_path(path); nana::filesystem::file_iterator end; @@ -814,7 +815,7 @@ namespace nana } private: bool io_read_; - nana::string def_ext_; + std::string def_ext_; place place_; categorize path_; @@ -835,22 +836,22 @@ namespace nana }nodes_; std::vector file_container_; - struct path_tag + struct path_rep { - nana::string filesystem; + std::string filesystem; }addr_; - struct selection_tag + struct selection_rep { kind::t type; - nana::string target; + std::string target; }selection_; - static nana::string saved_init_path; - static nana::string saved_selected_path; + static std::string saved_init_path; + static std::string saved_selected_path; };//end class filebox_implement - nana::string filebox_implement::saved_init_path; - nana::string filebox_implement::saved_selected_path; + std::string filebox_implement::saved_init_path; + std::string filebox_implement::saved_selected_path; #endif //class filebox @@ -1040,11 +1041,11 @@ namespace nana { for(auto & f: impl_->filters) { - nana::string fs = f.type; + std::string fs = f.type; std::size_t pos = 0; while(true) { - pos = fs.find(STR(" "), pos); + pos = fs.find(" ", pos); if(pos == fs.npos) break; fs.erase(pos); @@ -1053,7 +1054,7 @@ namespace nana } } else - fb.add_filter(STR("All Files"), STR("*.*")); + fb.add_filter("All Files", "*.*"); fb.load_fs(impl_->path, impl_->file); diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index b25efe40..55bbeb4c 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -38,7 +38,7 @@ namespace nana : public form { public: - msgbox_window(window wd, const ::nana::string& title, msgbox::button_t btn, msgbox::icon_t ico) + msgbox_window(window wd, const std::string& title, msgbox::button_t btn, msgbox::icon_t ico) : form(wd, rectangle(1, 1, 1, 1), appear::decorate<>()), owner_(wd), pick_(msgbox::pick_yes) { @@ -61,14 +61,14 @@ namespace nana { _m_click(arg); }); - yes_.caption(STR("OK")); + yes_.caption("OK"); width_pixel += 77; if(msgbox::yes_no == btn || msgbox::yes_no_cancel == btn) { - yes_.caption(STR("Yes")); + yes_.caption("Yes"); no_.create(*this); - no_.caption(STR("No")); + no_.caption("No"); no_.events().click.connect_unignorable([this](const arg_click& arg) { _m_click(arg); @@ -79,7 +79,7 @@ namespace nana if(msgbox::yes_no_cancel == btn) { cancel_.create(*this); - cancel_.caption(STR("Cancel")); + cancel_.caption("Cancel"); cancel_.events().click.connect_unignorable([this](const arg_click& arg) { _m_click(arg); @@ -843,7 +843,7 @@ namespace nana void inputbox::text::tip_string(std::wstring tip) { - impl_->tip.swap(utf8_cast(tip)); + impl_->tip = utf8_cast(tip); } void inputbox::text::tip_string(std::string tip_utf8) diff --git a/source/gui/widgets/button.cpp b/source/gui/widgets/button.cpp index 61c3f082..bbd36e19 100644 --- a/source/gui/widgets/button.cpp +++ b/source/gui/widgets/button.cpp @@ -400,14 +400,12 @@ namespace nana{ namespace drawerbase button::button(window wd, const std::string& text, bool visible) { - throw_not_utf8(text); create(wd, rectangle(), visible); caption(text); } button::button(window wd, const char* text, bool visible) { - throw_not_utf8(text, std::strlen(text)); create(wd, rectangle(), visible); caption(text); } diff --git a/source/gui/widgets/combox.cpp b/source/gui/widgets/combox.cpp index 18592de0..bb1d56cf 100644 --- a/source/gui/widgets/combox.cpp +++ b/source/gui/widgets/combox.cpp @@ -997,7 +997,7 @@ namespace nana auto editor = _m_impl().editor(); if (editor) - editor->text(to_nstring(str)); + editor->text(to_wstring(str)); API::refresh_window(*this); } diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index a433a759..828bea16 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -166,7 +166,7 @@ namespace nana oresolver& oresolver::operator<<(const wchar_t* text) { - cells_.emplace_back(utf8_cast(text)); + cells_.emplace_back(to_utf8(text)); return *this; } @@ -178,13 +178,13 @@ namespace nana oresolver& oresolver::operator<<(const std::wstring& text) { - cells_.emplace_back(utf8_cast(text)); + cells_.emplace_back(to_utf8(text)); return *this; } oresolver& oresolver::operator<<(std::wstring&& text) { - cells_.emplace_back(utf8_cast(text)); + cells_.emplace_back(to_utf8(text)); return *this; } @@ -298,7 +298,7 @@ namespace nana iresolver& iresolver::operator>>(std::wstring& text) { if (pos_ < cells_.size()) - text = utf8_cast(cells_[pos_++].text); + text = to_wstring(cells_[pos_++].text); return *this; } @@ -353,21 +353,20 @@ namespace nana return idx; } - std::string to_string(const export_options& exp_opt) const - { - std::string head_str; - bool first{true}; - for( size_type idx{}; idxstring({ x + 20, y + txtoff }, categ.text, txt_color); - native_string_type str = L'(' + to_nstring(categ.items.size()) + L')'; + native_string_type str = to_nstring('(' + std::to_string(categ.items.size()) + ')'); auto text_s = graph->text_extent_size(categ.text).width; auto extend_text_w = text_s + graph->text_extent_size(str).width; @@ -3822,7 +3821,7 @@ namespace nana item_proxy& item_proxy::text(size_type col, std::wstring str) { - ess_->lister.text(cat_, pos_.item, col, utf8_cast(str), columns()); + ess_->lister.text(cat_, pos_.item, col, to_utf8(str), columns()); ess_->update(); return *this; } @@ -3864,7 +3863,7 @@ namespace nana bool item_proxy::operator==(const std::wstring& s) const { - return (ess_->lister.get_cells(cat_, pos_.item).at(0).text == utf8_cast(s)); + return (ess_->lister.get_cells(cat_, pos_.item).at(0).text == to_utf8(s)); } item_proxy & item_proxy::operator=(const item_proxy& rhs) @@ -4007,7 +4006,7 @@ namespace nana size_type pos = 0; for (auto & txt : arg) { - ip.text(pos++, utf8_cast(txt)); + ip.text(pos++, to_utf8(txt)); if (pos >= items) break; } @@ -4062,7 +4061,7 @@ namespace nana std::string cat_proxy::text() const { internal_scope_guard lock; - return utf8_cast(cat_->text); + return to_utf8(cat_->text); } void cat_proxy::push_back(std::string s) @@ -4479,7 +4478,7 @@ namespace nana void listbox::insert(const index_pair& pos, std::wstring text) { - insert(pos, utf8_cast(text)); + insert(pos, to_utf8(text)); } void listbox::checkable(bool chkable) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index b84c515e..d061395e 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1179,7 +1179,7 @@ namespace nana{ namespace widgets if ( kwptr->kwbase.empty() || text.empty() ) return; - using index = std::wstring::size_type; + using index = std::wstring::size_type; std::vector entities; @@ -1202,7 +1202,7 @@ namespace nana{ namespace widgets return true; }; - ::nana::cistring cistr; + ::nana::ciwstring cistr; for (auto & ds : kwptr->kwbase) { index pos{0} ; diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 316b36d8..f53d0222 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -218,7 +218,7 @@ namespace drawerbase { textbox::textbox(window wd, const char* text, bool visible) { - throw_not_utf8(text, std::strlen(text)); + throw_not_utf8(text); create(wd, rectangle(), visible); caption(text); } diff --git a/source/gui/widgets/widget.cpp b/source/gui/widgets/widget.cpp index 7b7725b4..11b65165 100644 --- a/source/gui/widgets/widget.cpp +++ b/source/gui/widgets/widget.cpp @@ -56,7 +56,7 @@ namespace nana std::string widget::caption() const throw() { - return utf8_cast(_m_caption()); + return to_utf8(_m_caption()); } std::wstring widget::caption_wstring() const throw() @@ -64,7 +64,7 @@ namespace nana #if defined(NANA_WINDOWS) return _m_caption(); #else - return utf8_cast(_m_caption()); + return to_wstring(_m_caption()); #endif } diff --git a/source/paint/image.cpp b/source/paint/image.cpp index 9b10e696..53fc1c34 100644 --- a/source/paint/image.cpp +++ b/source/paint/image.cpp @@ -209,7 +209,12 @@ namespace paint image::image_impl_interface * helper = nullptr; { - std::transform(extension.begin(), extension.end(), extension.begin(), std::tolower); + std::transform(extension.begin(), extension.end(), extension.begin(), [](int ch) + { + if('A' <= ch && ch <= 'Z') + ch -= ('A' - 'a'); + return ch; + }); #if defined(NANA_WINDOWS) const wchar_t* ext_ico = L".ico"; diff --git a/source/system/dataexch.cpp b/source/system/dataexch.cpp index 1c4b34ee..cf18c153 100644 --- a/source/system/dataexch.cpp +++ b/source/system/dataexch.cpp @@ -32,8 +32,8 @@ namespace nana{ namespace system{ #ifdef NANA_WINDOWS std::wstring wstr = ::nana::charset(text, nana::unicode::utf8); _m_set(format::text, wstr.c_str(), (wstr.length() + 1) * sizeof(wchar_t)); -#else - _m_set(format::text, text, std::strlen(text) + 1); +#elif defined(NANA_X11) + _m_set(format::text, text.c_str(), text.length() + 1); #endif } @@ -212,14 +212,14 @@ namespace nana{ namespace system{ if(owner) { Atom atom_type; - switch(type) + switch(fmt) { case format::text: atom_type = spec.atombase().utf8_string; break; default: return false; } - spec.write_selection(owner, spec.atombase().utf8_string, buf, size); + spec.write_selection(owner, atom_type, buf, size); return true; } #endif @@ -265,7 +265,7 @@ namespace nana{ namespace system{ { Atom atom; - switch(type) + switch(fmt) { case format::text: atom = spec.atombase().utf8_string; break; default: