← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcpp-plugin-sdk-cpp/TestPlugin] Rev 12: merge

 

Merge authors:
  poy (poy)
------------------------------------------------------------
revno: 12 [merge]
committer: poy <poy@xxxxxxxxxx>
branch nick: TestPlugin
timestamp: Sun 2013-03-03 20:22:37 +0100
message:
  merge
modified:
  pluginsdk/PluginDefs.h
  pluginsdk/Util.cpp


--
lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/TestPlugin
https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/TestPlugin

Your team Dcplusplus-team is subscribed to branch lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/TestPlugin.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/TestPlugin/+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;
 }