From d16d69e7b86095c1493f4a7062751768c31a58fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Mon, 19 Oct 2015 20:11:55 +0000 Subject: Omegle: Various improvements * Remove typing weirdness * Fix resetting "stranger is typing" on receiving message * Make option "hi message" choose randomly from more messages git-svn-id: http://svn.miranda-ng.org/main/trunk@15571 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Omegle/src/utils.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'protocols/Omegle/src/utils.cpp') diff --git a/protocols/Omegle/src/utils.cpp b/protocols/Omegle/src/utils.cpp index 86db3feec1..0e5b4b2153 100644 --- a/protocols/Omegle/src/utils.cpp +++ b/protocols/Omegle/src/utils.cpp @@ -108,13 +108,29 @@ std::string utils::text::slashu_to_utf8(const std::string &data ) return new_string; } -std::string utils::text::trim(const std::string &data ) +std::string utils::text::trim(const std::string &data) { std::string spaces = " \t\r\n"; - std::string::size_type begin = data.find_first_not_of( spaces ); - std::string::size_type end = data.find_last_not_of( spaces ) + 1; + std::string::size_type begin = data.find_first_not_of(spaces); + std::string::size_type end = data.find_last_not_of(spaces); - return (begin != std::string::npos) ? data.substr( begin, end - begin ) : ""; + return (end != std::string::npos) ? data.substr(begin, end + 1 - begin) : ""; +} + +void utils::text::explode(std::string str, std::string separator, std::vector* results) +{ + std::string::size_type pos; + pos = str.find_first_of(separator); + while (pos != std::string::npos) { + if (pos > 0) { + results->push_back(str.substr(0, pos)); + } + str = str.substr(pos + 1); + pos = str.find_first_of(separator); + } + if (str.length() > 0) { + results->push_back(str); + } } int utils::debug::log(const std::string &file_name, const std::string &text) -- cgit v1.2.3