X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/3ee15695bbd86c97088270b855f810279c2b8275..8f8cc12362a05f4163db159c40579745b4b7aba6:/stglibs/common.lib/include/stg/common.h diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h index 605b9951..ec05adb1 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -103,6 +103,7 @@ std::string ToLower(const std::string & value); std::string ToUpper(const std::string & value); template +inline C Split(const std::string & value, char delim, F conv) { C res; @@ -112,13 +113,14 @@ while (pos != std::string::npos) { res.push_back(conv(value.substr(startPos, pos - startPos))); startPos = pos + 1; - pos = value.find_first_of(delim, pos); + pos = value.find_first_of(delim, pos + 1); } res.push_back(conv(value.substr(startPos, pos - startPos))); return res; } template +inline T FromString(const std::string & value) { T res; @@ -127,10 +129,18 @@ stream >> res; return res; } +template <> +inline +std::string FromString(const std::string & value) +{ +return value; +} + template +inline C Split(const std::string & value, char delim) { - return Split(value, delim, FromString); + return Split(value, delim, FromString); } std::string IconvString(const std::string & source, const std::string & from, const std::string & to); @@ -144,6 +154,11 @@ int ParseYesNo(const std::string & str, bool * val); bool WaitPackets(int sd); +bool ReadAll(int sd, void * dest, size_t size); +bool WriteAll(int sd, const void * source, size_t size); + +std::string ToPrintable(const std::string & src); + //----------------------------------------------------------------------------- int str2x(const std::string & str, int32_t & x); int str2x(const std::string & str, uint32_t & x);