diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 212176d..37e2350 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -1,4 +1,3 @@ -set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) cmake_minimum_required(VERSION 2.6) project(server) @@ -7,6 +6,8 @@ file(GLOB_RECURSE server_src "src/*.cpp" ) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -static -g") add_executable(server ${server_src}) install(TARGETS server RUNTIME DESTINATION bin) + diff --git a/server/src/main.cpp b/server/src/main.cpp index 6874718..d753a19 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -1,10 +1,16 @@ #include +#include #include "sock/tcpsock.hpp" +#include "utils/string.hpp" int main(int argc, char **argv) { //auto sock = sosc::TcpClient(); - std::cout << "compiled on windows" << std::endl; + std::string a = "this!!is!!a!!test"; + auto b = sosc::str::split(a, "!!"); + std::for_each(b.begin(), b.end(), [](std::string& i) { + std::cout << i << std::endl; + }); return 0; } diff --git a/server/src/sock/ip.cpp b/server/src/sock/ip.cpp deleted file mode 100644 index fb97c7a..0000000 --- a/server/src/sock/ip.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "ip.hpp" - diff --git a/server/src/sock/ip.hpp b/server/src/sock/ip.hpp deleted file mode 100644 index 1da0bd0..0000000 --- a/server/src/sock/ip.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef SOSC_UTIL_IP_H -#define SOSC_UTIL_IP_H - -namespace sosc { -class IpAddress { - -protected: - -}; -} - -#endif diff --git a/server/src/utils/net.hpp b/server/src/utils/net.hpp index 2083403..1fedbad 100644 --- a/server/src/utils/net.hpp +++ b/server/src/utils/net.hpp @@ -1,10 +1,63 @@ #ifndef SOSC_UTIL_NET_H #define SOSC_UTIL_NET_H +#include +#include + +#undef htons +#undef HTONS +#undef htonus +#undef HTONUS +#undef ntohs +#undef NTOHS +#undef ntohus +#undef NTOHUS + +#undef htonl +#undef HTONL +#undef htonul +#undef HTONUL +#undef ntohl +#undef NTOHL +#undef ntohul +#undef NTOHUL + +#undef htonll +#undef HTONLL +#undef htonull +#undef HTONULL +#undef ntohll +#undef NTOHLL +#undef ntohull +#undef NTOHULL + +#define HTONS (X) sosc::net::htonv(X) +#define HTONUS(X) sosc::net::htonv(X) +#define NTOHS (X) sosc::net::ntohv(X) +#define NTOHUS(X) sosc::net::ntohv(X) + +#define HTONL (X) sosc::net::htonv(X) +#define HTONUL(X) sosc::net::htonv(X) +#define NTOHL (X) sosc::net::ntohv(X) +#define NTOHUL(X) sosc::net::ntohv(X) + +#define HTONLL (X) sosc::net::htonv(X) +#define HTONULL(X) sosc::net::htonv(X) +#define NTOHLL (X) sosc::net::ntohv(X) +#define NTOHULL(X) sosc::net::ntohv(X) + namespace sosc { -namespace util { -namespace net { - -}}} +typedef std::chrono::system_clock time; + +namespace net { +class IpAddress { + +}; + +template +std::string htonv(T host_var); +template +T ntohv(std::string net_var, size_t offset); +}} #endif diff --git a/server/src/utils/string.cpp b/server/src/utils/string.cpp index 475d535..3cf199d 100644 --- a/server/src/utils/string.cpp +++ b/server/src/utils/string.cpp @@ -14,9 +14,9 @@ std::string sosc::str::ltrim(std::string str) { std::string* sosc::str::ltrim(std::string* str) { int marker = 0; for(; marker < str->length(); ++marker) - if((*str)[marker] < 0x21) break; + if((*str)[marker] > 0x20) break; - str->erase(0, marker - 1); + str->erase(0, marker); return str; } @@ -26,10 +26,10 @@ std::string sosc::str::rtrim(std::string str) { std::string* sosc::str::rtrim(std::string *str) { int marker = 0; - for(; marker < str->length(); --marker) - if((*str)[str->length() - marker - 1] < 0x21) break; + for(; marker < str->length(); ++marker) + if((*str)[str->length() - marker - 1] > 0x20) break; - str->erase(str->length() - marker - 1, marker); + str->erase(str->length() - marker, marker); return str; } @@ -64,7 +64,7 @@ std::vector sosc::str::split while((chunk_end = str.find(delimiter, chunk_end)) != std::string::npos && count != 0) { - parts.push_back(str.substr(chunk_start, chunk_start - chunk_end)); + parts.push_back(str.substr(chunk_start, chunk_end - chunk_start)); chunk_start = (chunk_end += delimiter.length()); --count; } @@ -92,3 +92,25 @@ std::string sosc::str::join(const std::vector& parts, return assembled; } + +bool sosc::str::starts + (const std::string& str, const std::string& start) +{ + if(start.length() > str.length()) + return false; + + return std::mismatch( + start.begin(), start.end(), str.begin() + ).first == start.end(); +} + +bool sosc::str::ends + (const std::string& str, const std::string& end) +{ + if(end.length() > str.length()) + return false; + + return std::mismatch( + end.begin(), end.end(), str.end() - end.length() + ).first == end.end(); +} diff --git a/server/src/utils/string.hpp b/server/src/utils/string.hpp index d65ef3a..6f26dcb 100644 --- a/server/src/utils/string.hpp +++ b/server/src/utils/string.hpp @@ -6,8 +6,12 @@ #include #include +#undef tostr +#undef TOSTR +#define TOSTR(X) std::to_string(X) + namespace sosc { -namespace str { +namespace str { std::string trim (std::string str); std::string* trim (std::string* str); @@ -26,6 +30,9 @@ std::string join(const std::vector& parts, char delimiter, int count = -1); std::string join(const std::vector& parts, std::string delimiter, int count = -1); + +bool starts(const std::string& str, const std::string& start); +bool ends(const std::string& str, const std::string& end); }} #endif