diff --git a/src/chat/chat-room.cpp b/src/chat/chat-room.cpp index 6d8373a6a..b6dcb41d2 100644 --- a/src/chat/chat-room.cpp +++ b/src/chat/chat-room.cpp @@ -247,7 +247,7 @@ string ChatRoomPrivate::createIsComposingXml () const { } if ((err >= 0) && isComposing) { int refreshTimeout = lp_config_get_int(core->config, "sip", "composing_refresh_timeout", composingDefaultRefreshTimeout); - err = xmlTextWriterWriteElement(writer, (const xmlChar *)"refresh", (const xmlChar *)to_string(refreshTimeout).c_str()); + err = xmlTextWriterWriteElement(writer, (const xmlChar *)"refresh", (const xmlChar *)Utils::toString(refreshTimeout).c_str()); } if (err >= 0) { /* Close the "isComposing" element. */ diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index aa21be3dd..1c205d3ed 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -17,6 +17,7 @@ */ #include +#include #include @@ -52,6 +53,30 @@ vector Utils::split (const string &str, const string &delimiter) { return out; } +#ifndef __ANDROID__ +#define TO_STRING_IMPL(TYPE) \ + string Utils::toString(TYPE val) { \ + return to_string(val); \ + } +#else +#define TO_STRING_IMPL(TYPE) \ + string Utils::toString(TYPE val) { \ + ostringstream os; \ + os << val; \ + return os.str(); \ + } +#endif // ifndef __ANDROID__ + +TO_STRING_IMPL(int) +TO_STRING_IMPL(long) +TO_STRING_IMPL(long long) +TO_STRING_IMPL(unsigned) +TO_STRING_IMPL(unsigned long) +TO_STRING_IMPL(unsigned long long) +TO_STRING_IMPL(float) +TO_STRING_IMPL(double) +TO_STRING_IMPL(long double) + int Utils::stoi (const string &str, size_t *idx, int base) { char *p; int v = strtol(str.c_str(), &p, base); diff --git a/src/utils/utils.h b/src/utils/utils.h index 6779552a8..d75838826 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -37,6 +37,16 @@ namespace Utils { return split(str, std::string(1, delimiter)); } + LINPHONE_PUBLIC std::string toString (int val); + LINPHONE_PUBLIC std::string toString (long val); + LINPHONE_PUBLIC std::string toString (long long val); + LINPHONE_PUBLIC std::string toString (unsigned val); + LINPHONE_PUBLIC std::string toString (unsigned long val); + LINPHONE_PUBLIC std::string toString (unsigned long long val); + LINPHONE_PUBLIC std::string toString (float val); + LINPHONE_PUBLIC std::string toString (double val); + LINPHONE_PUBLIC std::string toString (long double val); + LINPHONE_PUBLIC int stoi (const std::string &str, size_t *idx = 0, int base = 10); // Return a buffer allocated with new.