Merge authors: poy (poy) ------------------------------------------------------------ revno: 18 [merge] committer: poy <p...@123gen.com> branch nick: DevPlugin timestamp: Sun 2013-03-03 20:21:49 +0100 message: merge modified: pluginsdk/PluginDefs.h pluginsdk/Util.cpp
-- lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin Your team Dcplusplus-team is subscribed to branch lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin. To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin/+edit-subscription
=== modified file 'pluginsdk/PluginDefs.h' --- pluginsdk/PluginDefs.h 2013-01-29 18:14:01 +0000 +++ pluginsdk/PluginDefs.h 2013-03-03 19:21:04 +0000 @@ -74,7 +74,7 @@ #define DCINTF_DCPP_QUEUE_VER 2 #define DCINTF_DCPP_UTILS "dcpp.utils.DCUtils" /* Utility and convenience functions */ -#define DCINTF_DCPP_UTILS_VER 1 +#define DCINTF_DCPP_UTILS_VER 2 #define DCINTF_DCPP_TAGGER "dcpp.xml.DCTagger" /* Manipulation of an XML tagger */ #define DCINTF_DCPP_TAGGER_VER 2 @@ -409,6 +409,8 @@ /* Utility API version */ uint32_t apiVersion; + /* These functions attempt a conversion; they return the required buffer size. */ + size_t (DCAPI *to_utf8) (char* dst, const char* src, size_t n); size_t (DCAPI *from_utf8) (char* dst, const char* src, size_t n); === modified file 'pluginsdk/Util.cpp' --- pluginsdk/Util.cpp 2013-01-18 21:37:14 +0000 +++ pluginsdk/Util.cpp 2013-03-03 19:21:04 +0000 @@ -39,8 +39,12 @@ string res; if(str.empty()) return res; - res.resize(str.size() + 1); - res.resize(utils->wcs_to_utf8(&res[0], &str[0], res.size())); + auto n = str.size() * 3 / 2; + res.resize(n); + res.resize(utils->wcs_to_utf8(&res[0], &str[0], n)); + if(res.size() > n) { + utils->wcs_to_utf8(&res[0], &str[0], res.size()); + } return res; } @@ -48,8 +52,12 @@ wstring res; if(str.empty()) return res; - res.resize(str.size() + 1); - res.resize(utils->utf8_to_wcs(&res[0], &str[0], str.size())); + auto n = str.size(); + res.resize(n); + res.resize(utils->utf8_to_wcs(&res[0], &str[0], n)); + if(res.size() > n) { + utils->utf8_to_wcs(&res[0], &str[0], res.size()); + } return res; } @@ -61,8 +69,12 @@ string res; if(str.empty()) return res; - res.resize(str.size() + 1); - res.resize(utils->from_utf8(&res[0], &str[0], res.size())); + auto n = str.size() * 3 / 2; + res.resize(n); + res.resize(utils->from_utf8(&res[0], &str[0], n)); + if(res.size() > n) { + utils->from_utf8(&res[0], &str[0], res.size()); + } return res; } @@ -70,8 +82,12 @@ string res; if(str.empty()) return res; - res.resize(str.size() + 1); - res.resize(utils->to_utf8(&res[0], &str[0], str.size())); + auto n = str.size(); + res.resize(n); + res.resize(utils->to_utf8(&res[0], &str[0], n)); + if(res.size() > n) { + utils->to_utf8(&res[0], &str[0], res.size()); + } return res; }
_______________________________________________ Mailing list: https://launchpad.net/~linuxdcpp-team Post to : linuxdcpp-team@lists.launchpad.net Unsubscribe : https://launchpad.net/~linuxdcpp-team More help : https://help.launchpad.net/ListHelp