18 #ifndef __H__OCULAR_CORE_UTILS_STRING_OPERATIONS__H__
19 #define __H__OCULAR_CORE_UTILS_STRING_OPERATIONS__H__
21 #include "VoidCast.hpp"
28 #include <unordered_map>
65 static std::string
ToLower(std::string
const& str);
73 static std::string
ToUpper(std::string
const& str);
82 static bool IsEqual(std::string
const& strA, std::string
const& strB,
bool ignoreCase =
false);
91 static bool Contains(std::string
const& source, std::string
const& find,
bool ignoreCase =
false);
122 static void Split(std::string
const& str,
char delim, std::vector<std::string>& tokens);
129 static typename std::enable_if<std::is_arithmetic<T>::value, std::string>::type
FormatHex(T
const x)
131 std::stringstream sstream;
132 sstream <<
"0x" << std::setfill(
'0') << std::setw(
sizeof(T) * static_cast<T>(2)) << std::hex << x;
134 return sstream.str();
161 typename std::enable_if<!std::is_pointer<T>::value, std::string>::type
toString(T
const& data,
bool isPointer =
false)
const
166 auto find = m_ToFunctions.find(tStr);
168 if(find != m_ToFunctions.end())
170 result = find->second(void_cast<T>(data), isPointer);
190 typename std::enable_if<!std::is_pointer<T>::value,
bool>::type
toString(T
const& data, std::string& str,
bool isPointer =
false)
const
195 auto find = m_ToFunctions.find(tStr);
197 if(find != m_ToFunctions.end())
199 str = find->second(void_cast<T>(data), isPointer);
219 std::string
toString(std::string
const& type,
void* data,
bool isPointer =
false)
const
225 auto find = m_ToFunctions.find(type);
227 if(find != m_ToFunctions.end())
229 result = find->second(data, isPointer);
250 bool toString(std::string
const& type,
void* data, std::string& str,
bool isPointer =
false)
const
256 auto find = m_ToFunctions.find(type);
258 if(find != m_ToFunctions.end())
260 str = find->second(data, isPointer);
281 typename std::enable_if<!std::is_pointer<T>::value, T>::type
fromString(std::string
const& value)
const
286 auto find = m_FromFunctions.find(tStr);
288 if(find != m_FromFunctions.end())
290 find->second(value, void_cast<T*>(&result));
309 typename std::enable_if<!std::is_pointer<T>::value,
bool>::type
fromString(std::string
const& value, T&
object)
const
312 auto find = m_FromFunctions.find(value);
314 if(find != m_FromFunctions.end())
316 find->second(value,
object);
340 bool fromString(std::string
const& type, std::string
const& value,
void*
object)
346 auto find = m_FromFunctions.find(type);
348 if(find != m_FromFunctions.end())
350 find->second(value,
object);
364 typename std::enable_if<!std::is_pointer<T>::value,
void>::type
registerToString(std::function<std::string(
void*,
bool)> func)
367 auto find = m_ToFunctions.find(tStr);
369 if(find == m_ToFunctions.end())
371 m_ToFunctions.insert({tStr, func});
381 typename std::enable_if<!std::is_pointer<T>::value,
void>::type
registerFromString(std::function<
void(std::string
const&,
void*)> func)
384 auto find = m_FromFunctions.find(tStr);
386 if(find == m_FromFunctions.end())
388 m_FromFunctions.insert({tStr, func});
396 std::unordered_map<std::string, std::function<std::string(void*, bool)>> m_ToFunctions;
397 std::unordered_map<std::string, std::function<void(std::string const&, void*)>> m_FromFunctions;
static void Split(std::string const &str, char delim, std::vector< std::string > &tokens)
Definition: StringUtils.cpp:183
static std::string FormatWindowsError(unsigned long error)
Definition: StringUtils.cpp:113
std::string toString(std::string const &type, void *data, bool isPointer=false) const
Definition: StringUtils.hpp:219
std::enable_if<!std::is_pointer< T >::value, T >::type fromString(std::string const &value) const
Definition: StringUtils.hpp:281
std::enable_if<!std::is_pointer< T >::value, void >::type registerFromString(std::function< void(std::string const &, void *)> func)
Definition: StringUtils.hpp:381
static std::enable_if< std::is_arithmetic< T >::value, std::string >::type FormatHex(T const x)
Definition: StringUtils.hpp:129
static std::string ToLower(std::string const &str)
Definition: StringUtils.cpp:57
bool fromString(std::string const &type, std::string const &value, void *object)
Definition: StringUtils.hpp:340
std::enable_if<!std::is_pointer< T >::value, bool >::type fromString(std::string const &value, T &object) const
Definition: StringUtils.hpp:309
static std::string ToUpper(std::string const &str)
Definition: StringUtils.cpp:66
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
static bool Contains(std::string const &source, std::string const &find, bool ignoreCase=false)
Definition: StringUtils.cpp:94
Utility structure to convert a type T to a string representation.
Definition: Types.hpp:66
bool toString(std::string const &type, void *data, std::string &str, bool isPointer=false) const
Definition: StringUtils.hpp:250
std::enable_if<!std::is_pointer< T >::value, void >::type registerToString(std::function< std::string(void *, bool)> func)
Definition: StringUtils.hpp:364
std::enable_if<!std::is_pointer< T >::value, bool >::type toString(T const &data, std::string &str, bool isPointer=false) const
Definition: StringUtils.hpp:190
static bool IsEqual(std::string const &strA, std::string const &strB, bool ignoreCase=false)
Definition: StringUtils.cpp:75
static std::string FormatBytes(uint64_t bytes)
Definition: StringUtils.cpp:149
Collection of helper string-related utilities.
Definition: StringUtils.hpp:48
std::enable_if<!std::is_pointer< T >::value, std::string >::type toString(T const &data, bool isPointer=false) const
Definition: StringUtils.hpp:161