summaryrefslogtreecommitdiff
path: root/src/utils/stringutils.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-05 02:20:12 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-05 02:20:12 +0300
commit54fd7526e6a1d2d161fda10bccd609ec078b8fa9 (patch)
treeb2ef7a31891a0351f1053f6804a8abe4ff1ea895 /src/utils/stringutils.cpp
parentbc4957b24e6939f4e681e9412f9bbdd483a6bc35 (diff)
downloadmanaverse-54fd7526e6a1d2d161fda10bccd609ec078b8fa9.tar.gz
manaverse-54fd7526e6a1d2d161fda10bccd609ec078b8fa9.tar.bz2
manaverse-54fd7526e6a1d2d161fda10bccd609ec078b8fa9.tar.xz
manaverse-54fd7526e6a1d2d161fda10bccd609ec078b8fa9.zip
Add fast versions for function toString for different types.
Diffstat (limited to 'src/utils/stringutils.cpp')
-rw-r--r--src/utils/stringutils.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index b4e6e01b0..706135a56 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -709,6 +709,80 @@ std::string toStringPrint(const unsigned int val)
return str;
}
+std::string toString(unsigned int num)
+{
+ char buf[30];
+ buf[29] = '\0';
+ size_t idx = 28;
+ do
+ buf[idx--] = static_cast<char>((num % 10) + '0');
+ while(num /= 10);
+ return buf + idx + 1;
+}
+
+std::string toString(size_t num)
+{
+ char buf[100];
+ buf[99] = '\0';
+ size_t idx = 98;
+ do
+ buf[idx--] = static_cast<char>((num % 10) + '0');
+ while(num /= 10);
+ return buf + idx + 1;
+}
+
+std::string toString(uint16_t num)
+{
+ char buf[10];
+ buf[9] = '\0';
+ size_t idx = 8;
+ do
+ buf[idx--] = static_cast<char>((num % 10) + '0');
+ while(num /= 10);
+ return buf + idx + 1;
+}
+
+std::string toString(unsigned char num)
+{
+ char buf[5];
+ buf[4] = '\0';
+ size_t idx = 3;
+ do
+ buf[idx--] = static_cast<char>((num % 10) + '0');
+ while(num /= 10);
+ return buf + idx + 1;
+}
+
+std::string toString(int num)
+{
+ char buf[30];
+ bool useSign(false);
+ buf[29] = '\0';
+ size_t idx = 28;
+
+ if (num < 0)
+ {
+ useSign = true;
+ num = -num;
+ }
+ do
+ buf[idx--] = static_cast<char>((num % 10) + '0');
+ while(num /= 10);
+ if (useSign)
+ buf[idx--] = '-';
+ return buf + idx + 1;
+}
+
+std::string toString(float num)
+{
+ return strprintf("%f", num);
+}
+
+std::string toString(double num)
+{
+ return strprintf("%f", static_cast<float>(num));
+}
+
bool isDigit(const std::string &str)
{
if (str.empty())