diff options
author | Robert Pösel <robyer@seznam.cz> | 2015-10-20 09:37:32 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2015-10-20 09:37:32 +0000 |
commit | 589e20f2b2d8480bad649828230bab152b13d0ed (patch) | |
tree | 1ddd48f2e4cb58f468145046f396ffce29a0c8a0 | |
parent | aaef083794f6e88034ae40549dcf595ac161bd55 (diff) |
MinecraftDynmap: Adapt to use std_string_utils
git-svn-id: http://svn.miranda-ng.org/main/trunk@15577 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/MinecraftDynmap/MinecraftDynmap.vcxproj | 5 | ||||
-rw-r--r-- | protocols/MinecraftDynmap/src/stdafx.h | 2 | ||||
-rw-r--r-- | protocols/MinecraftDynmap/src/utils.cpp | 120 | ||||
-rw-r--r-- | protocols/MinecraftDynmap/src/utils.h | 22 |
4 files changed, 7 insertions, 142 deletions
diff --git a/protocols/MinecraftDynmap/MinecraftDynmap.vcxproj b/protocols/MinecraftDynmap/MinecraftDynmap.vcxproj index 5409ba5219..ae81b7dc57 100644 --- a/protocols/MinecraftDynmap/MinecraftDynmap.vcxproj +++ b/protocols/MinecraftDynmap/MinecraftDynmap.vcxproj @@ -25,6 +25,11 @@ <ImportGroup Label="PropertySheets">
<Import Project="$(ProjectDir)..\..\build\vc.common\plugin.props" />
</ImportGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\utils\std_string_utils.cpp">
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ </ClCompile>
+ </ItemGroup>
<ItemDefinitionGroup>
<ClCompile>
<ExceptionHandling>Sync</ExceptionHandling>
diff --git a/protocols/MinecraftDynmap/src/stdafx.h b/protocols/MinecraftDynmap/src/stdafx.h index 301af3bf93..68992c9a2b 100644 --- a/protocols/MinecraftDynmap/src/stdafx.h +++ b/protocols/MinecraftDynmap/src/stdafx.h @@ -63,6 +63,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. class MinecraftDynmapProto; +#include "../../utils/std_string_utils.h" + #include "utils.h" #include "proto.h" #include "constants.h" diff --git a/protocols/MinecraftDynmap/src/utils.cpp b/protocols/MinecraftDynmap/src/utils.cpp deleted file mode 100644 index ec01628899..0000000000 --- a/protocols/MinecraftDynmap/src/utils.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - -Minecraft Dynmap plugin for Miranda Instant Messenger -_____________________________________________ - -Copyright © 2015 Robert Pösel - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "stdafx.h" - -std::string utils::url::encode(const std::string &s) -{ - return (char*)ptrA(mir_urlEncode(s.c_str())); -} - -void utils::text::replace_first(std::string* data, const std::string &from, const std::string &to) -{ - std::string::size_type position = 0; - - if ((position = data->find(from, position)) != std::string::npos) - { - data->replace(position, from.size(), to); - position++; - } -} - -void utils::text::replace_all(std::string* data, const std::string &from, const std::string &to) -{ - std::string::size_type position = 0; - - while ((position = data->find(from, position)) != std::string::npos) - { - data->replace(position, from.size(), to); - position++; - } -} - -std::string utils::text::special_expressions_decode(std::string data) -{ - utils::text::replace_all(&data, "\\r", "\r"); - utils::text::replace_all(&data, "\\n", "\n"); - utils::text::replace_all(&data, "\\\"", "\""); - utils::text::replace_all(&data, "\\\\", "\\"); - - return data; -} - -std::string utils::text::slashu_to_utf8(const std::string &data) -{ - std::string new_string = ""; - - for (std::string::size_type i = 0; i < data.length(); i++) - { - if (data.at(i) == '\\' && (i+1) < data.length() && data.at(i+1) == 'u') - { - unsigned int udn = strtol(data.substr(i + 2, 4).c_str(), NULL, 16); - - if (udn >= 128 && udn <= 2047) - { // U+0080 .. U+07FF - new_string += (char)(192 + (udn / 64)); - new_string += (char)(128 + (udn % 64)); - } - else if (udn >= 2048 && udn <= 65535) - { // U+0800 .. U+FFFF - new_string += (char)(224 + (udn / 4096)); - new_string += (char)(128 + ((udn / 64) % 64)); - new_string += (char)(128 + (udn % 64 )); - } - else if (udn <= 127) - { // U+0000 .. U+007F (should not appear) - new_string += (char)udn; - } - - i += 5; - continue; - } - - new_string += data.at(i); - } - - return new_string; -} - -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; - - return (begin != std::string::npos) ? data.substr(begin, end - begin) : ""; -} - -time_t utils::time::from_string(const std::string &data) -{ - long long timestamp = _strtoi64(data.c_str(), NULL, 10); - - // If it is milli timestamp - if (timestamp > 100000000000) - timestamp /= 1000; - - // If conversion fails, use local time? - //if (!timestamp) - // timestamp = ::time(NULL); - - return (time_t)timestamp; -} diff --git a/protocols/MinecraftDynmap/src/utils.h b/protocols/MinecraftDynmap/src/utils.h index 105a9b0e0c..35420550b5 100644 --- a/protocols/MinecraftDynmap/src/utils.h +++ b/protocols/MinecraftDynmap/src/utils.h @@ -41,28 +41,6 @@ namespace http }; } -namespace utils -{ - namespace url - { - std::string encode(const std::string &s); - }; - - namespace text - { - void replace_first(std::string* data, const std::string &from, const std::string &to); - void replace_all(std::string* data, const std::string &from, const std::string &to); - std::string special_expressions_decode(std::string data); - std::string slashu_to_utf8(const std::string &data); - std::string trim(const std::string &data); - }; - - namespace time - { - time_t from_string(const std::string &data); - }; -}; - class ScopedLock { public: |